I am using BitBlt to draw a clock face onto a window. The clock face is a circle, and there is a mask that makes it transparent around the edge. The problem is that the background that the clock is drawn onto could be any colour or pattern, and i cant work out a way to make the thing look smooth on all backgrounds. I have tried to modify the image itself but i cant get it to look right
Ive searched the forum and most of the questions like this were not answered because speed was an issue. I dont mind any speed issues here though, seeing as though the clock face only very rarely gets re drawn, so i was wondering if anyone knew any way to do this?
Thanx,
Illspirit
Last edited by Illspirit; Jan 20th, 2003 at 05:03 PM.
Use
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
i am using alphablending to add a shine effect to my clock over the top of the hands, however i'm not sure how i'd use it here. This is an example of a clock face:
How would i tell it to alpha blend the edge of the clock only?
What you do is you use, instead of black or white in your mask, any grayscale value. Black = nothing copied, white = everything copied, RGB(63, 63, 63) = 1/4 image copied (blended with the background). For example, you would make the edges of the mask gradually fade out to black instead of immediately turn into black.
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
(Just a heads-up)
No, it doesn't work with just BitBlt. Here's a function I wrote, albeit a bit slow, that will do what you want (place in a module):
VB Code:
Public Type mRGB
R As Byte
G As Byte
B As Byte
A As Byte
End Type
Public Const BI_RGB = 0&
Public Const DIB_RGB_COLORS = 0
Public 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 BITMAPINFOHEADER '40 bytes
biSize As Long
biWidth As Long
biHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End Type
Public Type BITMAPINFO
bmiHeader As BITMAPINFOHEADER
bmiColors As mRGB
End Type
Public Declare Function GetDIBits Lib "gdi32" (ByVal aHDC As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO, ByVal wUsage As Long) As Long
Public Declare Function SetDIBits Lib "gdi32" (ByVal hdc As Long, ByVal hBitmap As Long, ByVal nStartScan As Long, ByVal nNumScans As Long, lpBits As Any, lpBI As BITMAPINFO, ByVal wUsage As Long) As Long
Public Declare Function GetObjectAPI Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Public Declare Function GetCurrentObject Lib "gdi32" (ByVal hdc As Long, ByVal uObjectType As Long) As Long
Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Public Function Morph2D(x As Long, y As Long, NumRow As Long) As Long
Morph2D = (y - 1) * NumRow + x
End Function
Public Function AlphaBltFast(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 hAlphaDC As Long, ByVal xSrc As Long, ByVal ySrc As Long)
Dim I As Long
Dim j As Long
Dim TempR As Long
Dim TempG As Long
Dim TempB As Long
Dim AlphaVal As mRGB
Dim SrcVal As mRGB
Dim DestVal As mRGB
Dim dBitmap As Long
Dim dBMP As BITMAP
Dim dPic() As mRGB
Dim dMem As BITMAPINFO
Dim sBitmap As Long
Dim sBMP As BITMAP
Dim sPic() As mRGB
Dim sMem As BITMAPINFO
Dim aBitmap As Long
Dim aBMP As BITMAP
Dim aPic() As mRGB
Dim aMem As BITMAPINFO
dBitmap = GetCurrentObject(hDestDC, OBJ_BITMAP)
sBitmap = GetCurrentObject(hSrcDC, OBJ_BITMAP)
aBitmap = GetCurrentObject(hAlphaDC, OBJ_BITMAP)
GetObjectAPI dBitmap, Len(dBMP), dBMP
GetObjectAPI sBitmap, Len(sBMP), sBMP
GetObjectAPI aBitmap, Len(aBMP), aBMP
With dMem.bmiHeader
.biBitCount = 32
.biCompression = BI_RGB
.biPlanes = 1
.biSize = Len(dMem.bmiHeader)
.biWidth = dBMP.bmWidth
.biHeight = dBMP.bmHeight
ReDim Preserve dPic(0 To (.biWidth * .biHeight) - 1) As mRGB
The SourceDC is the DC for your clock pic(PictureBox.hDC if its in a PictureBox), AlphaDC would be the alpha pic (PictureBox.hDC if its in a pictureBox).
When your thread has been resolved please edit the original post in the thread ()
and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.
This shows you blitting picClock to Dest at (63, 63) with a width of (200, 150), and the alpha channel being picClockMask. The function will read picClock and picClockMask from (0, 0) to (199, 149).
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
(Just a heads-up)
yea, i tried that, but first i got an error saying OBJ_BITMAP wasnt declared. So i removed Option Explicit from the module and tried it again and nothing was drawn. It doesnt even carry on past the function call to draw the hands, it just stops at that call.
VB Code:
BitBlt lDCSubBuffer, 0, 0, 122, 102, hdc, x, y, vbSrcCopy
hmm, well i got it to do something, but it masked the wrong parts, so i inverted the mask and now its made the clock face have an orange tinted face, and the masked part round the face flashes between normal and orange tinted everytime its redrawn as the second hand moves.
Hmm. Try changing that line in the code, where it has the explanation for the change in colour space. I thought I had stopped incorrect results from happening there (all of my tests have so far been grayscale), but it actually makes these incorrect results happen. So, change this:
VB Code:
'// Explanation: VB uses R, G, B order. Bitmap uses B, G, R, A order. Therefore, we must switch around the B and the R values.
With dPic(Morph2D(I, dBMP.bmHeight - j, dBMP.bmWidth))
.B = TempR
.G = TempG
.R = TempB
End With
To this:
VB Code:
With dPic(Morph2D(I, dBMP.bmHeight - j, dBMP.bmWidth))
.R = TempR
.G = TempG
.B = TempB
End With
All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
(Just a heads-up)
righty dokey, i did that and it seems to be working, but the rest of my clock drawing code is screwing it up coz its drawing the new face over the last face and loosing the faded edge. I'll sort that tomorrow, but so far its looking like the problems solved.