Re: UIScrollView to UIImage
Re: UIScrollView to UIImage
- Subject: Re: UIScrollView to UIImage
- From: David Duncan <email@hidden>
- Date: Sun, 28 Jul 2013 19:55:39 -0700
The scroll view's bounds.origin is also its contentOffset, which is likely what is happening when you render it in to the context.
However, you seem to imply that you just have a simple scroll view with a simple image inside – why do this at all?
Instead just use the contentOffset to determine the origin of the image an then use -drawAtPoint into an appropriately sized graphics context and you'll extract the part you want. Or if your comfortable with Core Graphics you can use CGImageCreateWithImageInRect() (that may not be the exact API, as I'm pulling from memory).
On Jul 28, 2013, at 8:31 AM, Trygve Inda <email@hidden> wrote:
> Update:
>
> CGRect rect = [scrollView bounds];
> UIGraphicsBeginImageContextWithOptions(rect.size,YES,0.0f);
> CGContextRef context = UIGraphicsGetCurrentContext();
> [scrollView.layer renderInContext:context];
> UIImage *capturedImage = UIGraphicsGetImageFromCurrentImageContext();
> UIGraphicsEndImageContext();
>
>
> The scroll view is full screen (768w x 955h) and the image in the scrollview
> is 1500w x 955h so it can only scroll right-left.
>
> If I run this code with the scrollview scrolled all the way to the left,
> everything is fine. The resulting image is the leftmost chuck of the image
> in the scroillview.
>
> However if I scroll the scrollview 100 pixels to the left (so the scrollview
> has 100 pixels off the left edge of the screen, 768 pixels on screen and 632
> pixels off the right edge of the screen)....
>
>
> The resulting image from the above code has 100 pixels of black on the left
> side, and then the correct image for the rest of it.
>
> Changing the first line to:
>
> CGRect rect = [scrollView frame];
>
> produces the exact same result. So somehow, the above code can't handle when
> the scrollview is scrolled away from 0,0.
>
> How can I fix this?
>
>
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
--
David Duncan
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden