0

I have a problem when i created PREVIEW HANDlER for a image . The problem is when i have photo on preview pane it dont resize itself maintaining the aspect ratio so i want to write a code so that the photo will resize itself maintaining the aspect ratio of the image. I also have to keep in mind that when i resize the image using my algorithim it should maintain the aspect ratio and the image should have possible maximum size in the preview pane (i mean there shouldn't be any other algorithim which could have the image preview of bigger size then the image obtained by our algorithim with maintained aspect ratio as well).

We have to keep in mind that height of the preview pane is constant factor so we have to deal with the changing width only(I mean according to the changing width we have to maintain the aspect ratio for both height and width of the image). Any help is developing algorthim is appreciated.

Sss
  • 1,519
  • 8
  • 37
  • 67
  • What kind of algorithm do you need actually? It's hard for me to understand which is constant and which may vary.. – Annie Kim Jul 19 '13 at 10:21
  • If you see any image in preview pane(in window exprlorer) and when you resize the preview pane you will observe that that image resizes itself according to the preview pane maintaining the aspect ratio. so i have created an image for any file(i mean when i click on that file i have an image on preview pane but that image don't maintain the aspect ratio. By aspect ratio i mean WidthOfImage/HeightOfImage must remain constant. – Sss Jul 19 '13 at 10:37
  • the image should resize in such a way that if this ratio currently is 16/4 then on reducing it must be 8/2) here we have to deal with HeightOfImage and WidthOfImage and WidthOfPreviewPane and HeightOfPreviewPane (which you can see in window explorer that it remains constant in the case of preview pane..when you resize the image only widthOfPreview pane changes Not height )..Have you got the question now ?? – Sss Jul 19 '13 at 10:37

1 Answers1

0
  • I'll clearly define the two ratios first.

    ImageRatio = WidthOfImage / HeightOfImage and

    WindowRatio = WidthOfPreviewPane / HeightOfPreviewPane.

  • Second, you may try your windows explorer again. When the WindowRatio is smaller than the ImageRatio and you drag the pane vertically, the height of the preview pane will also change.

    enter image description here

  • Finally, you may get ActualWidthOfImage and ActualHeightOfImage as below:

    if (WindowRatio > ImageRatio)
    {
        ActualHeightOfImage = HeightOfPreviewPane;
        ActualWidthOfImage = ActualHeightOfImage * ImageRatio;
    }
    else
    {
        ActualWidthOfImage = WidthOfPreviewPane;
        ActualHeightOfImage = ActualWidthOfImage / ImageRatio;
    }
    

Am I understand your problem correctly? I'd like to help you if you got further questions.

Annie Kim
  • 895
  • 6
  • 17
  • Your idea is absolutely correct the image obtained by this would maintain the aspect ratio and will also accomodated the maximum size inside the varying preview pane but what i want is the the image should be of original size until WidthOfPreviewPane =WidthOfImage and it should reduce the size just after the condition when WidthOfImage>WidthOfPreviewPane – Sss Jul 19 '13 at 12:08
  • (i mean at this condition we have reduced the width of preview pane more then WidthOfImage (It should start squeezing here .)According to your algorthim what will happen would be like this- that suppose you have opened the preview pane and currently the WidthOfPreviewPane>WidthOfImage ..here your algo is showing the image of very big size (size is zoomed) but NO..I just want the size squeezing(when image size>previewpane width) not zooming.what i exactly want is the image should be of the size of original size – Sss Jul 19 '13 at 12:09
  • until the condition is WidthOfPreviewPane>WidthOfImage and when WidthOfPreviewPane<=WidthOfImage then it should squeeze the size... You got my question ??? – Sss Jul 19 '13 at 12:09
  • You can extend my code that when WidthOfPreviewPane > WidthOfImage and HeightOfPreviewPane > HeightOfImage hold at the same time, you may do nothing. Just put your image on the center with original size. In case any of the conditions doesn't hold, you start zoom. – Annie Kim Jul 19 '13 at 12:14
  • I'll stop here. It is not even an algorithm. I think you may write down your code by yourself given that you already know all the logic. – Annie Kim Jul 19 '13 at 12:19
  • the program crashes when i try to do it..plase go through the link i have code there http://stackoverflow.com/questions/17746156/aspect-ratio-of-image-crashing-the-program – Sss Jul 19 '13 at 12:32
  • I have one question.I discussed with you this aspect ratio of image inside the window explorer about months before.Ans thanks to you for giving the solution but i still don't understand what logic you have used to do it ? what you have done is the only case when widthOfImage>HeightOfImage but how to implement it for vice versa.My algo for vice Versa is not working(because we know that height has to be a constant factor in my case and HeightOfImage>WidthOfImage) and also please explain it. Last time also you proved a big help. Please explain it for this case also. – Sss Aug 19 '13 at 07:11
  • 1
    @ShekharSinghSHEKHAWAT My solution works for both of the two cases you mentioned. The only difference is that `ImageRatio < 1` when `HeightOfImage > WidthOfImage`, but this will not affect the corectness of my solution. You may take an example and try. – Annie Kim Aug 20 '13 at 18:34