bbelcher Contributor

Joined: 30 Jul 2002 Posts: 172
|
Posted: Sat Mar 27, 2004 2:15 am Post subject: Code to keep Aspect Ratio |
|
|
Maybe this code will be helpful to someone. I used PGWARE's convert.dll for the ease of implantation. Any improvement would be welcomed.
NOTE: this example uses the CONVERT.dll from PGWARE
| Code: |
external @path(%0)vdsconv.dll
#DEFINE command,CONVERT
#DEFINE function,CONVERT
Title Keep Aspect Ratio
DIALOG CREATE,New Dialog,-1,0,550,551
DIALOG ADD,LINE,LINE1,66,41,475,443
DIALOG ADD,BITMAP,BITMAP1,68,43,470,437,,
DIALOG ADD,BUTTON,BUTTON1,28,44,73,24,Load Bitmap
DIALOG ADD,CHECK,CHECK1,31,129,120,18,keep Aspect Ratio
DIALOG ADD,STATUS,STATUS1,
DIALOG SHOW
:Evloop
wait event
goto @event()
:button1button
%%picture = @filedlg(*.BMP)
if %%picture
%%imgheight = @CONVERT(IMGHEIGHT,%%picture)
%%imgwidth = @CONVERT(IMGWIDTH,%%picture)
else
goto evloop
end
dialog remove,bitmap1
%%checkbox = @dlgtext(check1)
if @equal(%%checkbox,1)
rem %%maxbitmapwidth is the max size of your bitmap control
%%maxbitmapwidth = 470
%%greaterthenheight = @greater(%%maxbitmapwidth,%%imgheight)
%%greaterthenwidth = @greater(%%maxbitmapwidth,%%imgwidth)
rem if image is smaller then aspect ratio is not applied.
if @both(%%greaterthenheight,%%greaterthenwidth)
DIALOG ADD,BITMAP,BITMAP1,68,43,%%imgwidth,%%imgheight,%%picture,,
DIALOG set,status1,Original Image size: %%imgheight H X %%imgwidth W - No need to resize it fits.
rem if image is taller then wide then the bitmap controlt
elsif @greater(%%imgheight,%%imgwidth)
%%aspectratio = @FDIV(%%imgwidth,%%imgheight)
%%imgwidthBEFORFORMAT = @FMUL(%%maxbitmapwidth,%%aspectratio)
%%imgwidthAR = @FORMAT(%%imgwidthBEFORFORMAT,4.0)
DIALOG ADD,BITMAP,BITMAP1,68,43,%%imgwidthAR,%%maxbitmapwidth,%%picture,,stretch
DIALOG set,status1,Original Image size: %%imgheight H X %%imgwidth W - It's currently resized with a correct ratio to: %%maxbitmapwidth H X %%imgwidthAR W
rem if image is wider then tall then the bitmap control
elsif @greater(%%imgwidth,%%imgheight)
%%aspectratio = @FDIV(%%imgwidth,%%imgheight)
%%imgheightBEFORFORMAT = @FDIV(%%maxbitmapwidth,%%aspectratio)
%%imgheightAR = @FORMAT(%%imgheightBEFORFORMAT,4.0)
DIALOG ADD,BITMAP,BITMAP1,68,43,%%maxbitmapwidth,%%imgheightAR,%%picture,,stretch
DIALOG set,status1,Original Image size: %%imgheight H X %%imgwidth W - It's currently resized with a correct ratio to: %%imgheightAR H X %%maxbitmapwidth W
rem if image is same size wide, tall and larger then bitmap control
elsif @equal(%%imgwidth,%%imgheight)
%%aspectratio = @FDIV(%%imgwidth,%%imgheight)
%%imgheightBEFORFORMAT = @FDIV(%%maxbitmapwidth,%%aspectratio)
%%imgheightAR = @FORMAT(%%imgheightBEFORFORMAT,4.0)
DIALOG ADD,BITMAP,BITMAP1,68,43,%%maxbitmapwidth,%%imgheightAR,%%picture,,stretch
DIALOG set,status1,Original Image size: %%imgheight H X %%imgwidth W - It's currently resized with a correct ratio to: %%imgheightAR H X %%maxbitmapwidth W
else
end
goto evloop
else
rem aspect ration not applied check box unchecked
DIALOG ADD,BITMAP,BITMAP1,68,43,470,437,%%picture,,stretch
end
dialog set,status1,Original Image size: %%imgheight H X %%imgwidth W - It's currently stretched to: 437 H X 470 W
goto evloop
:Close
exit
|
|
|