I work on bitmap i read header of bmp 24 bit per pixel ,width 320 height 240,offset start of image data in location 54,use c#
in location 54 in bmp array i access to data ,i store data in new array :
struct pix //structure for pixel in bmp image
{
public byte r;//Red
public byte g;//Green
public byte b;//Blue
};
Bitmap img = new Bitmap(opendialog1.FileName);
string filename = opendialog1.FileName;
byte[] bmp = File.ReadAllBytes(filename);
int i=54;
pix[ , ] bmpdata = new pix[img.Height, img.Width]; //create array of structure
for (int row = 0; row < img.Height; row++)
{
for (int col = 0; col < img.Width; col++)
{
bmpdata[row, col].r = bmp[i];
bmpdata[row, col].g = bmp[i + 1];
bmpdata[row, col].b = bmp[i + 2];
i += 3;
}
is this correct method for copy data from bmp array into new array for data only ,i use c# window form ?
VulpesPosted Dec 31, 2013, 10:17 AM
You can then make changes to the array, copy the bytes back to the Bitmap and then unlock it.
For large scale changes, this is quicker than making individual changes to the pixels using the Bitmap.SetPixel method.
There's some sample code for doing all this here:
http://msdn.microsoft.com/en-us/library/system.drawing.imaging.bitmapdata.scan0(v=vs.110).aspx
Of course, there's nothing to stop you copying your array of bytes to an array of your pix struct (and back again) if you find that easier to work with.