如何获得图像的一部分并将其用作单独的图像? [英] How to get a part of an image and use it as a separate image?

查看:107
本文介绍了如何获得图像的一部分并将其用作单独的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个图块集,但是所有图块都在一个图像中。我想获取某种位图或图像数组中的每个图块。
是否有某种方法可以做到这一点?

I have a tileset but all the tiles are in one image. I want to get every tile in some kind of bitmap or image array. Is there some kind of method that does that?

推荐答案

使用 Bitmap.Clone(Rectangle,PixelFormat),在这里我们可以设置新图像的PixelFormat 和矩形的大小

Use Bitmap.Clone(Rectangle, PixelFormat) , Here we can set PixelFormat of new image and the size of the rectangle

// Create a Bitmap object from a file.
Bitmap myBitmap = new Bitmap("Grapes.jpg");

// Clone a portion of the Bitmap object.
Rectangle cloneRect = new Rectangle(0, 0, 100, 100);
System.Drawing.Imaging.PixelFormat format =
    myBitmap.PixelFormat;
Bitmap cloneBitmap = myBitmap.Clone(cloneRect, format);

// Draw the cloned portion of the Bitmap object.
e.Graphics.DrawImage(cloneBitmap, 0, 0);

这篇关于如何获得图像的一部分并将其用作单独的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆