Pointer to an image?
Pointer to an image?
Does anyone know how to get the pointer to an image in PB?
Help needed....
Help needed....
Re: Pointer to an image?
> how to get the pointer to an image in PB?
If you load the image, it's stored in the return value:
If not, use the ImageID() command:
If you load the image, it's stored in the return value:
Code: Select all
pointer=LoadImage(0,"C:\MyPic.bmp")
Code: Select all
LoadImage(0,"C:\MyPic.bmp")
pointer=ImageID()
hm, seems that it doesnt work...
i made this, just to test the pointer...
CreateImage(1, 100, 30)
ptr.l = UseImage(1)
Debug ptr
ptr.l = ImageID()
Debug ptr
Debug PeekL(ptr)
End
run it in debug mode. It crashes with the peekL command. The help says that the return value is the image ID, not the pointer to the image data (the pixels)
Maybe I asked wrong. I want the pointer to the first pixel of the image...
Any idea. Seems that it this is not possible...
i made this, just to test the pointer...
CreateImage(1, 100, 30)
ptr.l = UseImage(1)
Debug ptr
ptr.l = ImageID()
Debug ptr
Debug PeekL(ptr)
End
run it in debug mode. It crashes with the peekL command. The help says that the return value is the image ID, not the pointer to the image data (the pixels)
Maybe I asked wrong. I want the pointer to the first pixel of the image...
Any idea. Seems that it this is not possible...
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()
-
freedimension
- Enthusiast

- Posts: 613
- Joined: Tue May 06, 2003 2:50 pm
- Location: Germany
- Contact:
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
Ok, here are the results:
All the internal PB stuff does NOT return the pointer, it return the handle to the image! Fred said that there is no internal way to get the pointer to an image.
The GDI stuff works, but it copy the pixels to an array. Not the fastest solution. I tried to retrieve the pointer to the bitmap with gdi, (getobject), I got image height, widht, depth, but no pointer (always zero) ...
Does anyone know how to do it over the GDI?
All the internal PB stuff does NOT return the pointer, it return the handle to the image! Fred said that there is no internal way to get the pointer to an image.
The GDI stuff works, but it copy the pixels to an array. Not the fastest solution. I tried to retrieve the pointer to the bitmap with gdi, (getobject), I got image height, widht, depth, but no pointer (always zero) ...
Does anyone know how to do it over the GDI?

