Ooops
November 28, 2020, 11:24:19 AM

Author Topic: [bb] Icon to Blitz Image by John Blackledge [ 1+ years ago ]  (Read 427 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : Icon to Blitz Image
Author : John Blackledge
Posted : 1+ years ago

Description : ;Finally solved the colour problem!
;Microsoft store icon colours in reverse, Blue-Geen-Red!


Code :
Code: BlitzBasic
  1. Graphics3D 640,480,32
  2.  
  3. Const SM_CXICON = 11, SM_CYICON = 12
  4. iconWidth = api_GetSystemMetrics(SM_CXICON)
  5. iconHeight = api_GetSystemMetrics(SM_CYICON)
  6.  
  7. szExeName$ = "E:Blitz3DBlitz3D.exe"
  8. hIcon = api_ExtractIcon(0, szExeName$, 0)
  9.  
  10. ; Get a Windows drawing surface
  11. hDC = api_GetDC(0)
  12. ; Get a compatible that we can use.
  13. hMemDC= api_CreateCompatibleDC(hDC)
  14.  
  15. ; Create a blank Windows bitmap
  16. hMemBmp= api_CreateCompatibleBitmap( hDC, iconWidth, iconHeight )
  17.  
  18. ; Draw the icon on the bitmap.
  19. api_SelectObject(hMemDC, hMemBmp)
  20. api_DrawIcon(hMemDC, 0, 0, hIcon)
  21.  
  22. ; Create a blank Blitz image, and set it as the drawing buffer.
  23. blitzImage = CreateImage( iconWidth, iconHeight )
  24. SetBuffer ImageBuffer(blitzImage)
  25.  
  26. ; Copy the icon pixels from the Windows bitmap in the Blitz image
  27. For x = 0 To iconWidth-1
  28.         For y = 0 To iconHeight-1
  29.                 ; This was why my colours were originally wrong.
  30.                 ; M$ store icon pixels in Blue-Green-Red format, not Red-Blue-Green!!!!
  31.                 ; ... so swap them.
  32.                 bgr = api_GetPixel(hMemDC, x, y)
  33.                 b = bgr Shr 16 And %11111111
  34.                 g = bgr Shr 8 And %11111111
  35.                 r = bgr And %11111111
  36.                 rgb = (r Shl 16) Or (g Shl 8) Or b
  37.                 WritePixel(x, y, rgb)
  38.         Next
  39. Next
  40.  
  41. ; Reset the drawing buffer back to Backbuffer for normal use.
  42. SetBuffer BackBuffer()
  43. While Not KeyHit(1)
  44.         DrawImage blitzImage,0,0
  45.         Flip
  46. Wend
  47.  
  48. ;Clean all memory objects.
  49. api_ReleaseDC(0, hDC)
  50. api_DeleteDC(hMemDC)
  51. api_DeleteObject(hMemBMP)
  52. End


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal