forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


how to scale and keep aspect ratio.

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help
View previous topic :: View next topic  
Author Message
bbelcher
Contributor
Contributor


Joined: 30 Jul 2002
Posts: 172

PostPosted: Fri Mar 19, 2004 1:38 pm    Post subject: how to scale and keep aspect ratio. Reply with quote

Anyone know how you would scale an image or control and keep it's aspect ratio so it's just smaller or bigger and not distorted in some way.

Thanks.
Back to top
View user's profile Send private message
Boo
Valued Contributor
Valued Contributor


Joined: 31 Oct 2003
Posts: 599
Location: Gulf Breeze, Florida USA

PostPosted: Fri Mar 19, 2004 10:30 pm    Post subject: Reply with quote

Howdy!

You may want to check out these threads... Hope this info. helps you.

Cheers,

- Boo

http://forum.vdsworld.com/viewtopic.php?t=2209
http://forum.vdsworld.com/viewtopic.php?t=2172
Back to top
View user's profile Send private message
bbelcher
Contributor
Contributor


Joined: 30 Jul 2002
Posts: 172

PostPosted: Sat Mar 27, 2004 2:15 am    Post subject: Code to keep Aspect Ratio Reply with quote

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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> General Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group