TTPhotoViewController crops images

79 views
Skip to first unread message

Brandon Keepers

unread,
Jan 5, 2010, 9:43:22 AM1/5/10
to thr...@googlegroups.com
There seems to be an issue with TTPhotoViewController where it crops images that are irregularly shaped. You can see it in the TTCatalog app and in this app that we just published (http://itunes.apple.com/us/app/stryker-ivs/id345585768?mt=8)

It seems that the photo view controller tries to scale it to full size, but cuts off the edges and doesn't let you zoom out. I've tried changing the scaling mode on the photo view, but that didn't seem to make a difference. Anyone have an idea what might be causing it?

Thanks,
Brandon

idev

unread,
Jan 11, 2010, 1:17:38 AM1/11/10
to Three20
Found a solution? I see this issue in some of my images. I tried
setting the size in MockPhoto CGSizeZero, CGSizeMake(320,480) and
CGSizeMake(image width, image height) but none of these seem to make a
difference.

On Jan 5, 7:43 pm, Brandon Keepers <bran...@collectiveidea.com> wrote:
> There seems to be an issue withTTPhotoViewControllerwhere it cropsimagesthat are irregularly shaped.  You can see it in the TTCatalog app and in this app that we just published (http://itunes.apple.com/us/app/stryker-ivs/id345585768?mt=8)

Jonathan Saggau

unread,
Jan 11, 2010, 2:57:33 AM1/11/10
to thr...@googlegroups.com
Been a while since I poked at this, but I think this is the important bit.  Take a look in UIImageAdditions.m

Calling - (void)drawInRect:(CGRect)rect contentMode:(UIViewContentMode)contentMode when using UIViewContentModeScaleAspectFit doesn't always scale the rectangle correctly.  This is the offending bit, I think.  The code snippet for scaling the image you see below should work; you should be able to see where to st it in the source file (no pun intended) and what to replace with it.


    } else if (contentMode == UIViewContentModeScaleAspectFit) {
      CGSize imageSize = self.size;
      if (imageSize.height < imageSize.width) {
        imageSize.height = floor((imageSize.height/imageSize.width) * rect.size.width);
        imageSize.width = rect.size.width;
      } else {
        imageSize.width = floor((imageSize.width/imageSize.height) * rect.size.height);
        imageSize.height = rect.size.height;
      }
      rect = (rect.origin.x + floor(rect.size.width/2 - imageSize.width/2),
                        rect.origin.y + floor(rect.size.height/2 - imageSize.height/2),
                        imageSize.width, imageSize.height);
    }
  }

idev

unread,
Jan 13, 2010, 5:56:05 AM1/13/10
to Three20
I downloaded the latest code from Github and these statements are
already present there. Don't know what to change.

idev

unread,
Jan 19, 2010, 4:05:35 AM1/19/10
to Three20
Anything on this please?

Eelco Lempsink

unread,
Jan 21, 2010, 3:23:43 PM1/21/10
to thr...@googlegroups.com
On Jan 19, 2010, at 10:05 AM, idev wrote:
> Anything on this please?

I believe the problem is in the implementation of -frameOfPageAtIndex: in TTScrollView. (I ran into this months ago, but I needed to subclass TTScrollView anyway, sorry about not reporting this earlier.)

> - (CGRect)frameOfPageAtIndex:(NSInteger)pageIndex {
...
> CGFloat width, height;
> if (UIInterfaceOrientationIsLandscape(_orientation)) {
> if (size.width > size.height) {
> height = self.height;
> width = size.height/size.width * self.height;
> } else {
> height = size.width/size.height * self.width;
> width = self.width;
> }
> } else {
> if (size.width > size.height) {
> width = self.width;
> height = size.height/size.width * self.width;
> } else {
> width = size.width/size.height * self.height;
> height = self.height;
> }
> }
...
>
> }

The check whether to make the image fit to the width or to the height is too simplistic. A portrait oriented image can still be too wide to fit on the iPhone screen (e.g., the last image in the TTCatalog photo browser.) It should check the ratio between width and height, which is simply a matter of replacing

> if (size.width > size.height) {

with

> if (size.width / size.height > self.width / self.height) {

Additionally, there is another bug in the TTPhotoViewController: because it rotates _and_ lets the scrollView rotate too the image will do a wild animation, rotating twice and ending with the image upside down. To make the fix above also work for the TTPhotoViewController the rotation of the _scrollView must be disabled.

I just committed a patch containing both fixes to our fork: http://github.com/tupil/three20/commit/416d6f1f57b1f7fa1ee99d8100beb6399b69cf8d

Cherry-pick away ;)

--
Regards,

Eelco Lempsink

idev

unread,
Jan 23, 2010, 5:08:19 AM1/23/10
to Three20
Thanks a lot Eelco. That worked perfectly well.

> I just committed a patch containing both fixes to our fork:http://github.com/tupil/three20/commit/416d6f1f57b1f7fa1ee99d8100beb6...

Brandon Keepers

unread,
Feb 4, 2010, 11:21:16 AM2/4/10
to Three20

On Jan 21, 3:23 pm, Eelco Lempsink <ee...@lempsink.nl> wrote:
> I just committed a patch containing both fixes to our fork:http://github.com/tupil/three20/commit/416d6f1f57b1f7fa1ee99d8100beb6...

Awesome! It works great. Can someone from facebook pull in this
patch?

Joe D'Andrea

unread,
May 9, 2012, 1:26:47 PM5/9/12
to thr...@googlegroups.com
I second that! :) 
Reply all
Reply to author
Forward
0 new messages