0

I am successfully able to draw on UIView e.g. drawScreen with

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

I have added my UIImageView as subview of above UIView e.g. drawScreen so that it looks you are drawing over the image.

Now i want to save image with drawing, i have also done this part using

UIGraphicsBeginImageContext(CGSizeMake(drawScreen.frame.size.width, drawScreen.frame.size.height));

Problem:
The problem is that the resulted save image is of size drawScreen and my original image is of good quality. e.g,

size of drawScreen is 300x300

The size of my original image is 640x640

The size of resulted image is also 300x300.

How can i save original size image with editing?

oliholz
  • 7,447
  • 2
  • 43
  • 82
Irfan DANISH
  • 8,349
  • 12
  • 42
  • 67

2 Answers2

1

Start by simply replacing drawScreen.frame.size.width and drawScreen.frame.size.height with the size of the original image.

First of all, you will need to create a new UIView instance that is the size of your image (and add your image to it). Then you will need to scale and redraw your art to it. Depending on how you are storing your image, you will either need to multiply your coordinates by a calculated factor, or render something and then enlarge it. Either way, you will add your enlarged graphics as a subview on top of your new UIView. Then use the UIGraphicsGetCurrentImageContext.

You will want to read this documentation.

Also, you may find this question somewhat helpful.

Community
  • 1
  • 1
WolfLink
  • 3,308
  • 2
  • 26
  • 44
  • No it will not work. As i told you i am marking image portion, like pointing something in image with free hand circle or lines. Different sizes of drawscreen and image size will create drawing location problems. – Irfan DANISH Mar 27 '13 at 06:53
  • What i actually want is Show 640x640 image to the user (Without scrolling). User draw on this image and then save 640x640 image with drawing. – Irfan DANISH Mar 27 '13 at 06:58
  • And i have spent lots of hours in this effort and didn't find any tutorial, example etc – Irfan DANISH Mar 27 '13 at 06:59
0

I am able to save original sized image with editing using UIScrollView. I have disabled single finger scroll in my UIScrollView only allowed two fingers scrolling and use single finger to draw over image. I have used following codes to save original size image

UIGraphicsBeginImageContext(self.scrollView.contentSize);
 {
     CGPoint savedContentOffset = self.scrollView.contentOffset;
     CGRect savedFrame = self.scrollView.frame;

     self.scrollView.contentOffset = CGPointZero;
     self.scrollView.frame = CGRectMake(0, 0, self.scrollView.contentSize.width, self.scrollView.contentSize.height);

     [self.scrollView.layer renderInContext: UIGraphicsGetCurrentContext()];
     UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
     UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
     self.scrollView.contentOffset = savedContentOffset;
     self.scrollView.frame = savedFrame;
 }
 UIGraphicsEndImageContext();
Irfan DANISH
  • 8,349
  • 12
  • 42
  • 67