MSFN Forum: Problems with LoadImage and TransparentBlt - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Problems with LoadImage and TransparentBlt Colours being mapped wrong Rate Topic: -----

#1 User is offline   HyperHacker 

  • Just plain nuts
  • PipPipPip
  • Group: Members
  • Posts: 473
  • Joined: 01-May 05

Posted 08 October 2005 - 11:23 PM

I've encountered two strange problems when using LoadImage and TransparentBlt:

1) When using LoadImage, if I specify a width and height of 0 (use the image's actual size), it works alright, but if I speicfy an actual size, all pixels of colour FF0000 (RGB) are replaced with FE0000. :blink: I'm not sure if it does this to every colour, or just red, but it's strange...

2) Using TransparentBlt, if I pass values greater than the image's width/height for source width/height, the function fails entirely (error 87, invalid parameter).

Is it possible to get an image's dimensions after loading it? Seems like one of those things that should be really simple but is in fact incredibly complicated if not impossible. Like most things in Windows' API. <_<

[edit] Haha! I finally found a way to get the image's dimensions.

BITMAPINFO bm;
		bm.bmiHeader.biSize = sizeof(bm.bmiHeader); //Set the size
		bm.bmiHeader.biWidth = 0; //These 2 lines can be omitted, but then if the function fails,
		bm.bmiHeader.biHeight = 0; //these will be set to some random garbage.
		bm.bmiHeader.biBitCount = 0; //This needs to be zero

		ImageBMP = LoadImage(NULL,FName,IMAGE_BITMAP,0,0,LR_LOADFROMFILE); //Load the image
		OldImageBMP = SelectObject(ImageDC,ImageBMP);
		if(!OldImageBMP) DebugOut(DO_MINOR,"<randimg> Failed to select image bitmap\n");
		DebugOut(DO_STATUS,"<randimg> Created image bitmap: BMP=0x%08X OLD=0x%08X\n",ImageBMP,OldImageBMP);

		GetDIBits(ImageDC,ImageBMP,0,0,NULL,&bm,DIB_RGB_COLORS);
		ImageWidth = bm.bmiHeader.biWidth;
		ImageHeight = bm.bmiHeader.biHeight;


The documentation for GetDIBits says not to select the bitmap into a DC, but it also asks for a DC so I'm not sure what to make of that. It seems to work whether you select it or not.

So this basically works around both problems (no need to specify dimensions in LoadImage, and can use the image's exact height in TransparentBlt), but I'd still like to know what causes them.

This post has been edited by HyperHacker: 09 October 2005 - 12:03 AM



Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy