24bit to 32bit PNG
24bit to 32bit PNG
I have images that are 24bit with a black background. I was wondering how I would go about making the black background the alpha channel?
www.posemotion.com
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.
Thanks dige, I look into it.dige wrote:Just an idea: CreateImage() with 32Bit and draw the 24Bit Image
with DrawImage() into it?
www.posemotion.com
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.
- netmaestro
- PureBasic Bullfrog

- Posts: 8452
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Nope.netmaestro wrote:Do you need to save the images back to disk?
www.posemotion.com
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.
- netmaestro
- PureBasic Bullfrog

- Posts: 8452
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
No problem, thanks!netmaestro wrote:The job is simple then, I'll post code for you tomorrow if you don't have it solved by then. Sorry I can do nothing tonight, my laneway is 250 feet long and there's three feet of snow in it.
www.posemotion.com
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.
- netmaestro
- PureBasic Bullfrog

- Posts: 8452
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Code: Select all
; Start with a 24bit bmp image with a black background
CreateImage(0, 128,128,24)
StartDrawing(ImageOutput(0))
Circle(64,64,64,#Red)
StopDrawing()
; Create a new 32bit image to serve as the result and draw first image to it
CreateImage(1, 128,128,32)
StartDrawing(ImageOutput(1))
DrawImage(ImageID(0),0,0)
StopDrawing()
; Verify that the 32bit image is created correctly
OpenWindow(0,0,0,128,128, "Result", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
StartDrawing(WindowOutput(0))
DrawImage(ImageID(1),0,0)
StopDrawing()
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
; Show that the 32bit image's alphachannel is unused as yet - DrawAlphaImage can't show it
OpenWindow(0,0,0,128,128, "Result", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
StartDrawing(WindowOutput(0))
DrawAlphaImage(ImageID(1),0,0)
StopDrawing()
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
; Set the alphachannel data in the image to show full intensity for all colors
; except black, and no intensity for any black pixels
GetObject_(ImageID(1), SizeOf(BITMAP), bmp.BITMAP)
*bits = bmp\bmBits
For i=0 To bmp\bmHeight-1
For j=0 To bmp\bmWidthBytes-1 Step 4
*px.RGBQUAD = *bits + bmp\bmWidthBytes * i + j
With *px
If \rgbBlue=0 And \rgbGreen=0 And \rgbRed=0
*px\rgbReserved = 0
Else
*px\rgbReserved = $FF
EndIf
EndWith
Next
Next
; Now repeat the second test and see that the alphachannel is working correctly
; with DrawAlphaImage()
OpenWindow(0,0,0,128,128, "Result", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
StartDrawing(WindowOutput(0))
DrawAlphaImage(ImageID(1),0,0)
StopDrawing()
Repeat:Until WaitWindowEvent()=#PB_Event_CloseWindow
; Now try a test with sprites and see if it's working with #PB_Sprite_Alphablending
InitSprite():InitSprite3D()
OpenWindow(0,0,0,640,480,"Sprite Test",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0),0,0,640,480,0,0,0)
CreateSprite(0,128,128,#PB_Sprite_Texture|#PB_Sprite_AlphaBlending)
StartDrawing(SpriteOutput(0))
DrawAlphaImage(ImageID(1),0,0)
StopDrawing()
CreateSprite3D(0,0)
Repeat
ev = WindowEvent()
ClearScreen(GetSysColor_(#COLOR_BTNFACE))
Start3D()
DisplaySprite3D(0, 200,200)
Stop3D()
FlipBuffers()
Until ev = #PB_Event_CloseWindow
; Duh-duh duh-duh duh-duh - That's all, folks!
BERESHEIT
Thanks for your efforts netmaestro but when you load an image it basically just erases the background up to the point where the actual image starts. The blue bubbles are suppose to be transparent. Here's the image I used...
Download BMP Image
Download BMP Image
www.posemotion.com
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.
I'm looking for something similar to Gimp's "Color to Alpha", that would make the above bmp look like this...


www.posemotion.com
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.
- netmaestro
- PureBasic Bullfrog

- Posts: 8452
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
Thanks netmaestro! I'm still thinking as well.netmaestro wrote:That result would require a more complex algorithm, which I'm not exactly sure how to write. But it is an interesting little challenge, and I'm going to see what I can come up with in the coming days if no other solutions get posted in the meantime.
I was just wondering if each pixel is scanned for there color value and if anything fits the range of RGB(0,0,0) that pixel was erased. But if that RGB(0,0,0) pixel had a slight color value, (lets say Red(Color) = 20), then RGB(255,0,0) would be drawn to the alpha channel with a transparency value of 20.
So it might be better to create a bmp with the background color of RGB(255,0,255) instead of black. Just incase the images has black outlines.
www.posemotion.com
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.
PureBasic Tools for OS X: PureMonitor, plist Tool, Data Maker & App Chef
Even the vine knows it surroundings but the man with eyes does not.
-
adamredwoods
- New User

- Posts: 9
- Joined: Wed Feb 13, 2008 12:58 am
- Location: California
Side question:
Is there a way to do the above code line
On the Mac in OSX?
Many Thanks.
Is there a way to do the above code line
Code: Select all
GetObject_(ImageID(1), SizeOf(BITMAP), bmp.BITMAP)Many Thanks.
