Page 1 of 1

Image memory contents

Posted: Wed Jan 24, 2018 2:35 am
by coco2
Is there a way to access the memory contents of an image? I want to zoom the image on a canvas.

Re: Image memory contents

Posted: Wed Jan 24, 2018 4:35 am
by nco2k

Re: Image memory contents

Posted: Wed Jan 24, 2018 7:55 am
by coco2
Thanks but I need to access the memory of an image, not the drawing buffer. Is there any way to do that?

Re: Image memory contents

Posted: Wed Jan 24, 2018 9:21 am
by walbus
@coco2
Mean you this ?

Code: Select all

  Procedure CopyContent_Image_Canvas(source_ID, destination_ID, output_x, output_y, new_size_x, new_size_y)
    If Not StartDrawing(CanvasOutput(destination_ID)) : ProcedureReturn 0 : EndIf
    DrawImage(ImageID(source_ID), output_x, output_y, new_size_x, new_size_y)
    StopDrawing()
    ProcedureReturn 1
  EndProcedure

Re: Image memory contents

Posted: Thu Jan 25, 2018 2:31 am
by coco2
That works but it has two problems for what I am trying to do. DrawImage() can increase the size of the image which is good, but I need to use DrawAlphaImage() which can't enlarge. Also another problem is that when it zooms the image it is antialiased where there's transparency but I am making an image editor so I don't want this. I think I might have to draw the image using Box() but I don't know how to access the memory of the image.

Re: Image memory contents

Posted: Thu Jan 25, 2018 2:45 am
by citystate
this perhaps, then?

Code: Select all

Procedure CopyContent_Image_Canvas(source_ID, destination_ID, output_x, output_y, new_size_x, new_size_y)
  temporary_ID=CopyImage(source_ID,#PB_Any)
  If IsImage(temporary_ID)
    ResizeImage(temporary_ID,new_size_x,new_size_y)
    If StartDrawing(CanvasOutput(destination_ID))
      DrawAlphaImage(ImageID(temporary_ID), output_x, output_y)
      StopDrawing()
      return_value=1
    EndIf
    FreeImage(temporary_ID)
  EndIf
  ProcedureReturn 1
EndProcedure

Re: Image memory contents

Posted: Thu Jan 25, 2018 2:52 am
by coco2
Thanks I will try that, but I also just realised that nco2k is correct, I can access the image drawing buffer with DrawingBuffer()

Edit: thanks city state I think that might be what I need. I tried to access the buffer directly but it's not quite what I want to do. I want to read from the image buffer and at the same time draw to the canvas, but PureBasic can only draw to one output at a time.

Re: Image memory contents

Posted: Thu Jan 25, 2018 8:35 am
by walbus
You must create an array for the image data
From this array you can read and write at the same time to your image

Code: Select all

For i=0 To texture_height
  For ii=0 To texture_width
    texture(ii, i)=Point(ii, i)
  Next ii
Next i

Re: Image memory contents

Posted: Thu Jan 25, 2018 11:44 am
by wilbert
coco2 wrote:I want to read from the image buffer and at the same time draw to the canvas, but PureBasic can only draw to one output at a time.
On Windows you could try GetDIBits to get the pixel data.