Page 1 of 1

Pointer to an image?

Posted: Wed Feb 11, 2004 11:31 am
by Hurga
Does anyone know how to get the pointer to an image in PB?
Help needed....

Re: Pointer to an image?

Posted: Wed Feb 11, 2004 1:44 pm
by PB
> how to get the pointer to an image in PB?

If you load the image, it's stored in the return value:

Code: Select all

pointer=LoadImage(0,"C:\MyPic.bmp")
If not, use the ImageID() command:

Code: Select all

LoadImage(0,"C:\MyPic.bmp")
pointer=ImageID()

Posted: Wed Feb 11, 2004 2:58 pm
by Hurga
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...

Posted: Wed Feb 11, 2004 3:07 pm
by Dare2
Hi Hurga.

What are you intending to do with image?

Get/Set the pixel colours : clr=point(x,y) and plot(x,y [,clr]).

Or manipulate an image file?

Or something else?

Posted: Wed Feb 11, 2004 3:14 pm
by PB
You need the @ sign, so use this instead: Debug PeekL(@ptr)

Posted: Wed Feb 11, 2004 3:25 pm
by filperj
You need the @ sign, so use this instead: Debug PeekL(@ptr)
8O this will peek at ptr's address... and return the content of ptr...

Maybe I asked wrong. I want the pointer to the first pixel of the image...
Any idea. Seems that it this is not possible...
With a sprite , you can use drawingbuffer in a startdrawing/stopdrawing block:

Code: Select all

  ;  first, open ascreen and load asprite
startdrawing(spriteoutput(#mysprite))
   pixelptr=drawingbuffer()
stopdrawing()
In theory, that should work the same for an image, but it just doesn't, I don't know why... :cry:

Posted: Wed Feb 11, 2004 3:32 pm
by freak
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.

Timo

Posted: Wed Feb 11, 2004 6:38 pm
by freedimension
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.
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?)

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

Posted: Thu Feb 12, 2004 11:42 am
by Hurga
Will try that with the @ tonight. Hope it works.

Working with the GDI is probably to slow, but it is the last change for me if nothing else will work.

So thanks all together.

Posted: Fri Feb 13, 2004 8:59 am
by Hurga
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?