|
-
Jan 30th, 2008, 01:30 PM
#1
Thread Starter
Hyperactive Member
invisible
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.
-
Jan 30th, 2008, 07:57 PM
#2
Re: invisible
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
-
Jan 31st, 2008, 03:41 PM
#3
Thread Starter
Hyperactive Member
Re: invisible
how can I make the background colour transparent?
-
Jan 31st, 2008, 04:18 PM
#4
Re: invisible
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.
-
Jan 31st, 2008, 05:30 PM
#5
-
Jan 31st, 2008, 05:56 PM
#6
Re: invisible
Well that's really cool. Opens the door for alot of neat stuff
-
Jan 31st, 2008, 08:27 PM
#7
Re: invisible
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.
-
Jan 31st, 2008, 08:44 PM
#8
Re: invisible
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
-
Jan 31st, 2008, 09:04 PM
#9
Re: invisible
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
-
Jan 31st, 2008, 11:39 PM
#10
Re: invisible
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.
Last edited by jmsrickland; Jan 31st, 2008 at 11:53 PM.
-
Feb 1st, 2008, 01:02 PM
#11
Re: invisible
 Originally Posted by jmsrickland
OK, it has to go in the Picture2 Paint event.
Or you could set the destinations AutoRedraw to True.
-
Feb 1st, 2008, 01:22 PM
#12
Re: invisible
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.
-
Feb 1st, 2008, 01:46 PM
#13
Re: invisible
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
-
Feb 1st, 2008, 02:10 PM
#14
Re: invisible
Yeah, even better but just don't do that in the Paint Event
Last edited by jmsrickland; Feb 1st, 2008 at 02:16 PM.
-
Feb 24th, 2008, 07:56 AM
#15
Thread Starter
Hyperactive Member
Re: invisible
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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|