I've been looking into this for a while now, but I'm not really sure how I'd accomplish it. What I'd like to do is be able to open an image, find out its width and height and then examine the RGB value of each pixel.
I'm only really interested in a single image format at the moment (any of: .gif,.jpeg,.bmp,.png) but if anyone has a more general solution that would be rather welcome!
Thanks
Reading an image pixel by pixel
-
- Enthusiast
- Posts: 731
- Joined: Wed Apr 21, 2004 7:12 pm
Reading an image pixel by pixel
~I see one problem with your reasoning: the fact is thats not a chicken~
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
- Fluid Byte
- Addict
- Posts: 2336
- Joined: Fri Jul 21, 2006 4:41 am
- Location: Berlin, Germany
Is this any help?
Code: Select all
CreateImage(0,320,240)
hdc = StartDrawing(ImageOutput(0))
IW = ImageWidth(0) : IH = ImageHeight(0)
For i=0 To IH-1
colref = i * 100 / (IH-1)
Box(0,i,IW,1,RGB(155 + colref,colref,0))
Next
lpvBits = AllocateMemory(IW * IH * 4)
bmi.BITMAPINFO
bmi\bmiHeader\biSize = SizeOf(BITMAPINFOHEADER)
bmi\bmiHeader\biWidth = IW
bmi\bmiHeader\biHeight = IH
bmi\bmiHeader\biPlanes = 1
bmi\bmiHeader\biBitCount = 32
bmi\bmiHeader\biCompression = #BI_RGB
GetDIBits_(hdc,ImageID(0),0,IH,lpvBits,bmi,#DIB_RGB_COLORS)
*pxData.LONG = lpvBits
For i=1 To (IW * IH)
R = *pxData\l & $FF
G = *pxData\l >> 8 & $FF
B = *pxData\l >> 16
Noise = 30
Result = Noise - Random(Noise * 2)
R + Result : G + Result : B + Result
If Result < 0
If R < 0 : R = 0 : EndIf
If G < 0 : G = 0 : EndIf
If B < 0 : B = 0 : EndIf
Else
If R > 255 : R = 255 : EndIf
If g > 255 : G = 255 : EndIf
If B > 255 : B = 255 : EndIf
EndIf
*pxData\l = R | G << 8 | B << 16
*pxData + 4
Next
SetDIBits_(hdc,ImageID(0),0,IH,lpvBits,bmi,#DIB_RGB_COLORS)
FreeMemory(lpvBits)
StopDrawing()
OpenWindow(0,0,0,320,240,"Bitmap Manipulation",#WS_SYSMENU | #WS_CAPTION | 1)
CreateGadgetList(WindowID(0))
ImageGadget(0,0,0,0,0,ImageID(0))
While WaitWindowEvent() ! 16 : Wend
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
-
- Enthusiast
- Posts: 731
- Joined: Wed Apr 21, 2004 7:12 pm