• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: UIScrollView to UIImage
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Re: UIScrollView to UIImage (From: Trygve Inda <email@hidden>)

  • Prev by Date: Printing Problem
  • Next by Date: Exiting non-POSIX threads?
  • Previous by thread: Re: UIScrollView to UIImage
  • Next by thread: Re-booting after changing Icons in OS X Doc app
  • Index(es):
    • Date
    • Thread