Page 1 of 1
ImageResize()
Posted: Thu Oct 14, 2004 5:10 am
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 !
Posted: Thu Oct 14, 2004 9:54 am
by Fred
Seems like a bug, I will take a closer look !
Re: ImageResize()
Posted: Fri Sep 22, 2023 8:34 pm
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)
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
Re: ImageResize()
Posted: Fri Sep 22, 2023 11:07 pm
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....
Re: ImageResize()
Posted: Sat Sep 23, 2023 1:41 am
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
Re: ImageResize()
Posted: Sat Sep 23, 2023 9:33 am
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