views:

44

answers:

2

I'm using Bitmap Class' .setPixel and .getPixel to draw my bitmap fonts on .NET CF. But it is too slow, in java we have getRGB() and setRGB() to set array of colors with a single call. Is there something like that in .NET CF. My requirement is simply to draw a portion of a bitmap into another bitmap at specified x,y.

EDIT: The source image have transparancy (not alpha but just simple transparency).

+2  A: 

Don't do your own 'blit' with a for loop and get/set pixels!

Use Graphics.FromImage() and draw the other bitmap into it using DrawImage().

Will
yea, but how to draw a PORTION of a bitmap to another bitmap?
VOX
@VOX use the other overloads of DrawImage http://msdn.microsoft.com/en-us/library/ms142041.aspx if it's a rectangular portion
Pete Kirkham
the portion is rectangular but there's a white space (or purple space) that I don't want to draw it to dest bitmap as it is a bitmap font. sorry if i didn't make it clear.
VOX
+2  A: 

Don't roll your own loop. You should be able to run the DrawImage method with the ImageAttributes attribute, setting the correct color key (white, purple, whatever you use in your image).

imageAttributes = new ImageAttributes();
imageAttributes.SetColorKey(Color.Magenta, Color.Magenta);

graphics.DrawImage(image, 
                   destinationRectangle, 
                   sourceRectangle.X, 
                   sourceRectangle.Y, 
                   sourceRectangle.Width, 
                   sourceRectangle.Height, 
                   GraphicsUnit.Pixel, 
                   imageAttributes);
Paul-Jan
thanks paul. That's exactly what i need.
VOX