How to get a part of an image and use it as a separate image?

前端 未结 1 789
失恋的感觉
失恋的感觉 2020-12-17 15:53

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?

相关标签:
1条回答
  • 2020-12-17 16:05

    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);
    
    0 讨论(0)
提交回复
热议问题