Jump to content
  • Advertisement
Sign in to follow this  
16bit_port

writing bitmap

This topic is 3173 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. So I'm able to actually write the image to a bitmap and it looks correct except that there are thick "borders/padding" on the top and on the right side. Does anyone know what's causing that? The dimension of the image is 200x200. Length is equal to the Width (hence "LengthAndWidth").
BITMAPFILEHEADER bmpfh;
bmpfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
bmpfh.bfReserved1 = bmpfh.bfReserved2 = 0;
bmpfh.bfSize = sizeof(BITMAPFILEHEADER);//+sizeof(BITMAPINFOHEADER)+sizeof(RGBTRIPLE)*std::pow(LengthAndWidth*1.f,2);
bmpfh.bfType = 0x4D42;

BITMAPINFOHEADER bmpih;
bmpih.biSize = sizeof(BITMAPINFOHEADER);
bmpih.biWidth = bmpih.biHeight = LengthAndWidth;
bmpih.biPlanes = 1;
bmpih.biBitCount = 24;
bmpih.biCompression = BI_RGB;//0;
bmpih.biSizeImage = sizeof(RGBTRIPLE)*LengthAndWidth*LengthAndWidth;
bmpih.biXPelsPerMeter = bmpih.biYPelsPerMeter = 0;//2400;
bmpih.biClrImportant = 0;
bmpih.biClrUsed = 0;

ofstream writer( OutputFileName, ofstream::binary );
writer.write( (char*)(&bmpfh), sizeof(BITMAPFILEHEADER) );
writer.write( (char*)(&bmpih), sizeof(BITMAPINFOHEADER) );

unsigned remainder = LengthAndWidth % 4;

writer.write( (char*)image, bmpih.biSizeImage );
writer.close();


RGBTRIPLE *image = new RGBTRIPLE[LengthAndWidth*LengthAndWidth];

float R, G, B;
for( int j = 0, k = rect.bottom-1; j < rect.bottom; j++, k-- )
	for( int i = 0; i < rect.right; i++ )
	{
		R = G = B = 0.f;

                ...

		image[ k*LengthAndWidth + i ].rgbtRed = R;
		image[ k*LengthAndWidth + i ].rgbtGreen = G;
		image[ k*LengthAndWidth + i ].rgbtBlue = B;
	}


I go through the pixels from top to bottom, but since the image is flipped in a bitmap, I stored the pixel data starting from the other end.

Share this post


Link to post
Share on other sites
Advertisement
If you don't want the image to be stored flipped upside-down you can make the height negative. Just beware that this is only for BI_RGB which you happen to be using.

The grey area at the side and right are suspiciously close to the size you'd be left with if you subtract the total height and width of the non-client area of a window. Thus I suspect you are trying to create a window of exactly 200x200, and then proceed to obtain the client area of this window for your rect which will be reduced to about the proportions in your image. If you want the client rectangle of your window to be 200x200 then you need to create a window larger than that by using AdjustWindowRectEx to calculate the correct window size.

If you check the values of rect.right and rect.bottom with the debugger, you'll see that they are not 200.

Share this post


Link to post
Share on other sites
Quote:
Original post by iMalc
If you don't want the image to be stored flipped upside-down you can make the height negative. Just beware that this is only for BI_RGB which you happen to be using.

The grey area at the side and right are suspiciously close to the size you'd be left with if you subtract the total height and width of the non-client area of a window. Thus I suspect you are trying to create a window of exactly 200x200, and then proceed to obtain the client area of this window for your rect which will be reduced to about the proportions in your image. If you want the client rectangle of your window to be 200x200 then you need to create a window larger than that by using AdjustWindowRectEx to calculate the correct window size.

If you check the values of rect.right and rect.bottom with the debugger, you'll see that they are not 200.


Thank you very much! You were exactly right about everything.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!