Results 1 to 21 of 21

Thread: Smoothing Jaggies - *Resolved*

  1. #1

    Thread Starter
    Fanatic Member Illspirit's Avatar
    Join Date
    Mar 2001
    Location
    Blackpool, England
    Posts
    815

    Arrow Smoothing Jaggies - *Resolved*

    Hey,

    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.
    Illspirit - [email protected]

    SmartBarXP Lead Developer
    SmartBarXP - The leading desktop sidebar application for Microsoft Windows XP

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    what you seek is called alphablending, here's an article about doing it with win32 api
    http://msdn.microsoft.com/library/de...tmaps_6ig4.asp
    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.

  3. #3
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    I have a VB function that will do alpha blending at about 3 seconds for a 800x600 image. It's fluid @ 40fps (Celly 533) for a 48x48 image.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  4. #4

    Thread Starter
    Fanatic Member Illspirit's Avatar
    Join Date
    Mar 2001
    Location
    Blackpool, England
    Posts
    815
    hey,

    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?
    Attached Images Attached Images  
    Illspirit - [email protected]

    SmartBarXP Lead Developer
    SmartBarXP - The leading desktop sidebar application for Microsoft Windows XP

  5. #5
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    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)

  6. #6

    Thread Starter
    Fanatic Member Illspirit's Avatar
    Join Date
    Mar 2001
    Location
    Blackpool, England
    Posts
    815
    hey,

    yea i thought that originally, but i get this when i try it:



    Attached Images Attached Images  
    Illspirit - [email protected]

    SmartBarXP Lead Developer
    SmartBarXP - The leading desktop sidebar application for Microsoft Windows XP

  7. #7

    Thread Starter
    Fanatic Member Illspirit's Avatar
    Join Date
    Mar 2001
    Location
    Blackpool, England
    Posts
    815
    am i doing something wrong? this is my blt code:

    VB Code:
    1. BitBlt lDCSubBuffer, 0, 0, 122, 102, hdc, X, Y, vbSrcCopy
    2.     BitBlt lDCSubBuffer, 0, 0, 122, 102, lDCClockFace, 122, 0, vbSrcPaint
    3.     BitBlt lDCSubBuffer, 0, 0, 122, 102, lDCClockFace, 0, 0, vbSrcAnd


    and this is the new clockface file:




    any ideas?
    Attached Images Attached Images  
    Illspirit - [email protected]

    SmartBarXP Lead Developer
    SmartBarXP - The leading desktop sidebar application for Microsoft Windows XP

  8. #8
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    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:
    1. Public Type mRGB
    2.     R As Byte
    3.     G As Byte
    4.     B As Byte
    5.     A As Byte
    6. End Type
    7. Public Const BI_RGB = 0&
    8. Public Const DIB_RGB_COLORS = 0
    9. Public Type BITMAP
    10.     bmType As Long
    11.     bmWidth As Long
    12.     bmHeight As Long
    13.     bmWidthBytes As Long
    14.     bmPlanes As Integer
    15.     bmBitsPixel As Integer
    16.     bmBits As Long
    17. End Type
    18. Private Type BITMAPINFOHEADER '40 bytes
    19.     biSize As Long
    20.     biWidth As Long
    21.     biHeight As Long
    22.     biPlanes As Integer
    23.     biBitCount As Integer
    24.     biCompression As Long
    25.     biSizeImage As Long
    26.     biXPelsPerMeter As Long
    27.     biYPelsPerMeter As Long
    28.     biClrUsed As Long
    29.     biClrImportant As Long
    30. End Type
    31. Public Type BITMAPINFO
    32.     bmiHeader As BITMAPINFOHEADER
    33.     bmiColors As mRGB
    34. End Type
    35. 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
    36. 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
    37. Public Declare Function GetObjectAPI Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
    38. Public Declare Function GetCurrentObject Lib "gdi32" (ByVal hdc As Long, ByVal uObjectType As Long) As Long
    39. Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    40.  
    41. Public Function Morph2D(x As Long, y As Long, NumRow As Long) As Long
    42.     Morph2D = (y - 1) * NumRow + x
    43. End Function
    44.  
    45. 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)
    46. Dim I As Long
    47. Dim j As Long
    48.  
    49. Dim TempR As Long
    50. Dim TempG As Long
    51. Dim TempB As Long
    52.  
    53. Dim AlphaVal As mRGB
    54. Dim SrcVal As mRGB
    55. Dim DestVal As mRGB
    56.  
    57. Dim dBitmap As Long
    58. Dim dBMP As BITMAP
    59. Dim dPic() As mRGB
    60. Dim dMem As BITMAPINFO
    61.  
    62. Dim sBitmap As Long
    63. Dim sBMP As BITMAP
    64. Dim sPic() As mRGB
    65. Dim sMem As BITMAPINFO
    66.  
    67. Dim aBitmap As Long
    68. Dim aBMP As BITMAP
    69. Dim aPic() As mRGB
    70. Dim aMem As BITMAPINFO
    71.  
    72.     dBitmap = GetCurrentObject(hDestDC, OBJ_BITMAP)
    73.     sBitmap = GetCurrentObject(hSrcDC, OBJ_BITMAP)
    74.     aBitmap = GetCurrentObject(hAlphaDC, OBJ_BITMAP)
    75.  
    76.     GetObjectAPI dBitmap, Len(dBMP), dBMP
    77.     GetObjectAPI sBitmap, Len(sBMP), sBMP
    78.     GetObjectAPI aBitmap, Len(aBMP), aBMP
    79.    
    80.     With dMem.bmiHeader
    81.         .biBitCount = 32
    82.         .biCompression = BI_RGB
    83.         .biPlanes = 1
    84.         .biSize = Len(dMem.bmiHeader)
    85.         .biWidth = dBMP.bmWidth
    86.         .biHeight = dBMP.bmHeight
    87.         ReDim Preserve dPic(0 To (.biWidth * .biHeight) - 1) As mRGB
    88.     End With
    89.      
    90.     GetDIBits hDestDC, dBitmap, 0, dBMP.bmHeight, dPic(0), dMem, DIB_RGB_COLORS
    91.    
    92.     With sMem.bmiHeader
    93.         .biBitCount = 32
    94.         .biCompression = BI_RGB
    95.         .biPlanes = 1
    96.         .biSize = Len(sMem.bmiHeader)
    97.         .biWidth = sBMP.bmWidth
    98.         .biHeight = sBMP.bmHeight
    99.         ReDim Preserve sPic(0 To (.biWidth * .biHeight) - 1) As mRGB
    100.     End With
    101.    
    102.     GetDIBits hSrcDC, sBitmap, 0, sBMP.bmHeight, sPic(0), sMem, DIB_RGB_COLORS
    103.    
    104.     With aMem.bmiHeader
    105.         .biBitCount = 32
    106.         .biCompression = BI_RGB
    107.         .biPlanes = 1
    108.         .biSize = Len(aMem.bmiHeader)
    109.         .biWidth = aBMP.bmWidth
    110.         .biHeight = aBMP.bmHeight
    111.         ReDim Preserve aPic(0 To (.biWidth * .biHeight) - 1) As mRGB
    112.     End With
    113.    
    114.     GetDIBits hAlphaDC, aBitmap, 0, aBMP.bmHeight, aPic(0), aMem, DIB_RGB_COLORS
    115.    
    116.     For j = y To y + (nHeight - 1)
    117.         For I = x To x + (nWidth - 1)
    118.            
    119.             DestVal = dPic(Morph2D(I, dBMP.bmHeight - j, dBMP.bmWidth)) 'dColour.L = GetPixel(hDestDC, I, J)
    120.             SrcVal = sPic(Morph2D(I - x + xSrc, sBMP.bmHeight - (j - y + ySrc), sBMP.bmWidth)) 'sColour.L = GetPixel(hSrcDC, I - x + xSrc, J - y + ySrc)
    121.             AlphaVal = aPic(Morph2D(I - x + xSrc, aBMP.bmHeight - (j - y + ySrc), aBMP.bmWidth)) 'aColour.L = GetPixel(hAlphaDC, I - x + xSrc, J - y + ySrc)
    122.            
    123.             AlphaVal.R = 255 - AlphaVal.R
    124.             AlphaVal.G = 255 - AlphaVal.G
    125.             AlphaVal.B = 255 - AlphaVal.B
    126.            
    127.             TempR = (AlphaVal.R * CLng(SrcVal.R + 256 - DestVal.R)) / 256 + DestVal.R - AlphaVal.R
    128.             TempG = (AlphaVal.G * CLng(SrcVal.G + 256 - DestVal.G)) / 256 + DestVal.G - AlphaVal.G
    129.             TempB = (AlphaVal.B * CLng(SrcVal.B + 256 - DestVal.B)) / 256 + DestVal.B - AlphaVal.B
    130.            
    131.             '// 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.
    132.             With dPic(Morph2D(I, dBMP.bmHeight - j, dBMP.bmWidth))
    133.                 .B = TempR
    134.                 .G = TempG
    135.                 .R = TempB
    136.             End With
    137.            
    138.         Next I
    139.     Next j
    140.    
    141.     SetDIBits hDestDC, dBitmap, 0, dBMP.bmHeight, dPic(0), dMem, DIB_RGB_COLORS
    142.    
    143.     DeleteObject dBitmap
    144.     ReDim dPic(0)
    145.    
    146.     DeleteObject sBitmap
    147.     ReDim sPic(0)
    148.    
    149.     DeleteObject aBitmap
    150.     ReDim aPic(0)
    151.    
    152. End Function
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  9. #9

    Thread Starter
    Fanatic Member Illspirit's Avatar
    Join Date
    Mar 2001
    Location
    Blackpool, England
    Posts
    815
    hey,

    thanx for that function, ive put it in a module, but am not sure how i'd use it What are the source and alpha DCs that i pass to it?

    thanx,
    Illspirit
    Illspirit - [email protected]

    SmartBarXP Lead Developer
    SmartBarXP - The leading desktop sidebar application for Microsoft Windows XP

  10. #10
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    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.

  11. #11

    Thread Starter
    Fanatic Member Illspirit's Avatar
    Join Date
    Mar 2001
    Location
    Blackpool, England
    Posts
    815
    yea, but wots the alpha pic? i tried using the mask but the function didnt do anything
    Illspirit - [email protected]

    SmartBarXP Lead Developer
    SmartBarXP - The leading desktop sidebar application for Microsoft Windows XP

  12. #12
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    You use it like so:
    VB Code:
    1. AlphaBlt Dest.hDC, 63, 63, 200, 150, picClock.hDC, picClockMask.hDC, 0, 0
    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)

  13. #13

    Thread Starter
    Fanatic Member Illspirit's Avatar
    Join Date
    Mar 2001
    Location
    Blackpool, England
    Posts
    815
    hey,

    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:
    1. BitBlt lDCSubBuffer, 0, 0, 122, 102, hdc, x, y, vbSrcCopy
    2.     BitBlt lDCSubBuffer2, 0, 0, 122, 102, lDCClockFace, 122, 0, vbSrcCopy
    3.  
    4. Debug.Print "X"
    5.     AlphaBltFast lDCSubBuffer, 0, 0, 122, 120, lDCClockFace, lDCSubBuffer2, 0, 0
    6. Debug.Print "Y"    'Doesnt print this!
    Illspirit - [email protected]

    SmartBarXP Lead Developer
    SmartBarXP - The leading desktop sidebar application for Microsoft Windows XP

  14. #14
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    LOL!
    VB Code:
    1. Public Const OBJ_BITMAP = 7
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  15. #15

    Thread Starter
    Fanatic Member Illspirit's Avatar
    Join Date
    Mar 2001
    Location
    Blackpool, England
    Posts
    815
    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.

    Attached Images Attached Images  
    Illspirit - [email protected]

    SmartBarXP Lead Developer
    SmartBarXP - The leading desktop sidebar application for Microsoft Windows XP

  16. #16
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    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:
    1. '// 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.
    2.             With dPic(Morph2D(I, dBMP.bmHeight - j, dBMP.bmWidth))
    3.                 .B = TempR
    4.                 .G = TempG
    5.                 .R = TempB
    6.             End With
    To this:
    VB Code:
    1. With dPic(Morph2D(I, dBMP.bmHeight - j, dBMP.bmWidth))
    2.                 .R = TempR
    3.                 .G = TempG
    4.                 .B = TempB
    5.             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)

  17. #17

    Thread Starter
    Fanatic Member Illspirit's Avatar
    Join Date
    Mar 2001
    Location
    Blackpool, England
    Posts
    815
    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.

    thanx, i'll let you know if it has worked
    Illspirit - [email protected]

    SmartBarXP Lead Developer
    SmartBarXP - The leading desktop sidebar application for Microsoft Windows XP

  18. #18

    Thread Starter
    Fanatic Member Illspirit's Avatar
    Join Date
    Mar 2001
    Location
    Blackpool, England
    Posts
    815

    Thumbs up fantastic, it worked like a charm

    thanx alot for your help!!
    Illspirit - [email protected]

    SmartBarXP Lead Developer
    SmartBarXP - The leading desktop sidebar application for Microsoft Windows XP

  19. #19
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Can I see what it looks like? I've never actually had a real-life example of this function
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  20. #20

    Thread Starter
    Fanatic Member Illspirit's Avatar
    Join Date
    Mar 2001
    Location
    Blackpool, England
    Posts
    815
    yea, here it is on the 3 xp themes

    Attached Images Attached Images  
    Illspirit - [email protected]

    SmartBarXP Lead Developer
    SmartBarXP - The leading desktop sidebar application for Microsoft Windows XP

  21. #21
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    That looks awesome Thanks for sharing!
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width