Dayle Rees 08-03-2003, 08:04 AM Hi guys,
I've got this problem where i need to make a program which shows like on the attatched image.
As you can see it needs to use transparency ( best if i could give a range ) .. it also has to be either a cusom shape... or maybe could be done using a semi transparent image on a transparent form. Ive tried this before i made the form transparent, and loaded a Transparent GIF but all the transparencies in the GIF came out white.
Anyone know a way I can do it?
Thanks.
D.z
GavinO 08-03-2003, 08:33 AM You can do single level transparency with some API, I'd recommend looking at elitevb.com for an example, they have a nice one. The alpha blending that you seem to want is much more difficult .... not really sure where to point you, other than that it is asked for on a regular basis, and that a forum search might get you some answers.
zak2zak 08-03-2003, 09:16 AM May Be This helps.......
You need to use API as mentioned below:
SetWindowRgn
DeleteObject
CreateCompatibleDC
SelectObject
GetObject
CreateRectRgn
CombineRgn
DeleteDC
GetPixel
'In the procedure or events that you want to triger just set as shown below below:
DoEvents 'if the picture is large & U want other process to be running
Call SetRegion(picSelect, &HFFFFFF) 'here I set the transparent pixel to White
'Or
SetRegion picSelect, &HFFFFFF
I have a module attached to this reply which has the full source
And is ready to use. Feel free to try..
GavinO 08-03-2003, 10:32 AM In addition to what he had, instead of pure white, you want to blend the white with the color behind it, which involves finding that color (don't ask me!) and doing a proportional blend. I think that the blend is something like: break out each channel of each color, multiply it by the percentage that that color is in the final pixel, add the channels, and recompose the color. Lengthy process; it would help to find an API function to do it.
Dayle Rees 08-04-2003, 11:38 AM Yeah i get it, li'll give it a go and let u know what i can come up with, thanks.
Dayle Rees 08-04-2003, 12:23 PM On using the mod above i get User Defined type not defined, on declaring BM as bitmap, was i meant to include any references?
Dz
reboot 08-04-2003, 12:26 PM You need to define the BITMAP type.
passel 08-04-2003, 02:03 PM Hi guys,
I've got this problem where i need to make a program which shows like on the attatched image.
As you can see it needs to use transparency ( best if i could give a range ) .. it also has to be either a cusom shape... or maybe could be done using a semi transparent image on a transparent form. Ive tried this before i made the form transparent, and loaded a Transparent GIF but all the transparencies in the GIF came out white.
Anyone know a way I can do it?
Thanks.
D.z
Here's an example of a way to emulate what you want, but may not be what you're looking for.
Doesn't use any API though.
For those who don't want to download, Just add a command button and put a picturebox on the form, stretch it horizontally a bit, and paste this code in the declarations area.
Private Sub Command1_Click()
Dim colr As Long
Dim rc As Single, gc As Single, bc As Single
Dim rb As Long, gb As Long, bb As Long
Dim b As Single, r As Single, g As Single
With Picture1
.BorderStyle = 0 'none
colr = Me.Point(15, 15)
bb = (colr And &HFF0000) \ &H10000
gb = (colr And &HFF00&) \ &H100
rb = colr And &HFF
rc = (&HFF - rb) / .ScaleWidth
gc = (&HFF - gb) / .ScaleWidth
bc = (&HFF - bb) / .ScaleWidth
colr = &HFFFFFF
r = 255: g = 255: b = 255
For i = 0 To .ScaleWidth
Picture1.Line (i, 0)-(i, .ScaleHeight), colr
r = r - rc: g = g - gc: b = b - bc
colr = Int(b) * &H10000 + Int(g) * &H100 + Int(r)
Next
.CurrentX = 5: .CurrentY = 5
Picture1.Print "This is a simulation of shading"
End With
End Sub
zak2zak 08-05-2003, 06:06 AM May Be This Helps..
'Just Add In the mod Declarations
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 Const RGN_XOR = 3 'Creates the union of two combined regions except for any overlapping areas.
Private Const RGN_DIFF = 4 'Combines the parts of hrgnSrc1 that are not part of hrgnSrc2.
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 OffsetRgn Lib "gdi32" (ByVal hRgn As Long, ByVal x As Long, ByVal y 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 CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Const SM_CYCAPTION = 4 'Height of windows caption
Const SM_CXBORDER = 5 'Width of no-sizable borders
Const SM_CYBORDER = 6 'Height of non-sizable borders
Const SM_CXDLGFRAME = 7 'Width of dialog box borders
Const SM_CYDLGFRAME = 8 'Height of dialog box borders
Private Declare Function GetSystemMetrics Lib "USER32" (ByVal nIndex As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject 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 oldRgn As Long
Private Dragging As Boolean
Private dragX As Long
Private dragY As Long
Private A As Boolean, b As Boolean
Private J As Byte
Dim x As Long 'Used to loop thru the pixels
Dim y As Long 'Used to loop thru the pixels
Dim wid As Long 'Width of picture - Used to loop thru the pixels
Dim hgt As Long 'Height of picture - Used to loop thru the pixels
Dim ttlHeight As Long 'Height of the form's titlebar & top border in pixels
Dim xBorder As Long 'Width of the form's side borders in pixels
Dim rgnPic As Long 'Region of the picture
Dim rgnPixel As Long 'Region of a pixel - used to subtract out tiny areas
Dim colPixel As Long 'Color of a pixel in the picture
Dim picDC As Long 'Temporary device context used to get pixel color info
Dim oldBmp As Long '1x1 bitmap created when picDC is created.
Dim transColor As Long
'Calculate the size of the picture which we will fit the form to
wid = Me.ScaleX(Me.Picture.Width, vbHimetric, vbPixels)
hgt = Me.ScaleX(Me.Picture.Height, vbHimetric, vbPixels)
'Create a region the same size as our picture dimensions
rgnPic = CreateRectRgn(0, 0, wid, hgt)
'Select our picture into a temporary device context so we can
' read the color information.
picDC = CreateCompatibleDC(Me.hdc)
oldBmp = SelectObject(picDC, Me.Picture.handle)
transColor = GetPixel(picDC, 0, 0)
'Loop thru all pixels in the picture
For y = 0 To hgt
For x = 0 To wid
' check the color of each pixel
colPixel = GetPixel(picDC, x, y)
If colPixel = transColor Then
'If the color is our mask color (Pure red in this case) then
' create a tiny region for it and remove it from the picture
rgnPixel = CreateRectRgn(x, y, x + 1, y + 1)
CombineRgn rgnPic, rgnPic, rgnPixel, RGN_XOR
'Clean up our graphics resource
DeleteObject rgnPixel
End If
Next x
Next y
'Clean up our temporary picture resources
SelectObject picDC, oldBmp
DeleteDC picDC
DeleteObject oldBmp
'Calculate how much we need to offset the region so it lays directly ontop
' of the form's picture (client x,y instead of form x,y)
ttlHeight = GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYDLGFRAME)
xBorder = GetSystemMetrics(SM_CXDLGFRAME)
'Offset our region by the calculated amount
OffsetRgn rgnPic, xBorder, ttlHeight
'Fit the window to our new region
' If its the first time, store the original handle.
' If its more than the first time, just delete the previous custom handle.
If oldRgn = 0 Then
oldRgn = SetWindowRgn(Me.hwnd, rgnPic, True)
Else
DeleteObject SetWindowRgn(Me.hwnd, rgnPic, True)
End If
end sub
------------------------------------
this comes i think from psc aint sure, it works tho.. ( i got an old p200 on which it works 2 * * * * ). But it is slow cuz it goes thu the whole form, better if you know what regions 2 cut out and just do those, but since i use it for a slpashscreen with a very complicated picture i use it like this
*EDIT* this does no do shading, it's either transparant or not
|