HyperHacker Posted October 9, 2005 Posted October 9, 2005 (edited) 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. 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. Edited October 9, 2005 by HyperHacker
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now