Help! In VB6, I have two picture boxes, pic1 and pic2. I'd like to copy pic1 to pic2, minus its white areas---so that pic1's non-white areas appear over pic2.
(pic2 doesn't even have to be an image, just a solid color.)
Someone suggested I look at the BitBlt info on MS's site, but it's way over my head. If that is the only way to do it, maybe someone could take pity on me and post a bit of sample code Thanks!
well what you need is masking. I haven't done that for a long time so I am not sure if it's the black or the white part does not show, so you might need to inverse it first (which is really easy though) but you will surely need a maskfile...
so I would propose you to go to www.ur.co.nz I had no clue about all of that and after reading this everything was clear... go for the bitblt tutorial...
Thanks, guys. I thought this would be pretty simple, but I've posted on several forums (even asked some of those online "experts"), and no one seems to know...
See, I'm writing a program to make chess diagrams for webpages. I want the user to be able to change the colors of the squares, without changing the chess pieces _on_ the squares. Maybe there's an easier way to do this...?
well the problem is that there is no easier way of doing it... except for maybe saving each tile with each background... but that's not a good option anyways...
so what you would need to do is have two sets of pics.. one for the tiles and one for the masks... (while the mask files go for each color.. 16 white, 16 black, 16 masks...) the code you would need to do it than would be just two simple lines, you could even copy without understanding, even though they are really simple...
there is another way of doing it, but I guess noone told you about it, because it leaks memory as crazy and kills that system that way... it's transparent-blt....
Fox: I already said this in email, but---thanks very much! Your generosity is impressive.
/\/\isanThr0p: Fox wrote a complete example for me (with a very interesting 100-square chessboard, by the way---must be one of those chess variations. :?)
It does use BitBlt transparency; is that really such a problem? It seems to me that Fox knows his stuff...
I'd be glad to upload the example, if it's okay with Fox.
it's exactly what I said earlier. you need two pictues, one as mask and one for the tile... than you blit it with two different OpCodes (operations, the first one is an 'or' and the second one is an 'and')
Fox did not use BitBlt though, he used the paint picture which is pretty much the same thing, but you don't need to declare it first. As far as I know it's also a lot slower which does not matter when you don't draw those things in a loop. (I am not sure about the speed difference, I think there used to be one, so I never used this paint function again...)
did not fox already use the image list?
oh well...
NO DO NOT USE THE TRANSPARENT BLT API. IT'S CRAP!
it leaks memory as crazy and will cause you computer to crash after playing a while (especialy if you play as long as a 100*100 field would take )
picture2.autoredraw = true
picture2.scalewidth = picture1.scalewidth
picture2.scaleheight = picture1.scaleheight
For X% = 0 to Picture1.scalewidth
For y% =0 to picture1.scaleheight
if Picture1.Point (X%,Y%) <> Picture1.BackColor Then
Picture2.circle(X%,Y%),1,picture1.point(X%,Y%)
end if
next
next
The above code copies a picture from pic1 to pic2. Anything that is Pic1's backcolor it doesn't copy
Originally posted by VBD picture2.autoredraw = true
picture2.scalewidth = picture1.scalewidth
picture2.scaleheight = picture1.scaleheight
For X% = 0 to Picture1.scalewidth
For y% =0 to picture1.scaleheight
if Picture1.Point (X%,Y%) <> Picture1.BackColor Then
Picture2.circle(X%,Y%),1,picture1.point(X%,Y%)
end if
next
next
The above code copies a picture from pic1 to pic2. Anything that is Pic1's backcolor it doesn't copy
Originally posted by VBD picture2.autoredraw = true
picture2.scalewidth = picture1.scalewidth
picture2.scaleheight = picture1.scaleheight
For X% = 0 to Picture1.scalewidth
For y% =0 to picture1.scaleheight
if Picture1.Point (X%,Y%) <> Picture1.BackColor Then
Picture2.circle(X%,Y%),1,picture1.point(X%,Y%)
end if
next
next
The above code copies a picture from pic1 to pic2. Anything that is Pic1's backcolor it doesn't copy
Yeah, that code will be slow as all hell. What you need is a mask. Copy your image, make everything that is non-white black, and save this as another image. You will then have your silhouette, or mask. Then, you can BitBlt the Mask with vbMergePaint, and then BitBlt the Sprite with vbSrcAnd.
It works fine, but now the problem is when the spirit is moved (redrawn) how can I clear the old one from the playing field. There is gonna be more than 1 spirit on the playing field.
See I run in to another thing because the spirit(s) will only be put on the playing field in specific locations (blocks). Say the map is made up of 13 blocks. 1 Block can only hold 1 spirit since these blocks will be cm^2.
Say spirit Joe is in block a3 and wishes to move to b5. How could i clear Joe from a3 and draw him in b5. Maybe what i have to do is just redraw the whole field per each team's turn. And I run into something else. If 2 SPIRITS on the same team, submit to move on the same block during the teams turn then I would either have to give the red team member more time to pick a new location, or move 1 of the spirits to a block that is nearest to the already filled block. I see myself probably having to make a function moving the user to the nearest block. oh well.
Another thing is text. Is there a way I could draw text on the playing field (picture box) over the SPIRIT?
Please if you can help me or give me any suggestions on which approach is the better or best, I would appreciate it VERY much!
Okay, you need to do something called double buffering. It is when you copy all of your stuff to an invisible picturebox first. Then you SRCCOPY it all to the front picturebox (visible), and clear the invisible one. This way you see no flicker and no trails.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
(Just a heads-up)
Actually, my application didn't need animation speed; I'm creating pictures (chess pieces on board) only as quickly as the user can click. So the Image Control method has worked fine.
I'm intrigued about the TextOut method, though. I'd like to move some words smoothly across a black background without flicker. Would TextOut be the best way? Could you give a few sample code lines for us API dummies?
1) Draw the whole stuff in each frame again (background and sprites). Use this method if you have to redraw the whole frame anyways, eg. if you have animated and/or scrolling tiles like in Jump 'n' Runs, RPGs, RTS or any 3D game.
2) Draw the background once. Then backup the square where you're going to draw a sprite and restore the picture in each frame (because of intersection problems). Note that you have to restore the picture parts in inversed order as you draw them. Use this method if you have a fixed, non-animated background and just small parts that are active, like a Tetris game or similar (just the blocks are moving) or for the world map of your game (fixed picture; animated waterfall or so on it).