//Define parameters
TMemoryStream* Bitmap = new TMemoryStream();
unsigned char header[54];
unsigned char cameradata[262144];
unsigned char imagebtmp[786432];
//Create header & test data
//The header is 54 bytes long with the following fields
//Field Bytes Description
//bfType 2 Bitmap identifier. Must be 'BM'
//bfSize 4 Can be set to 0 for uncompressed bitmaps
//bfReserved 2 Set to 0
//bfReserved 2 Set to 0
//bfOffbits 4 Specifies start of image data in bytes
//biSize 4 Size of info header (40 bytes)
//biWidth 4 width of bitmap in pixels
//biHeight 4 height of bitmap in pixels
//biPlances 2 Set to 1
//biBitCount 2 Bit depth of bitmap, set to 24
//biCompression 4 Images are uncompressed so set to 0
//biSizeImage 4 The size of the padded image in bytes
//biXPelsPerM 4 Resolution in X, set to 0
//biYPelsPerM 4 Resolution in y, set to 0
//biClrUsed 4 N/A, set to 0
//biClrImportant4 N/A, set to 0
for (int i=0;i<54;i++)
{ header[i] = 0; }
header[0] = 66; //Set to 'B'
header[1] = 77; //Set to 'M'
header[10] = 54; //Sets bfOffbits
header[14] = 40; //Sets biSize
header[19] = 2; //sets biWidth to 512
header[23] = 2; //sets biHeight to 512
header[26] = 1; //Sets biPlanes
header[28] = 24; //Sets biBitCount
header[36] = 12; //Sets size of padded image 512x512x3
//Create some simulation data
for (int i=0;i<262144;i++)
{
cameradata[i]=0;
}
//Convert the cameradata to the imagebtmp. Each
//8bit pixel value is repeated 3 times for the
//Red, Green, Blue to give us a greyscale
int tally =0;
for (int j=0;j<262144;j++)
{
imagebtmp[tally]=cameradata[j];
tally++;
imagebtmp[tally]=cameradata[j];
tally++;
imagebtmp[tally]=cameradata[j];
tally++;
}
//Now elsewhere in the code we can update image
Bitmap->Clear();
Bitmap->WriteBuffer(header,54);
Bitmap->WriteBuffer(imagebtmp,786432);
Bitmap->Position = 0;
Image1->Picture->Bitmap->LoadFromStream(Bitmap);
Image1->Refresh();