Image memory contents

Just starting out? Need help? Post your questions and find answers here.
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Image memory contents

Post by coco2 »

Is there a way to access the memory contents of an image? I want to zoom the image on a canvas.
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: Image memory contents

Post by nco2k »

If OSVersion() = #PB_OS_Windows_ME : End : EndIf
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: Image memory contents

Post by coco2 »

Thanks but I need to access the memory of an image, not the drawing buffer. Is there any way to do that?
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: Image memory contents

Post 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
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: Image memory contents

Post 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.
citystate
Enthusiast
Enthusiast
Posts: 638
Joined: Sun Feb 12, 2006 10:06 pm

Re: Image memory contents

Post 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
there is no sig, only zuul (and the following disclaimer)

WARNING: may be talking out of his hat
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: Image memory contents

Post 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.
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: Image memory contents

Post 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
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Image memory contents

Post 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.
Windows (x64)
Raspberry Pi OS (Arm64)
Post Reply