how can I make part of a picture invisible? What I mean is, that if you wanted to put it in a picturebox, you would be able to see the backcolor through it, like a PNG washout thing, which is what they call it in microsofft office.
Printable View
how can I make part of a picture invisible? What I mean is, that if you wanted to put it in a picturebox, you would be able to see the backcolor through it, like a PNG washout thing, which is what they call it in microsofft office.
If it's a .gif make it's background color transparent. If it's a .png I hear you cannot load it into a picturebox so look here for info about PNG
http://www.vbforums.com/showthread.php?t=506545
how can I make the background colour transparent?
If it's a GIF you will need some application that will allow you to load the GIF image and then set it's transparent color. For a free and easy one to use download Microsoft's Gif Animator.
Google for Microsoft GIF Animator Application and you will find several places to download it.
Maybe this help?
Draw Picture Transparently On Another Picture
Well that's really cool. Opens the door for alot of neat stuff
I added a second Picturebox and called it Picture2. It contains a bitmap.
One question:
How do you get it to draw the picture in Picture1 on top of the picture in the Picture2?
I can get it to work as long as Picture1 is drawn on the Form but not if I want Picture1 to be drawn on the picture in Picture2.
Need to change it slightly, something like,....
Code:DrawTransPicture Picture1.Picture, 100, 100, RGB(255, 0, 255), Picture2
Code:Public Sub DrawTransPicture(img As StdPicture, ImageX As Long, ImageY As Long, ImgTransColour As Long, pic As PictureBox)
Dim hbmDc As Long
Dim hBmp As Long
Dim hBmpOld As Long
Dim bmp As BITMAP
If img.Type = vbPicTypeBitmap Then
hBmp = img.Handle
hbmDc = CreateCompatibleDC(0&)
If hbmDc <> 0 Then
hBmpOld = SelectObject(hbmDc, hBmp)
If GetObject(hBmp, Len(bmp), bmp) <> 0 Then
Call TransparentBlt(pic.hdc, ImageX, ImageY, bmp.bmWidth, bmp.bmHeight, hbmDc, 0, 0, bmp.bmWidth, bmp.bmHeight, ImgTransColour)
End If
Call SelectObject(hbmDc, hBmpOld)
DeleteObject hBmpOld
DeleteDC hbmDc
End If
End If
End Sub
BTW, what I do is pass the hDC of the object instead of the pic box for destination , it's more flexible for future usage. ;)
Code:' put pic1 on form1
TransPicture Picture1.Picture, 100, 100, vbMagenta, Form1.hdc
' put pic1 on pic2
TransPicture Picture1.Picture, 100, 100, vbMagenta, Picture2.hdc
Code:Public Sub TransPicture(img As StdPicture, X As Long, _
Y As Long, TransColor As Long, DestHdc As Long)
Dim hbmDc As Long
Dim hBmp As Long
Dim hBmpOld As Long
Dim bmp As BITMAP
If img.Type = vbPicTypeBitmap Then
hBmp = img.Handle
hbmDc = CreateCompatibleDC(0&)
If hbmDc <> 0 Then
hBmpOld = SelectObject(hbmDc, hBmp)
If GetObject(hBmp, Len(bmp), bmp) <> 0 Then
Call TransparentBlt(DestHdc, X, Y, bmp.bmWidth, bmp.bmHeight, _
hbmDc, 0, 0, bmp.bmWidth, bmp.bmHeight, TransColor)
End If
Call SelectObject(hbmDc, hBmpOld)
DeleteObject hBmpOld
DeleteDC hbmDc
End If
End If
End Sub
I tried something similar to your example and it didn't work. Then I tried your example and still it didn't work.
EDIT
OK, never mind. All three worked. My first attempt and your two examples. The problem is that in the code that I copied the action took place in the Resize event which upon load probably executed the functions but was then erased when the Form became visible. So when I stretched the form a bit the picture then was displayed on the picture box
EDIT EDIT
I think the Resize event is the wrong place to start that stuff. Maybe it should be in the Paint event instead.
EDIT EDIT EDIT
Nope, the Paint event won't work.
That whole method there is something wrong with it because the picture will dissapear if something else moves on top of the Form.
EDIT EDIT EDIT EDIT
OK, it has to go in the Picture2 Paint event.
Or you could set the destinations AutoRedraw to True.Quote:
Originally Posted by jmsrickland
I tried that and it won't draw at all. If you use that API on the Form the Form needs to be AutoRedraw = False and if you use it for a Picturebox then that needs to be AutoRedraw = False also.
Ya guess your right, with Autodraw enabled and running the code from a button I had to do a pic=image,
TransPicture Picture1.Picture, 20, 20, vbMagenta, PicDest.hdc
PicDest.Picture = PicDest.Image
TransPicture Picture3.Picture, 50, 0, vbMagenta, PicDest.hdc
PicDest.Picture = PicDest.Image
Yeah, even better but just don't do that in the Paint Event
what if I want to paint it onto an image control and want to still see the stuff behind the image control in the background?