Re: UIScrollView to UIImage

2013-07-28 Thread Trygve Inda
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 (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: UIScrollView to UIImage

2013-07-28 Thread David Duncan
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 cocoa...@xericdesign.com 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 (Cocoa-dev@lists.apple.com)
 
 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:
 https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
 
 This email sent to david.dun...@apple.com

--
David Duncan


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: UIScrollView to UIImage

2013-07-21 Thread Cody Garvin
Hi Trygve, sorry for the misinformation earlier. 

I wanted to follow up and let you know this is indeed working for me. Forgot to 
follow up Friday, so sending today.

A few things.

A) Are you adding the QuartzCore framework to your project (I don't believe 
you'd be able to compile if you weren't), so I think you're good there.

B) Make sure your layer / view isn't nil. Are you using an outlet? Make sure 
your outlet is connected. 

- Cody


Cody Garvin | Developer
Servalsoft LLC

On Jul 17, 2013, at 6:56 PM, Trygve Inda cocoa...@xericdesign.com wrote:

 I am trying to take a snapshot of my UIScrollView and store it in a
 UIImage:
 
 UIGraphicsBeginImageContext(scrollView.bounds.size);
 [scrollView.layer renderInContext:UIGraphicsGetCurrentContext()];
 UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
 UIGraphicsEndImageContext();
 
 
 This works for the most views, but when I try it with the UIScrollView, I
 just get a black image (but [image size] is correct).
 
 Any ideas?
 
 Trygve
 
 
 
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 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:
 https://lists.apple.com/mailman/options/cocoa-dev/cody%40servalsoft.com
 
 This email sent to c...@servalsoft.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: UIScrollView to UIImage

2013-07-19 Thread Cody Garvin
You're right Kyle. I quickly tried it, saw it worked and moved on. 

I'll try it again another way and report back

Please excuse mobile typos

On Jul 18, 2013, at 1:37 PM, Kyle Sluder k...@ksluder.com wrote:

 On Thu, Jul 18, 2013, at 01:18 PM, Cody Garvin wrote:
 The UIScrollView adds these subviews to what's called a contentView. This
 is why you have to change a content size to adjust your scrolling, vs
 changing the frame of the UIScrollView. You're grabbing the wrong layer.
 
 When learning about Auto Layout on iOS, I spent a lot of time exploring
 the internals of UIScrollView. My investigations led me to conclude that
 there is no such thing as a content view as you describe it. You can see
 this for yourself if you call -recursiveDescription on your scroll view
 (or any of its ancestors).
 
 It looks to me like the initial design of UIScrollView—that is, before
 the iOS 2.0 SDK ever shipped—was similar to that of NSScrollView on the
 Mac. This is why the documentation makes references to content views.
 
 At some point before iOS 2.0, this design was changed, and the area
 scrolled by the scroll view no longer maps to an actual UIView object.
 This is why UITableView and friends are _subclasses_ of UIScrollView,
 rather than _subviews_.
 
 The _contentView ivar, and the private -contentView method, now seem to
 exist for the purpose of supporting
 -touchesShouldBegin:withEvent:inContentView: and friends. There is no
 secret content view in the view hierarchy.
 
 Again, this understanding is derived from poking at UIScrollView's
 internals. It is not definitive, and quite likely not (entirely)
 correct. But it jibes with my understand of UIScrollView much better
 than the anonymous contentView theory.
 
 You can grab the correct view / layer: [[scrollView contentView] layer];
 
 There is no public -contentView method on UIScrollView, so attempting to
 call it is likely to get your app rejected by the App Store. Please do
 not use this method.
 
 --Kyle Sluder

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: UIScrollView to UIImage

2013-07-18 Thread Cody Garvin
Hi Trygve,

The UIScrollView adds these subviews to what's called a contentView. This is 
why you have to change a content size to adjust your scrolling, vs changing the 
frame of the UIScrollView. You're grabbing the wrong layer.

You can grab the correct view / layer: [[scrollView contentView] layer];

Hope that helps

- Cody

On Jul 17, 2013, at 8:21 PM, Trygve Inda cocoa...@xericdesign.com wrote:

 Does it do that even if the scroll view isn't scrolled at all but is at the
 very top? 
 
 On 18 Jul, 2013, at 9:56, Trygve Inda cocoa...@xericdesign.com wrote:
 
 I am trying to take a snapshot of my UIScrollView and store it in a
 UIImage:
 
 UIGraphicsBeginImageContext(scrollView.bounds.size);
 [scrollView.layer renderInContext:UIGraphicsGetCurrentContext()];
 UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
 UIGraphicsEndImageContext();
 
 
 This works for the most views, but when I try it with the UIScrollView, I
 just get a black image (but [image size] is correct).
 
 Any ideas?
 
 Trygve
 
 
 Yes. It is a right to left full screen scroll view with 3 views in it. I can
 get an image of any of the views with the above code, but not the scroll
 view itself (which may show more than one view)
 
 
 
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 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:
 https://lists.apple.com/mailman/options/cocoa-dev/cody%40servalsoft.com
 
 This email sent to c...@servalsoft.com


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: UIScrollView to UIImage

2013-07-18 Thread Kyle Sluder
On Thu, Jul 18, 2013, at 01:18 PM, Cody Garvin wrote:
 The UIScrollView adds these subviews to what's called a contentView. This
 is why you have to change a content size to adjust your scrolling, vs
 changing the frame of the UIScrollView. You're grabbing the wrong layer.

When learning about Auto Layout on iOS, I spent a lot of time exploring
the internals of UIScrollView. My investigations led me to conclude that
there is no such thing as a content view as you describe it. You can see
this for yourself if you call -recursiveDescription on your scroll view
(or any of its ancestors).

It looks to me like the initial design of UIScrollView—that is, before
the iOS 2.0 SDK ever shipped—was similar to that of NSScrollView on the
Mac. This is why the documentation makes references to content views.

At some point before iOS 2.0, this design was changed, and the area
scrolled by the scroll view no longer maps to an actual UIView object.
This is why UITableView and friends are _subclasses_ of UIScrollView,
rather than _subviews_.

The _contentView ivar, and the private -contentView method, now seem to
exist for the purpose of supporting
-touchesShouldBegin:withEvent:inContentView: and friends. There is no
secret content view in the view hierarchy.

Again, this understanding is derived from poking at UIScrollView's
internals. It is not definitive, and quite likely not (entirely)
correct. But it jibes with my understand of UIScrollView much better
than the anonymous contentView theory.

 You can grab the correct view / layer: [[scrollView contentView] layer];

There is no public -contentView method on UIScrollView, so attempting to
call it is likely to get your app rejected by the App Store. Please do
not use this method.

--Kyle Sluder

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: UIScrollView to UIImage

2013-07-17 Thread Roland King
Does it do that even if the scroll view isn't scrolled at all but is at the 
very top? 

On 18 Jul, 2013, at 9:56, Trygve Inda cocoa...@xericdesign.com wrote:

 I am trying to take a snapshot of my UIScrollView and store it in a
 UIImage:
 
 UIGraphicsBeginImageContext(scrollView.bounds.size);
 [scrollView.layer renderInContext:UIGraphicsGetCurrentContext()];
 UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
 UIGraphicsEndImageContext();
 
 
 This works for the most views, but when I try it with the UIScrollView, I
 just get a black image (but [image size] is correct).
 
 Any ideas?
 
 Trygve
 
 
 
 ___
 
 Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
 
 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:
 https://lists.apple.com/mailman/options/cocoa-dev/rols%40rols.org
 
 This email sent to r...@rols.org

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: UIScrollView to UIImage

2013-07-17 Thread Trygve Inda
 Does it do that even if the scroll view isn't scrolled at all but is at the
 very top? 
 
 On 18 Jul, 2013, at 9:56, Trygve Inda cocoa...@xericdesign.com wrote:
 
 I am trying to take a snapshot of my UIScrollView and store it in a
 UIImage:
 
 UIGraphicsBeginImageContext(scrollView.bounds.size);
 [scrollView.layer renderInContext:UIGraphicsGetCurrentContext()];
 UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
 UIGraphicsEndImageContext();
 
 
 This works for the most views, but when I try it with the UIScrollView, I
 just get a black image (but [image size] is correct).
 
 Any ideas?
 
 Trygve
 

Yes. It is a right to left full screen scroll view with 3 views in it. I can
get an image of any of the views with the above code, but not the scroll
view itself (which may show more than one view)



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com