D
Daan Schilder
Guest
Hi, currently im working on an application to read data from a 4000 x 4000 CCD sensor. I can get the data from the CCD sensor into my computer, but only as an char array. This, i would like to convert to an bitmap. So what i did was, create a header for the bitmap, and tried to convert it to a memorystream. (bottom of following code). the error occurs in the line where I do this:
MemoryStream^ ms = gcnew MemoryStream(raw);
and says: No instance of constructor "System::IO::MemoryStream::MemoryStream" matches the argument list
argument types are: (unsigned char[48000054])
could anyone tell me how to convert my char [] to Bitmap the proper way?
void array2bmp(const char * img, int w, int h, PictureBox^ pb)
{
Bitmap^ b;
//FILE *f;
int filesize = 54 + (w + ((4 - (w % 4)) % 4)) * h * 3; //w is your image width, h is image height, both int
unsigned char bmpfileheader[14] = {B,M, 0,0,0,0, 0,0, 0,0, 54,0,0,0};
unsigned char bmpinfoheader[40] = {40,0,0,0, 0,0,0,0, 0,0,0,0, 1,0, 24,0};
unsigned char bmppad[3] = {0,0,0};
bmpfileheader[ 2] = (unsigned char)(filesize );
bmpfileheader[ 3] = (unsigned char)(filesize>> 8);
bmpfileheader[ 4] = (unsigned char)(filesize>>16);
bmpfileheader[ 5] = (unsigned char)(filesize>>24);
bmpinfoheader[ 4] = (unsigned char)( w );
bmpinfoheader[ 5] = (unsigned char)( w>> 8);
bmpinfoheader[ 6] = (unsigned char)( w>>16);
bmpinfoheader[ 7] = (unsigned char)( w>>24);
bmpinfoheader[ 8] = (unsigned char)( h );
bmpinfoheader[ 9] = (unsigned char)( h>> 8);
bmpinfoheader[10] = (unsigned char)( h>>16);
bmpinfoheader[11] = (unsigned char)( h>>24);
memcpy(raw, bmpfileheader, 14);
memcpy(raw+14, bmpinfoheader, 40);
unsigned char *dataptr = raw+54;
for(int i=h-1; i>=0; i--)
{
for(int j=0; j<w; j++)
{
if ((i & 1) == 0) //green - red line
{
if (j & 1) // red
{
*dataptr++ = *(img+i*w+j+w-1); //blue
*dataptr++ = *(img+i*w+j-1); //green
*dataptr++ = *(img+i*w+j); //red
}
else // green
{
*dataptr++ = *(img+i*w+j+w); //blue
*dataptr++ = *(img+i*w+j); //green
*dataptr++ = *(img+i*w+j+1); //red
}
}
else //blue - green line
{
if (j & 1) // green
{
*dataptr++ = *(img+i*w+j-1); //blue
*dataptr++ = *(img+i*w+j); //green
*dataptr++ = *(img+i*w+j-w); //red
}
else // blue
{
*dataptr++ = *(img+i*w+j); //blue
*dataptr++ = *(img+i*w+j+1); //green
*dataptr++ = *(img+i*w+j-w+1); //red
}
}
}
}
MemoryStream^ ms = gcnew MemoryStream(raw);
pb->Image = b->FromStream(ms);
}
Thanks in advance
Continue reading...
MemoryStream^ ms = gcnew MemoryStream(raw);
and says: No instance of constructor "System::IO::MemoryStream::MemoryStream" matches the argument list
argument types are: (unsigned char[48000054])
could anyone tell me how to convert my char [] to Bitmap the proper way?
void array2bmp(const char * img, int w, int h, PictureBox^ pb)
{
Bitmap^ b;
//FILE *f;
int filesize = 54 + (w + ((4 - (w % 4)) % 4)) * h * 3; //w is your image width, h is image height, both int
unsigned char bmpfileheader[14] = {B,M, 0,0,0,0, 0,0, 0,0, 54,0,0,0};
unsigned char bmpinfoheader[40] = {40,0,0,0, 0,0,0,0, 0,0,0,0, 1,0, 24,0};
unsigned char bmppad[3] = {0,0,0};
bmpfileheader[ 2] = (unsigned char)(filesize );
bmpfileheader[ 3] = (unsigned char)(filesize>> 8);
bmpfileheader[ 4] = (unsigned char)(filesize>>16);
bmpfileheader[ 5] = (unsigned char)(filesize>>24);
bmpinfoheader[ 4] = (unsigned char)( w );
bmpinfoheader[ 5] = (unsigned char)( w>> 8);
bmpinfoheader[ 6] = (unsigned char)( w>>16);
bmpinfoheader[ 7] = (unsigned char)( w>>24);
bmpinfoheader[ 8] = (unsigned char)( h );
bmpinfoheader[ 9] = (unsigned char)( h>> 8);
bmpinfoheader[10] = (unsigned char)( h>>16);
bmpinfoheader[11] = (unsigned char)( h>>24);
memcpy(raw, bmpfileheader, 14);
memcpy(raw+14, bmpinfoheader, 40);
unsigned char *dataptr = raw+54;
for(int i=h-1; i>=0; i--)
{
for(int j=0; j<w; j++)
{
if ((i & 1) == 0) //green - red line
{
if (j & 1) // red
{
*dataptr++ = *(img+i*w+j+w-1); //blue
*dataptr++ = *(img+i*w+j-1); //green
*dataptr++ = *(img+i*w+j); //red
}
else // green
{
*dataptr++ = *(img+i*w+j+w); //blue
*dataptr++ = *(img+i*w+j); //green
*dataptr++ = *(img+i*w+j+1); //red
}
}
else //blue - green line
{
if (j & 1) // green
{
*dataptr++ = *(img+i*w+j-1); //blue
*dataptr++ = *(img+i*w+j); //green
*dataptr++ = *(img+i*w+j-w); //red
}
else // blue
{
*dataptr++ = *(img+i*w+j); //blue
*dataptr++ = *(img+i*w+j+1); //green
*dataptr++ = *(img+i*w+j-w+1); //red
}
}
}
}
MemoryStream^ ms = gcnew MemoryStream(raw);
pb->Image = b->FromStream(ms);
}
Thanks in advance
Continue reading...