# [.net] GDI+ Image question

This topic is 4267 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello all. Quick question, is there a way using GDI+ to copy and paste a System.Drawing.Bitmap into another Bitmap? I can make a copy of the source image, but there doesnt seem to be a "Paste into" type method. I can replace on image with anothers data, but that really isnt what I am trying to accomplish. There is the option of doing LockBits() on the source and destination image, but I want to keep the code as readable as possible. This is also the reason I want to strictly use GDI+ calls ( no DX, Managed DX, etc... ) Right now, im doing it bit by bit, like this: newImage.SetPixel(i+currentX,j,curImg.GetPixel(i, j)); Let me tell you... its SLOW.... It works, but its pretty painful. Please, someone, tell me im missing a simple Method here somewhere.

##### Share on other sites
You should use a Graphics object and the DrawImage method. For example;
Bitmap Source = new Bitmap("source.png");Bitmap Destination = new Bitmap(100, 100);Graphics g = Graphics.FromImage(Destination);g.DrawImage(Source, 10, 20); // Draw source onto destination at coordinates (10, 20)

Note that because of the way drawing (and pixel offsets) work, you might want to set g.PixelOffsetMode = PixelOffsetMode.Half;. Otherwise, the image will be drawn half a pixel higher and to the left than you might have expected, resulting in a blurry result. You should set this before the DrawImage call.

##### Share on other sites
Doh!

Argh, thats it exactly, thanks so much. Biggest downside to large frameworks is finding what you need. I should have known this from way to many WinForm programs.

Thanks again, apps about 10x faster now :)

• 9
• 16
• 9
• 13
• 41