Mayank Patel Mayank Patel - 1 year ago 149
iOS Question

Combine two UIImageView in to one image stretching

When i tried two combine two

then images are stretching here's code what i am using

CGSize size =CGSizeMake(MAX(self.imgCapture.size.width, self.imgGallary.size.width), MAX(self.imgCapture.size.height, self.imgGallary.size.height));


[self.imgCaptured.image drawInRect:CGRectMake(self.view.frame.origin.x,self.view.frame.origin.y,size.width/2,self.imgCapture.size.height)];

[self.imgGallaryCD.image drawInRect:CGRectMake(self.view.frame.origin.x+(size.width/2),self.view.frame.origin.y,size.width/2,self.imgGallary.size.height)];

UIImage *finalImage = UIGraphicsGetImageFromCurrentImageContext();

Here's First screenshot is there is two UIImageview's

enter image description here

Second screenshot is when i am combine this image into one but image is stretching i want that aspect ratio like screenshot 1

enter image description here

Answer Source

The image is not "stretching". It is squeezing. It's a matter of simple arithmetic. Looking at your image context size and your drawInRect commands, we see that your image context is the size of one image, so now you are drawing both images at half width. So they are squeezed horizontally. You need the image context to be the size of both images added together.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download