CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 1999
    Posts
    3

    Resizing calculation

    I wanted to stretch some pictures I was drawing at my dialog, but (you can see the source...) the result was not the thing I wanted!
    I am looking if the image is smaller than the space I have for it (in this case x=160, y=210). If not I tried to resize it by dividing and that stuff.
    In the end I placed it into the middle. (That is the only thing that works!)
    The problem is that my pic is always too large. I am sure it is just a thing I am not realizing right now, but very simple.

    Hoping for help. Thank you!

    int width = image.GetWidth();
    int height = image.GetHeight();

    int nwidth, nheight;
    int left, top;

    if((width <= 160) && (height <= 210))
    {
    nwidth = width;
    nheight = height;

    left = (160 - width) / 2;
    top = (210 - height) / 2;
    }
    else
    {
    long dif1 = width / 160;
    long dif2 = height / 210;

    if(dif2 >= dif1)
    {
    nwidth = width / dif2;
    nheight = height / dif2;
    }
    else
    {
    nwidth = width / dif1;
    nheight = height / dif1;
    }

    left = (160 - nwidth) / 2;
    top = (210 - nheight) / 2;
    }





  2. #2
    Join Date
    May 1999
    Posts
    11

    Re: Resizing calculation

    Maybe you lose the precision when you use LONG
    you can try like this:

    double dif1 = double(width / 160.0);
    double dif2 = double(height / 210.0);
    //use double instead of long...
    ..........








Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured