#PB_Image_KeepAspect and #PB_Movie_KeepAspect etc.
Posted: Mon Jul 25, 2005 3:39 am
ResizeImage()
ResizeMovie()
DrawImage()
(and more?)
All lack a Keep aspect resize flag/mode/option.
ResizeImage() #PB_Image_KeepAspect could be used with the existing [mode] argument.
ResizeMovie() #PB_Movie_KeepAspect would need a [flag] argument added.
DrawImage() #PB_Draw_KeepAspect would need a [flag] argument added.
It is very easy to add, here is a example keep aspect capable resize
(that is able to scale up AND down while keeping original aspect)
Select a program/window,
then press the "Print Screen" key,
and look at the aspect resized image in the test window.
Altough I don't mind using my own procedures,
I think many would love a simple flag to do it instead
(not to mention a "little" faster when implemented in ASM
ResizeMovie()
DrawImage()
(and more?)
All lack a Keep aspect resize flag/mode/option.
ResizeImage() #PB_Image_KeepAspect could be used with the existing [mode] argument.
ResizeMovie() #PB_Movie_KeepAspect would need a [flag] argument added.
DrawImage() #PB_Draw_KeepAspect would need a [flag] argument added.
It is very easy to add, here is a example keep aspect capable resize
(that is able to scale up AND down while keeping original aspect)
Select a program/window,
then press the "Print Screen" key,
and look at the aspect resized image in the test window.
Code: Select all
;This is the aparently magic yet so easy way to do it
;I use this to get the proper width/height for image resizing and movie resizing etc.
Procedure AspectSize(source_w,source_h,*dest_w,*dest_h)
Protected aspect.f,w.l,h.l,width.l,height.l
If source_w=0 Or source_h=0 Or *dest_w=0 Or *dest_h=0 : ProcedureReturn : EndIf
width=PeekL(*dest_w)
height=PeekL(*dest_h)
aspect.f=source_w/source_h
w.l=width
h.l=width/aspect
If h>height
w=height*aspect
h=height
EndIf
PokeL(*dest_w,w)
PokeL(*dest_h,h)
EndProcedure
;Example use code grabbed from a recent forum post, and slightly modified.
If OpenWindow(0,300,30,600,400,#PB_Window_SystemMenu,"test")
UseJPEGImageEncoder()
CreateGadgetList(WindowID())
ImageGadget(0,0,0,WindowWidth(),WindowHeight(),0)
Repeat
ev=WindowEvent()
If GetAsyncKeyState_(#VK_SNAPSHOT)<>0 : If ev=0 : Delay(1) : EndIf
GetWindowRect_(GetForegroundWindow_(),win.RECT)
x=win\left : y=win\top : w=win\right-win\left : h=win\bottom-win\top
dm.DEVMODE : srcDC=CreateDC_("DISPLAY","","",dm) : trgDC=CreateCompatibleDC_(srcDC)
bm=CreateCompatibleBitmap_(srcDC,w,h) : SelectObject_(trgDC,bm) : BitBlt_(trgDC,0,0,w,h,srcDC,x,y,#SRCCOPY)
DeleteDC_(trgDC) : ReleaseDC_(bm,srcDC) : CreateImage(0,w,h)
StartDrawing(ImageOutput()) : DrawImage(bm,0,0) : StopDrawing()
w_new.l=WindowWidth()
h_new.l=WindowHeight()
AspectSize(w,h,@w_new,@h_new)
ResizeImage(0,w_new,h_new)
SetGadgetState(0,UseImage(0))
Delay(500)
EndIf
Until ev=#PB_EventCloseWindow
EndIf
I think many would love a simple flag to do it instead

(not to mention a "little" faster when implemented in ASM
