Bitmap question?

  • Thread starter Thread starter RawSteel
  • Start date Start date
R

RawSteel

Hi.
A am having some dificulties, getting pixells of a Bitmap image into a
byte array.
I am developing a control for Microsoft Compact Framework, and i need
to get the pixels of the image in one dimentional byte array, make
some changes and rewrite the bitmap.
I know that I can use Bitmap.LockBits() method but it returns a
BitmapData object, that is not present in Compact Framework class
library.
So if anyone knows other way I will thank him for sharing the
knowledge with me :)
 
A am having some dificulties, getting pixells of a Bitmap image into a
byte array.
I am developing a control for Microsoft Compact Framework, and i need
to get the pixels of the image in one dimentional byte array, make
some changes and rewrite the bitmap.
I know that I can use Bitmap.LockBits() method but it returns a
BitmapData object, that is not present in Compact Framework class
library.
So if anyone knows other way I will thank him for sharing the
knowledge with me :)

Sure the BitmapData class is present in the framework.
This class also has a property which returns you an Array of all Pixels as
int's.
 
Sure the BitmapData class is present in the framework.
This class also has a property which returns you an Array of all Pixels as
int's.

Sorry , but it is NOT present.I check that carefully :)
I know that with BitmapData is easy, but I need a managed way of doing this.
And also fast.Fastest possible.
 
Sure the BitmapData class is present in the framework.
Sorry , but it is NOT present.I check that carefully :)
I know that with BitmapData is easy, but I need a managed way of doing this.
And also fast.Fastest possible.

The BitmapData class can be found in:

System.Drawing.Imaging.BitmapData

be sure to include system.drawing.dll.

see
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1031/cpref/html/frlrfsystemdrawing
imagingbitmapdataclasstopic.htm
 
Hi cody
Sure the BitmapData class is present in the framework.
This class also has a property which returns you an Array of all Pixels as
int's.

Could You give us example ot that property?
I'm sorry. But i cannot find it in a .NET docs. :(

Marcin
 
Sure the BitmapData class is present in the framework.
Could You give us example ot that property?
I'm sorry. But i cannot find it in a .NET docs. :(

OK I was a bit mistaken, there is no property for converting the bitmapdata
into an array but there is a property to get the address of the first
scannline. the properties name is "Scan0"

You have to enable unsafe code in your project and cast the IntPtr returned
from "Scan0" to byte*.
Then you can use the returned pointer as you would do in C.
(You could also use the Marshal class to copy a managed array into the
location pointed to by IntPtr but that might be slower).
 
cody said:
In this case you have to use Bitmap.GetPixel. Maybe it is possible with
interop to get the address of the bitmap data but I don't know what
functions your Pocket PC supports.

Yes, I tryed that but it's too slow, and the algoritm is not fast
enough.

Can I write bytes directly in the memory, without using LockBits
method of the Bitmap class.

In fact is there a way writing data directly in memory regardless of
the object, just wherever I need.
:)
 
Back
Top