我正在尝试将两个UIImageView
合并为combinedView
。我遇到的问题是,在我将self.firstImageView
和self.secondImageView
作为子视图添加到combinedView
后,我检查combinedView.image
的字节大小时得到的输出是0.我需要combinedView.image
最终在JEPGRepresentation中传递给我的后端,所以我不确定如何将这些视图组合在一起,或者我现在做错了什么。
感谢您的帮助!
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
答案 0 :(得分:0)
您正在添加self.firstImageView和self.secondImageView作为组合视图的子视图,而且您没有将任何图像分配给combinedView。所以[combinedPicData length]总是只有0。
请参阅以下链接以合并两张图片。
iOS - Merging two images of different size
blend two uiimages based on alpha/transparency of top image