Make Bitmap Transparent With BitBit
Hi all - Lets say I have a bitmap with a region that has been marked with a certain color to detone a transparent area - how could I go about BitBit'ing on top of another picture in VB so that the solid color becomes transparent? THanks -Chris
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
How To Make White To Transparent In Bitmap File?
Hello, Everyone:
I tried to make white to transparent in Bitmap file. I would like the output transparent file still a Bitmap file? How can I achieve it? Would someone be kind to help me out? I have photoshop, Illustrator... However, I don't have Corel Draw... Is there any free software to do it?
Thank you very much!
Charlie
Transparent Bitmap?
Is it possible to draw transparent bits onto a bitmap?
I want to be able to make sections of images that i create transparent.
Transparent Bitmap
I'm making a programme bitmaps without transparent backgrounds will be loaded from files then, the background made transparent, then stored in Image controls. I've tried using transparentblt, but that only works on things with hdc. I tried creating a transparent bitmap in a picturebox, which works in the picture box itself, but I can't transfer it to an Image control.
Any ideas? I apologise if I haven't explained things properly.
Creating Transparent Bitmap
Hi peoples, it has been awhile. This place is really rockin' now!
Anyway, I need code samples/pointers to code/etc that will enable me to open a bitmap file, check out what the first pixel colour is and then change that colour to another in memory and then save the file.
I realise that 24bit bmps are a little trickier to use than 16 bit, so I am willing to use code for 16bit bitmaps. Can I just open the bitmap and change a palette colour?
I need it to be entirely using Windows API's, as I am doing this in Access rather than VB.
Any help is greatly appreciated.
Cheers
Making Parts Of Bitmap Image Transparent
Hey I was wondering on how to make parts of a bitmap image transparent.
Like you have a bitmap picture with a red background and a blue box in the middle
I want to make the red back ground transparent to anything it is placed on in the form.
eg. another image.
And another question is
with the blue box and red background
can you change the value of the colour as it is bitmap and make the red look green when the bitmap picture is opened in the form.
~
Drawing A Bitmap With One Transparent Color Over A DC... What's Wrong?
Hi!
I have to draw both bitmaps and icons over a device context that could be any color - even gradient. For icons, this is pretty straightforward - DrawIconEx supports it (not sure, but the code works). Unlike icons, bitmaps are drawn just as they are - with gray background color, so the form's background gets all wrong. I went to MSDN and found C++ code that should work (see attached file, .cpp file), converted the code using API-Guide and my rather limited C++ to VB conversion knowledge. This is what I got:
(see attached file)
Option Explicit
Private Type BITMAP
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function GetObject Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Declare Function DPtoLP Lib "gdi32" (ByVal hdc As Long, lpPoint As POINTAPI, ByVal nCount As Long) As Long
Private Declare Function CreateBitmap Lib "gdi32" (ByVal nWidth As Long, ByVal nHeight As Long, ByVal nPlanes As Long, ByVal nBitCount As Long, lpBits As Any) As Long
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function SetMapMode Lib "gdi32" (ByVal hdc As Long, ByVal nMapMode As Long) As Long
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 Declare Function SetBkColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function GetMapMode Lib "gdi32" (ByVal hdc As Long) As Long
Private Const SRCCOPY = &HCC0020 ' (DWORD) dest = source
Private Const NOTSRCCOPY = &H330008 ' (DWORD) dest = (NOT source)
Private Const SRCAND = &H8800C6 ' (DWORD) dest = source AND dest
Private Const SRCPAINT = &HEE0086 ' (DWORD) dest = source OR dest
'Const SRCINVERT = &H660046 ' (DWORD) dest = source XOR dest
'Const SRCERASE = &H440328 ' (DWORD) dest = source AND (NOT dest )
Private Function DrawTransparentBitmap(ByVal hdc As Long, ByVal hBitmap As Long, _
ByVal xStart As Long, ByVal yStart As Long, _
ByVal cTransparentColor As Long)
Dim bm As BITMAP
Dim cColor As Long
Dim bmAndBack As Long, bmAndObject As Long, bmAndMem As Long, bmSave As Long
Dim bmBackOld As Long, bmObjectOld As Long, bmMemOld As Long, bmSaveOld As Long
Dim hdcMem As Long, hdcBack As Long, hdcObject As Long, hdcTemp As Long, hdcSave As Long
Dim ptSize As POINTAPI
hdcTemp = CreateCompatibleDC(hdc)
SelectObject hdcTemp, hBitmap ' // Select the bitmap
GetObject hBitmap, Len(bm), bm
ptSize.x = bm.bmWidth ' // Get width of bitmap
ptSize.y = bm.bmHeight ' // Get height of bitmap
Debug.Print ptSize.x & "-" & ptSize.y
DPtoLP hdcTemp, ptSize, 1 ' // Convert from device
' // Create some DCs to hold temporary data.
hdcBack = CreateCompatibleDC(hdc)
hdcObject = CreateCompatibleDC(hdc)
hdcMem = CreateCompatibleDC(hdc)
hdcSave = CreateCompatibleDC(hdc)
' // Create a bitmap for each DC. DCs are required for a number of
' // GDI functions.
' // Monochrome DC
bmAndBack = CreateBitmap(ptSize.x, ptSize.y, 1, 1, ByVal 0&)
' // Monochrome DC
bmAndObject = CreateBitmap(ptSize.x, ptSize.y, 1, 1, ByVal 0&)
bmAndMem = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y)
bmSave = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y)
' // Each DC must select a bitmap object to store pixel data.
bmBackOld = SelectObject(hdcBack, bmAndBack)
bmObjectOld = SelectObject(hdcObject, bmAndObject)
bmMemOld = SelectObject(hdcMem, bmAndMem)
bmSaveOld = SelectObject(hdcSave, bmSave)
' // Set proper mapping mode.
SetMapMode hdcTemp, GetMapMode(hdc)
' // Save the bitmap sent here, because it will be overwritten.
BitBlt hdcSave, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY
' // Set the background color of the source DC to the color.
' // contained in the parts of the bitmap that should be transparent
cColor = SetBkColor(hdcTemp, cTransparentColor)
' // Create the object mask for the bitmap by performing a BitBlt
' // from the source bitmap to a monochrome bitmap.
BitBlt hdcObject, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY
' // Set the background color of the source DC back to the original
' // color.
SetBkColor hdcTemp, cColor
' // Create the inverse of the object mask.
BitBlt hdcBack, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, NOTSRCCOPY
' // Copy the background of the main DC to the destination.
BitBlt hdcMem, 0, 0, ptSize.x, ptSize.y, hdc, xStart, yStart, SRCCOPY
' // Mask out the places where the bitmap will be placed.
BitBlt hdcMem, 0, 0, ptSize.x, ptSize.y, hdcObject, 0, 0, SRCAND
' // Mask out the transparent colored pixels on the bitmap.
BitBlt hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcBack, 0, 0, SRCAND
' // XOR the bitmap with the background on the destination DC.
BitBlt hdcMem, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCPAINT
' // Copy the destination to the screen.
BitBlt hdc, xStart, yStart, ptSize.x, ptSize.y, hdcMem, 0, 0, SRCCOPY
' // Place the original bitmap back into the bitmap sent here.
BitBlt hdcTemp, 0, 0, ptSize.x, ptSize.y, hdcSave, 0, 0, SRCCOPY
' // Delete the memory bitmaps.
DeleteObject SelectObject(hdcBack, bmBackOld)
DeleteObject SelectObject(hdcObject, bmObjectOld)
DeleteObject SelectObject(hdcMem, bmMemOld)
DeleteObject SelectObject(hdcSave, bmSaveOld)
' // Delete the memory DCs.
DeleteDC hdcMem
DeleteDC hdcBack
DeleteDC hdcObject
DeleteDC hdcSave
DeleteDC hdcTemp
End Function
Private Sub Form_Load()
DrawTransparentBitmap Me.hdc, Picture1.Image.Handle, 100, 100, &H8000000F
End Sub
===
What's wrong with the code? Was I wrong in my conversions?
Thanks a lot in advance!
Stas
How To Make A Transparent GIF With A Transparent Background?
Hi, im kinda new to VB and im trying to make nice form with a custom picture i designed. Since the picture isnt rectangular i have to use transparency so it doesnt stay ugly. If i just set the transparent GIF as a background the transparent section of the gif will show the form background and not the desktop (or whatever is behind the app) like this:
Form 1
Then i used this code to make the background transparent:
Code:
Option Explicit
Private Declare Function CreateRectRgn Lib _
"gdi32" (ByVal X1 As Long, ByVal Y1 As Long, _
ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function CombineRgn Lib _
"gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, _
ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Private Declare Function SetWindowRgn Lib _
"user32" (ByVal hWnd As Long, ByVal hRgn As Long, _
ByVal bRedraw As Boolean) As Long
Private Declare Function DeleteObject Lib _
"gdi32" (ByVal hObject As Long) As Long
' Constants used by the CombineRgn function
Private Const RGN_AND = 1
Private Const RGN_OR = 2
Private Const RGN_XOR = 3
Private Const RGN_DIFF = 4
Private Const RGN_COPY = 5
Private Sub Form_Activate()
Dim rgnForm As Long, rgnCombined As Long
Dim rgnControl As Long, x As Long
Dim formWidth As Single, formHeight As Single
Dim borderWidth As Single, titleHeight As Single
Dim ctlLeft As Single, ctlTop As Single
Dim ctlWidth As Single, ctlHeight As Single
Dim ctl As Control
' Calculate the form area
borderWidth = (Me.Width - Me.ScaleWidth) / 2
titleHeight = Me.Height - Me.ScaleHeight - borderWidth
' Convert to Pixels
borderWidth = ScaleX(borderWidth, vbTwips, vbPixels)
titleHeight = ScaleY(titleHeight, vbTwips, vbPixels)
formWidth = ScaleX(Me.Width, vbTwips, vbPixels)
formHeight = ScaleY(Me.Height, vbTwips, vbPixels)
' Create a region for the whole form
rgnForm = CreateRectRgn(0, 0, formWidth, formHeight)
rgnCombined = CreateRectRgn(0, 0, 0, 0)
' Make the graphical area transparent by combining the two regions
x = CombineRgn(rgnCombined, rgnForm, rgnForm, RGN_DIFF)
' Make the controls visible
For Each ctl In Controls
' Make the regions of controls whose container is the form visible
If TypeOf ctl.Container Is Form Then
ctlLeft = ScaleX(ctl.Left, vbTwips, vbPixels) + borderWidth
ctlTop = ScaleX(ctl.Top, vbTwips, vbPixels) + titleHeight
ctlWidth = ScaleX(ctl.Width, vbTwips, vbPixels) + ctlLeft
ctlHeight = ScaleX(ctl.Height, vbTwips, vbPixels) + ctlTop
rgnControl = CreateRectRgn(ctlLeft, ctlTop, ctlWidth, ctlHeight)
x = CombineRgn(rgnCombined, rgnCombined, rgnControl, RGN_OR)
End If
Next ctl
' Set the clipping area of the window using the resulting region
SetWindowRgn hWnd, rgnCombined, True
' Tidy up
x = DeleteObject(rgnCombined)
x = DeleteObject(rgnControl)
x = DeleteObject(rgnForm)
End Sub
The form stays transparent but the background picture of the form is invisible as well. Then i tried to add the background picture as a picture box but the transparent parts kept showing the form background color and not the desktop like this:
Form 2
This is how i want it to look:
Form 3
Any help would be greatly apreciated.
Thanks in advanced.
How Can I Make One Btimap From 2 Bitmap?
I want to clip a region from a Bitmap from centre and bitmap is larger than the monitor scale around 2000*2000 pixles.
How can I cut the region from a bitmap and save that region as different bitmap.
Also i want to make the frame of the bitmap and this bitmap also may be the same size as above and I want to draw the black frame on the bitmap and
save that bitmap with a different name. for this I thought that I can make a black bitmap so I can copy the required bitmap into the black bitmap
in centere. Its not need required to diplay the bitmap on screen. I just want to do it by getting the bitmap patth.
How Do U Make A Bitmap That Has A Weird Extention
I see all these games files and how they don't have anything that's clearly easy open. UT has utx and stuff liek that. I want to know how to make a bitmap with a weird extention that end users can't open though paint or anything like that..just through my editor. Now, i know i create my own format and save it in a file. but wouldn't that be somewhat slow...i've been thinking about C++ alot lately. i'm already in C++ class and i'm about to learn how to build classes...so...mmm. would this be more of a C++ task(just because of speed.)
Make A Monochrome Bitmap From A Text Box
I have a text box with data on it.
what API call can give me raw data to be able to
make a monochrome bitmap from that text box?
I would build the bitmap myself; I just need the bits.
Thank you
Yaz
How To Make Border On Bitmap Of Given Size
I want to make border on a bitmap with a specified size and color. and vice versa I want to cut the bitmap from centere region by the given sizes.
I don't want to display the bitmap in any control box visible to user. Just by reading the path and save the update bitmap.
Please help me out...
How Do You Make A Bitmap Move UP Or LEFT ...
Hi,
I know the code to move a bitmap to the right, which is : (Example)
Image1.Left = Image1.Left + 20
But, how do you move the object in the opposite direction.
Also, to move an object upwards its
Image1.Top = Image1.Top + 10
But, how do you move the object downwards.
Any Info, I`m in the middle of making a game!!!
Mark
How To Make A Toolbar Representation Bitmap For A UserControl??
Hello Every1,
I wanna make a Bitmap for my usercontrol so that I can change its representation in the toolbox. But the problem, is no matter how big the bitmap i make, it cant be displayed properly in the VB Toolbox. Its displayed but nothing can be made out of it. I want to make one just like the Label control, what dimensions should i take for the bitmap and what format should i save it in.Thanx in advance.
How Can You Make A Bitmap Flash (i.e. Load Then Unload)?
Hi,
I have a main picture box(MainPic1) and two other Pictures in boxes (Pic1) and (Pic2). I also have a button. When I press the button, the main picture box becomes pic1, but I want it to change the picture continuously until the button is pressed again, to make it look if the picture is flashing (i.e. alternating between the two). Is it possible to do this? Any Code?
Thanks
Mark
How Can I Make A Transparent DDB Or DIB
I'm trying to use TransparentBlt(here I can not fill the last argument)and TransparentDIBits(here I can not fill also the last argument and the fifth argument from end declared UINT).thanks
How To Make The Pop Up Box Not Transparent?
Hi,
I am doing this program that when it is doing something a pop up box will appear but it always transparent.
I would like to know how to make it not transparent...
Thank you
Make A Picturebox Transparent...
Here an example to make a picturebox transparent... Is resulted from a bit searching with Google and something do handicraft with the attempt to agree imagebox transparent. A lot of fun while using... 8)
How To Make A Form Transparent
i want to make a form transparent.
i have one picture on my form i want to show only my pic not form.
please tell me how to make.
thankx
How To Make Pictureboxes Transparent
im making a game like space envaders. the ship is an ICO file because i want transparency, and i am using a picture box because image controls flicker when moved. problem is, picture boxes have no backstyle proprerty. so how is this done?
any ideas?
How To Make Transparent Image Box ?
How Can I Make a transparent Image Box ?
Here in this Image
http://www.arab-x.com/uploads/Jun-06/c28aac314f.jpg
I Only Want the player to appear , not the white block around him .
How can i make this white block disappear as if the image was an icon not BMP ?
Make The Backgroundcolor Transparent?
Hi all,
I managed to use D3DXsprite.draw to draw a bitmap of a crosshair on the screen. However, the crosshair is now drawn with its black background on the screen. I want to make the background transparent. When using the D3DXsprite.draw method you can specify a color with which the bitmap will be drawn. Now I know that you can specify a color which makes the black color transparent, but I've forgotten the value(!). Anyone out there who knows the value?
Much appreciated.
[FAQ] How To Make A Frame Transparent
Code:
Option Explicit
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const WS_EX_TRANSPARENT = &H20&
Private Const GWL_EXSTYLE = (-20)
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const SWP_FRAMECHANGED = &H20
Private Declare Function SetBkMode Lib "gdi32" (ByVal hdc As Long, ByVal nBkMode As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Const TRANSPARENT = 1
Private Declare Function InvalidateRectLong Lib "user32" Alias "InvalidateRect" (ByVal hwnd As Long, ByVal lpRect As Long, ByVal bErase As Long) As Long
Public Sub MakeFrameTransparent(ByVal fraThis As Control)
Dim lExStyle As Long
lExStyle = GetWindowLong(fraThis.hwnd, GWL_EXSTYLE)
lExStyle = lExStyle Or WS_EX_TRANSPARENT
'\ Set window style to be transparent
Call SetWindowLong(fraThis.hwnd, GWL_EXSTYLE, lExStyle)
'\ make the fram backstyle transparent
Call SetBkMode(GetDC(fraThis.hwnd), TRANSPARENT)
'\ Make frame window redraw itself
Call SetWindowPos(fraThis.hwnd, 0, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE + SWP_FRAMECHANGED)
Call InvalidateRectLong(fraThis.hwnd, vbNull, True)
End Sub
-||{How Do I Make A FRAME TRANSPARENT} Pls Help ||-
hi,
how can i make a frame transparent so dat it may look like it is directly placed on the form background.... i removed the borders and caption.. now i need to make the background transparent.. how can i do dat?
pls help!
How Do You Make Transparent Text?
I am making a media presentation program and I need a few tips. How could I make it look like text is fading in with a picture? I am using the msimg32.dll api. This works but I also need to find some way to blend text as well. Can anyone help me?
How Do You Make A Picturebox Transparent?
I am trying to make a picturebox, with the name label, Picture1 transparent. However not the pen marks that the user makes when they draw using the mouse clicks, etc.
However Picture1, only makes "Box" marks using the mouse and nothing else. Then select objects on Frame1, using Picture1.
The "Box" marks are made using the Picture1.Line... command.
!is It Possible To Make Listbox Transparent?!
I was wondering if it would be possible to set list box background transparent.
I've built a program with amazing GUI and wanted it to shine but can't due to list box taken up soo much darn space.
Id also like to learn how to do it to.
How To Make An Optionbutton Transparent?
I have searched the forum and found some threads, but i couldn´t find anything that would really solve my problem.
Does anyone know where i can get some code to solve this problem?
Please Help Me. I Need Make Transparent Region
Please help me.
I have in Form1.Picture a picture with blue Background and I need make this blue color transparent.
I want with BitBlt make blue background transparent but background of form is visible and I need it transparent.
I want make a animated decoration for my desktop.
I will not grab picture form desktop for backround to my animation but I will as bacground really Windows.
-||{How Do I Make A FRAME TRANSPARENT} Pls Help ||-
hi,
how can i make a frame transparent so dat it may look like it is directly placed on the form background.... i removed the borders and caption.. now i need to make the background transparent.. how can i do dat?
pls help!
Make A Listbox TRANSPARENT?
Is it possible to make a listbox Transparent? I have clouds as a background and no color i pick goes good at all
I may also need a transparent textbox later.. can someone help?
Make Check Box Transparent
i'd like to make my check boxes transparent
of course i've searched and have seen the label trick, but these are on a tab strip, so labels dont show
here's what it should look like
How To Make A Picture Box Transparent
is there a way to make a picture box transparent? I know you can change the background color, but I can't figure out how to make it transparent. Thanks.
How Do I Make A Transparent Form
I was wondering how you can make a form transparent. Also does anyone know how to make a color on a picture transparent.
Thanks in advance
Make Frame Transparent?
Does anyone know how to make a frame transparent? I am just using the frame to separate groups of similar data on a form but I want it transparent so the form background can be seen.
How Do I Make A GIF's Background Transparent?
Umm im not sure what you mean by that.
See, in Photoshop, I went to NEW. And under the CONTENTS option, i said Transparent.
Now with these settings, i created an image. And then put this image into the Image List. Then I called it up in the toolbar which displayed it with a white background, when I didn't put a white background in the first place. I made it TRANSPARENT!
How Do Make A Gif File Transparent?
how do make it so you can make a gif file transparent? And how do let the user choose the color that becomes transparent? btw this is for vb!
How Do I Make A Listbox Transparent
HI,
I have a form with a picture, and a listbox on it. I would like the picture from the main form to show through the listbox (make the listbox transparent). Any ideas?
Thanks,
RvRvR
|