Pointer to an image?
Posted: Wed Feb 11, 2004 11:31 am
Does anyone know how to get the pointer to an image in PB?
Help needed....
Help needed....
http://www.purebasic.com
https://www.purebasic.fr/english/
Code: Select all
pointer=LoadImage(0,"C:\MyPic.bmp")
Code: Select all
LoadImage(0,"C:\MyPic.bmp")
pointer=ImageID()
8O this will peek at ptr's address... and return the content of ptr...You need the @ sign, so use this instead: Debug PeekL(@ptr)
With a sprite , you can use drawingbuffer in a startdrawing/stopdrawing block:Maybe I asked wrong. I want the pointer to the first pixel of the image...
Any idea. Seems that it this is not possible...
Code: Select all
; first, open ascreen and load asprite
startdrawing(spriteoutput(#mysprite))
pixelptr=drawingbuffer()
stopdrawing()
Depends on the work you have to do in the image. If you only want to set or read some Points leave it alone. If you have very complex things to do, go for it. I use these Functions which are largely from Danilo (who else?)freak wrote:Because the sprite functions use DirectX, and the image functions use
Windows GDI.
You can use GetDIBits_() to copy the image data into a memory buffer,
and after modifying it, use SetDIBits_() to copy them back.
Dunno how fast that is though.
Code: Select all
Procedure CopyImageToMem(Img.l, mem.l)
Protected bmi.myBITMAPINFO
Protected w.l, h.l, hBmp.l, hDC.l
UseImage(Img)
w = ImageWidth()
h = ImageHeight()
hBmp = ImageID()
bmi\bmiHeader\biSize = SizeOf(BITMAPINFOHEADER)
bmi\bmiHeader\biWidth = w
bmi\bmiHeader\biHeight = -h
bmi\bmiHeader\biPlanes = 1
bmi\bmiHeader\biBitCount = 32
bmi\bmiHeader\biCompression = #BI_RGB
hDC = StartDrawing( ImageOutput() )
If GetDIBits_(hDC, hBmp, 0, h, mem, bmi, #DIB_RGB_COLORS)
StopDrawing()
ProcedureReturn #True
Else
StopDrawing()
ProcedureReturn #False
EndIf
EndProcedure
Procedure CopyMemToImage(mem.l, Img.l)
Protected bmi.myBITMAPINFO
Protected w.l, h.l, hBmp.l, hDC.l
UseImage(Img)
w = ImageWidth()
h = ImageHeight()
hBmp = ImageID()
bmi\bmiHeader\biSize = SizeOf(BITMAPINFOHEADER)
bmi\bmiHeader\biWidth = w
bmi\bmiHeader\biHeight = -h
bmi\bmiHeader\biPlanes = 1
bmi\bmiHeader\biBitCount = 32
bmi\bmiHeader\biCompression = #BI_RGB
hDC = StartDrawing( ImageOutput() )
If SetDIBits_(hDC, hBmp, 0, h, mem, bmi, #DIB_RGB_COLORS)
StopDrawing()
ProcedureReturn #True
Else
StopDrawing()
ProcedureReturn #False
EndIf
EndProcedure