Pointer to an image?

Everything else that doesn't fall into one of the other PB categories.
Hurga
Enthusiast
Enthusiast
Posts: 148
Joined: Thu Jul 17, 2003 2:53 pm
Contact:

Pointer to an image?

Post by Hurga »

Does anyone know how to get the pointer to an image in PB?
Help needed....
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Pointer to an image?

Post 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()
Hurga
Enthusiast
Enthusiast
Posts: 148
Joined: Thu Jul 17, 2003 2:53 pm
Contact:

Post 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...
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post 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?
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

You need the @ sign, so use this instead: Debug PeekL(@ptr)
filperj
User
User
Posts: 77
Joined: Tue Sep 16, 2003 8:53 pm
Location: Nevers(France)

Post 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:
freak
PureBasic Team
PureBasic Team
Posts: 5947
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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
quidquid Latine dictum sit altum videtur
freedimension
Enthusiast
Enthusiast
Posts: 613
Joined: Tue May 06, 2003 2:50 pm
Location: Germany
Contact:

Post 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
Hurga
Enthusiast
Enthusiast
Posts: 148
Joined: Thu Jul 17, 2003 2:53 pm
Contact:

Post 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.
Hurga
Enthusiast
Enthusiast
Posts: 148
Joined: Thu Jul 17, 2003 2:53 pm
Contact:

Post 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?
Post Reply