TransparentBlt Huge Images?

Hey, its probably something really simple but when I use TransparentBlt, my image comes out far too big for the screen and I cant seem to fix it. It worked perfect when just using BitBlt so I've probably messed something up.

1
2
3
4
5
6
7
void drawSprite(Sprite theSprite)
{
	HBITMAP originalBitMap;
	originalBitMap = (HBITMAP)SelectObject(bitmapHDC,theSprite.bitmap);
	TransparentBlt(backHDC,theSprite.x,theSprite.y+5,theSprite.x+548,theSprite.y+548,bitmapHDC,0,0,61,68,RGB(255,255,255));
	SelectObject(bitmapHDC,originalBitMap); 
}
Yeah well, it's not particularly surprising if you look at the parameters you're passing...
I suggest looking at the documentation to see what each parameter represents:
http://msdn.microsoft.com/en-us/library/dd145141%28v=vs.85%29.aspx
Yeah I've looked at that to get the function. What parameters would you suggest I use? The "theSprite.x/y+548" was used in the bitblt function because it was too large, so I assumed using it again would work but its not. Apart from that I dont see much else wrong.
Apart from that I dont see much else wrong.

Yeah, apart from the error nothing's wrong (probably).
I mean, what do you expect when you pass nonsensical values for the destination size?
What are you trying to do in the first place?
Just display a bitmap sprite on the screen with transparency for my game, it was working fine with the Bitblt but I didnt want do go any further with the game until I had transparency. At the moment its just all stretched and stretches more as you move to the right hand side of the screen.

Heres some screenshots, 1st is using bitblt.

http://imageshack.us/photo/my-images/404/bitshot.png/
http://imageshack.us/photo/my-images/249/transpshot.png/
Last edited on
Unless you want to stretch/distort the image, the dest size and source size should be the same. Per Athar's link, the parameter list is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
BOOL TransparentBlt(
  __in  HDC hdcDest,  // the 'dest' DC to draw to
  __in  int xoriginDest, // X coord on the dest to draw to
  __in  int yoriginDest, // Y coord
  __in  int wDest,  // how many pixels wide the image will appear on dest
  __in  int hDest,  // how many pixels tall

  __in  HDC hdcSrc,  // the 'source' DC from which the image is pulled from
  __in  int xoriginSrc,  // where on the DC the image is coming from
  __in  int yoriginSrc, // " "
  __in  int wSrc,  // how many pixels wide the image is on the source DC
  __in  int hSrc,  // how many pixels tall it is

  __in  UINT crTransparent  // the transparent color
);


Now look at what you're passing:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
TransparentBlt(
backHDC,   // dest DC
theSprite.x,  // dest x
theSprite.y+5,  // dest y
theSprite.x+548, // dest width
theSprite.y+548, // dest height

bitmapHDC,  // src dc
0, // src x
0, // src y
61, // src w
68, // src h

RGB(255,255,255));


You're taking an image that is 61 x 68 and stretching it to 548+ x 548+ !


What Athar was saying is that you should actually understand the parameters you're passing, rather than just pass nonsense and hope it works. Here, passing theSprite.x+548 doesn't make any sense -- and had you read what the parameters are actually for, you might have noticed that for yourself. ;P
Last edited on
Yeah I knew it was wrong I just didnt know it had to be the same value for both, thanks :)
But if you didn't know that, you didn't read the documentation properly. That was the point...
Topic archived. No new replies allowed.