Tutorial :getPixel setPixel too slow, is there any other alternative on .NET CF



Question:

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).


Solution:1

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);  


Solution:2

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().


Solution:3

Use bitmap, BitBlt functionality. I show an example in here.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »