|
-
Sep 2nd, 2000, 01:00 AM
#1
Thread Starter
Addicted Member
How can I make part of my bitmap transparent so that when someone changes the system colors the background of my bitmap is not the wrong color.
-
Sep 2nd, 2000, 01:24 AM
#2
How about using the Refresh method to fix the color?
-
Sep 2nd, 2000, 01:35 AM
#3
Thread Starter
Addicted Member
I
I dont have a transparent bitmap. I would like to know if there is a way to create one.
-
Sep 2nd, 2000, 07:05 AM
#4
Fanatic Member
There are a lot of methods to make an image transparent. In VB6, the most easiest way to do this, is to put an ImageBox control on the form, which contains a GIF file. Since you can create transparent GIF files (like in Paint Shop Pro) it would be very easy to accomplish this.
VB6 does the transparency automatically. There could be any flickering when the form activates if you are use big transparent 256 colour pictures.
Other simple methods that don't require any code, are i.e. using a ImageList control. This OCX lets you choose the transparent colour (the MaskColor property)
-
Sep 2nd, 2000, 07:25 AM
#5
-
Sep 2nd, 2000, 09:28 AM
#6
Thread Starter
Addicted Member
How do I use the BitBlt API?
-
Sep 2nd, 2000, 01:34 PM
#7
Add 2 PictureBoxes. Call then Picture1 and Picture2. Load your picture (make sure the background is white) in Picture1.
Code:
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Sub Command1_Click()
Me.ScaleMode = vbPixels
BitBlt Picture2.hDC, 0, 0, Picture1.Width, Picture1.Height, Picture1.hDC, 0, 0, vbSrcAnd
End Sub
If the colour turns out a little "dark", then you must create a Mask for the picture and draw it on before you draw your original picture.
-
Sep 2nd, 2000, 02:27 PM
#8
Hyperactive Member
That's right
That's right. Now, before you ask how to Blt with a mask, I'll tell you. First, make a mask of the image. Make sure that the source image has a black backround. Pure black. Next, you have to make a mask of the picture. To make a mask, simply take the source picture, make it's backround white. Whatever Is not going to be transparent, must be black. THE SOURCE AND MASK IMAGES MUST BE THE SAME SIZE. Now that you have the source with the black backround, and the Mask, black with a white backround, it's time to make 2 picture boxes. One named picSprite(load the source image here), one named picMask(Load the mask in here). Add a command button(caption="Blt", name="cmdBlt"). Now, Add this code.
Code:
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Sub cmdBlt_Click()
Me.Cls
With picSprite
BitBlt Me.hdc, 0, 0, .ScaleWidth, .ScaleHeight, picMask.hdc, 0, 0, vbSrcAnd
BitBlt Me.hdc, 0, 0, .ScaleWidth, .ScaleHeight, picSprite.hdc, 0, 0, vbSrcPaint
End With
me.Refresh
End Sub
Now what this does is it takes the source and the mask and then it makes the backround of the source image transparent. It then draws this transparent image on the top left corner of your form. I hope this works for what you need it for.
Designer/Programmer of the Comtech Operating System(CTOS)
-
Sep 2nd, 2000, 04:11 PM
#9
Or if you don't want to use a mask, you can use TransparentBlt instead. Also, TransparentBlt will let you use any colour for transparency whereas BitBlt is limited to only black and white.
Code:
Private Declare Function TransparentBlt Lib "msimg32.dll" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal crTransparent As Long) As Boolean
Private Sub Command1_Click()
Me.ScaleMode = vbPixels
TransparentBlt Picture2.hdc, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, vbWhite
End Sub
-
Sep 2nd, 2000, 06:48 PM
#10
Please be aware that TransparentBlt is only supported on Win98 and Win2000. Win95 and WinNT lacks this function.
-
Sep 2nd, 2000, 07:26 PM
#11
Yes, this API is quite new so the API Text Viewer does not have it...But the PlatForm SDK does.
-
Sep 2nd, 2000, 07:33 PM
#12
Originally posted by Megatron
Yes, this API is quite new so the API Text Viewer does not have it...But the PlatForm SDK does.
So does MSDN library.
-
Sep 3rd, 2000, 06:37 AM
#13
Fanatic Member
TransparentBlt is stupid. I used it in a GUI app and found out that each call to this routine uses a lot of system resources - which are irreversible!!! So I had to write my own routine with For..Next iterations and GetPixel() and SetPixel()...
-
Sep 3rd, 2000, 09:08 AM
#14
Originally posted by Joacim Andersson
Originally posted by Megatron
Yes, this API is quite new so the API Text Viewer does not have it...But the PlatForm SDK does.
So does MSDN library.
PSDK is part of MSDN.
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
|