I'm still very much a PB beginner but getting a bit better with practice.
I want to simplify the 24 bit RGB data in a colour bitmap into a 'custom' 8-bit format (imagine it's a grayscale, although that's not exactly what I'll be doing). Assume the original image is a .jpg. I then want to do a bit of threshold detection math on the custom data. Finally, I want to show a (rudimentary) thumbnail image using the custom data,
My solution:
Using the .jpg converter plug-in, load the image.
Save the loaded image as a .bmp
Open the .bmp as a 'binary' file (do we have those in PB?)
Read the first part of the file, ie the .bmp header- get file length, image height/width etc
DIM array.l() as a store for the 8-bit data
Read sequentially the R+G+B data from the .bmp file
Do the 24 to 8 bit math conversion and store result in array()
Do the 'analysis' stuff on array() & save to disk
Read through array(), then use a palette to return some 'pseudoRGB' values
Display the pseudoRGB using PLOT
I've tried the PLOT routine by simply drawing on a window. I don't have a particular speed problem with that. I expect it could display faster using StartDrawing(ImageOutput)/ImageGadget/LoadImage or better still, drawn onto a WindowedScreen. That's not a priority.
This seems very kludgy. Can I access the actual image data in memory using PEEK? What are the other better ways?
Thanks.
Al
Where's my image data in memory?
-
- Addict
- Posts: 1265
- Joined: Wed Feb 28, 2007 9:13 am
- Location: London
Change the image's colour depth. Here's some code.
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
You can use the API's GetObject_(), GetDIBits_(), and some others if you're on Windows. Here's a thread that deals somewhat in the areas you want to touch, with some usage examples:
http://www.purebasic.fr/english/viewtopic.php?t=35627
http://www.purebasic.fr/english/viewtopic.php?t=35627
BERESHEIT
This might actually be a good feature request, I was fooling around with storing images in databases (in Yenc actually) and found it annoying I couldn't seem to find some statement to retrieve them from or create them in memory...
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany