0

I'm trying to enable resizing and moving of an image within a certain view. doing so, the challenge is not to lose the image quality. I have a UIImageView placed inside UIView (I'm not using UIScrollView as implementing it, i found it not suitable for this case) and I'm following the UIPanGestureRecognizer and UIPinchGestureRecognizer for dragging and zooming.

the problem is when I'm trying to recreate the new image in the boundaries of the UIView: if the UIImageView is in the boundaries of the UIView it's fine, taking the visible rect scaling according to CGImageCreateWithImageInRect . However, if the inner UIImageView is smaller than the UIView (zoom-out) or moved so it doesn't cover the whole UIView, it just creates the image in the original size, or not in the position I was intending.

The solution that works is renderInContext , which makes an image of what is visible in the UIView - but that the image quality is drastically reduced.

is there a way to do it without losing the image quality? maybe add some edges with 0 alpha, so it will suit the frames of the UIView , yet suits memory demands?

insertusernamehere
  • 23,204
  • 9
  • 87
  • 126
wwwwwwn
  • 48
  • 7
  • This one may be halp you :http://stackoverflow.com/questions/6638623/uiviewcontentmodescaleaspectfill-not-clipping – Divya Bhaloidiya Jul 22 '13 at 10:08
  • i guess it's a bit more tricky here, i try to make a new image with the scale and the position of the original image, and fill the spaces that might appear with alpha = 0 edges (or something transparent). the actual cropping works, as long as the as the UIImageView was bigger or equal to the containing UIView – wwwwwwn Jul 22 '13 at 10:46

1 Answers1

0

if you just change the frame of a UIImageView it should handle the scaling for you based on the content mode, you should have it set to scaleToFill probably. not sure why you are messing around with CGImage stuff (unless you are trying to recreate the image ...).

or have i misinterpreted what you are trying to achieve?

Fonix
  • 11,447
  • 3
  • 45
  • 74
  • i am trying to recreate the image, having a new image in the same quality, yet fits the changing the user applied (zooming and composition). – wwwwwwn Jul 22 '13 at 09:09