ImageResize()

Linux specific forum
matty47
User
User
Posts: 35
Joined: Fri Sep 26, 2003 10:21 pm

ImageResize()

Post by matty47 »

If I load an 1154 x 864 image and then ResizeImage(1,640,480) the image is just cut off from 0,0 to 640,480. That is the full image is not scaled just cropped. Is this what the function is supposed to do? If so has anyone written code to resample/scale the image to a smaller size?
Thanks for any help !
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post by Fred »

Seems like a bug, I will take a closer look !
HarrysLad
User
User
Posts: 59
Joined: Fri Jun 04, 2010 9:29 pm
Location: Sunny Spain

Re: ImageResize()

Post by HarrysLad »

I've just noticed that ResizeImage() doesn't work although it was reported as a possible bug way back in 2004. ResizeImage() works as expected on both MacOS and Windows.

I'm using PB 6.01 on Ubuntu 20.04

Is there any chance of a fix or could someone suggest a workaround?

Code: Select all

If OpenWindow(0, 0, 0, 1000, 800, "Canvas container example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  CanvasGadget(0, 10, 10, 980, 780, #PB_Canvas_Container)
  CanvasGadget(1, 720, 5, 250, 200,#PB_Canvas_Border)
  ButtonGadget(2, 10, 740, 80, 30, "Show")
  
  CloseGadgetList()
  
  Repeat
    Event = WaitWindowEvent()
    
    If Event = #PB_Event_Gadget
      Select EventGadget() 
        Case 0
          If EventType() = #PB_EventType_LeftButtonDown Or (EventType() = #PB_EventType_MouseMove And GetGadgetAttribute(0, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton)
            If StartDrawing(CanvasOutput(0))
              x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
              y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
              Circle(x, y, 10, RGB(Random(255), Random(255), Random(255)))
              GrabDrawingImage(1,0,0,OutputWidth(),OutputHeight())
              StopDrawing()
              ResizeImage(1,245, 195)
              SetGadgetAttribute(1,#PB_Canvas_Image ,ImageID(1))
            EndIf
          EndIf
          
        Case 2
          Run ! 1
          If Run = 1
            HideGadget(1,1)
          Else
            HideGadget(1,0)
          EndIf 
      EndSelect
    EndIf
    
  Until Event = #PB_Event_CloseWindow
EndIf

[edit]: I take it all back (I think) :oops:

It now seems that it's the
SetGadgetAttribute(1, #PB_Canvas_Image, ImageID(1))
function that works in MacOS/Windows but not in Linux.

Again, a fix or the suggestion of a workaround would be most welcome.

Or maybe it's both. I'm losing the will to live here...

Dave
Last edited by HarrysLad on Sat Sep 23, 2023 7:35 am, edited 1 time in total.
User avatar
Bisonte
Addict
Addict
Posts: 1305
Joined: Tue Oct 09, 2007 2:15 am

Re: ImageResize()

Post by Bisonte »

You are using a canvas to show the image ?

Draw the Image directly on it....

If there is a bug in ResizeImage... you can try : DrawImage(ImageID, x, y, w, h) to resize it on the Canvas direct....
PureBasic 6.21 (Windows x64) | Windows 11 Pro | AsRock B850 Steel Legend Wifi | R7 9800x3D | 64GB RAM | RTX 5080 | ThermaltakeView 270 TG ARGB | build by vannicom​​
English is not my native language... (I often use DeepL.)
BarryG
Addict
Addict
Posts: 4128
Joined: Thu Apr 18, 2019 8:17 am

Re: ImageResize()

Post by BarryG »

matty47 wrote: Thu Oct 14, 2004 5:10 amIf I load an 1154 x 864 image and then ResizeImage(1,640,480) the image is just cut off from 0,0 to 640,480.
Got a code snippet to show this? Because it works properly here (the red borders are still there after resizing):

Code: Select all

CreateImage(0,1154,864,24,#Yellow)
StartDrawing(ImageOutput(0))
DrawingMode(#PB_2DDrawing_Outlined)
Box(0,0,1154,864,#Red)
StopDrawing()
ResizeImage(0,640,480)
ShowLibraryViewer("Image",0)
CallDebugger
HarrysLad
User
User
Posts: 59
Joined: Fri Jun 04, 2010 9:29 pm
Location: Sunny Spain

Re: ImageResize()

Post by HarrysLad »

Bisonte wrote: Fri Sep 22, 2023 11:07 pm You are using a canvas to show the image ?

Draw the Image directly on it....

If there is a bug in ResizeImage... you can try : DrawImage(ImageID, x, y, w, h) to resize it on the Canvas direct....
Cheers Bisonte, that's exactly the workaround that I needed.
For reference, this works on all three platforms.

Code: Select all

If OpenWindow(0, 0, 0, 1000, 800, "Canvas container example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
  CanvasGadget(0, 10, 10, 980, 780, #PB_Canvas_Container)
  CanvasGadget(1, 720, 5, 250, 200,#PB_Canvas_Border)
  ButtonGadget(2, 10, 740, 80, 30, "Show")
  
  CloseGadgetList()
  
  Repeat
    Event = WaitWindowEvent()
    
    If Event = #PB_Event_Gadget
      Select EventGadget() 
        Case 0
          If EventType() = #PB_EventType_LeftButtonDown Or (EventType() = #PB_EventType_MouseMove And GetGadgetAttribute(0, #PB_Canvas_Buttons) & #PB_Canvas_LeftButton)
            If StartDrawing(CanvasOutput(0))
              x = GetGadgetAttribute(0, #PB_Canvas_MouseX)
              y = GetGadgetAttribute(0, #PB_Canvas_MouseY)
              Circle(x, y, 10, RGB(Random(255), Random(255), Random(255)))
              GrabDrawingImage(1,0,0,OutputWidth(),OutputHeight())
              StopDrawing()
              If StartDrawing(CanvasOutput(1))
                DrawImage(ImageID(1),0,0,245,195)
                StopDrawing()
              EndIf
;              ResizeImage(1,245,195)
;              SetGadgetAttribute(1, #PB_Canvas_Image,ImageID(1))
            EndIf
          EndIf

        Case 2
          Run ! 1
          If Run = 1
            HideGadget(1,1)
          Else
            HideGadget(1,0)
          EndIf 
      EndSelect
    EndIf
    
  Until Event = #PB_Event_CloseWindow
EndIf

I owe you a pint or two.

Dave
Post Reply