0

I am trying to merge two UIImageViews together into combinedView. The issue I am encountering is that after I have added the self.firstImageView and self.secondImageView as subviews to my combinedView, the output I get when I check the byte size of combinedView.image is 0. I need combinedView.image to be eventually passed to my backend in a JEPGRepresentation, so am unsure how else I could approach to combining the views together, or what I am doing incorrectly at the moment.

Thanks for your help!

UIImageView *combinedView = [[UIImageView alloc] init];
[combinedView addSubview:self.firstImageView];
[combinedView sendSubviewToBack:self.firstImageView];
[combinedView addSubview:self.secondImageView];
[combinedView bringSubviewToFront:self.secondImageView];

NSData *firstPicData = UIImageJPEGRepresentation(self.firstImageView.image, 1.0);
NSLog(@"Size of first:%d",[firstPicData length]); //outputs a non-zero number

NSData *secondPicData = UIImageJPEGRepresentation(self.secondImageView.image, 1.0);
NSLog(@"Size of second:%d",[secondPicData length]); //also outputs a non-zero number

NSData *combinedPicData = UIImageJPEGRepresentation(combinedView.image, 1.0);
NSLog(@"Size of combined:%d",[combinedPicData length]); //! outputs 0 bytes
daspianist
  • 5,336
  • 8
  • 50
  • 94

1 Answers1

0

You are adding self.firstImageView and self.secondImageView as a sub view of combined view and more over you didn't assign any image to combinedView. So [combinedPicData length] will be only 0 always.

Refer the following links for merging of two images.

iOS - Merging two images of different size

blend two uiimages based on alpha/transparency of top image

Merge Two Image on to one Image programmatically in iphone

How to merge two half images in ios app?

Community
  • 1
  • 1
Venk
  • 5,949
  • 9
  • 41
  • 52