-5

在将附加字节附加到 NSMutableData 后,我想从 NSdata 保存图像。以下是我的要求的示例代码。

NSData *sourceData = = UIImageJPEGRepresentation([info objectForKey:@"UIImagePickerControllerOriginalImage"], 1);

NSMutableData *concatenatedData = [NSMutableData data];
[concatenatedData appendData:sourceData];
[concatenatedData appendData:sourceData];

UIImage *myFinalImage = [[UIImage alloc] initWithData:concatenatedData]; 
UIImageWriteToSavedPhotosAlbum(myFinalImage, self, nil, nil); 

我将 sourcedata 附加了 2 次,但我的最终图像只保存了一个 sourceData 字节。

我在这里错过了什么吗?

4

1 回答 1

1

这是示例:

CGSize newSize = CGSizeMake({Here give width}, {Here give height});
     UIImage *myFinalImage1 = [[UIImage alloc] initWithData:concatenatedData]; 
      UIImage *myFinalImage2 = [[UIImage alloc] initWithData:concatenatedData]; 

        // Set up width height with values.
        CGSize newSize = CGSizeMake(width, height);
        UIGraphicsBeginImageContext( newSize );

        [myFinalImage1 drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];

        [myFinalImage2 drawInRect:CGRectMake(newSize.width,newSize.height,newSize.width,newSize.height*2) blendMode:kCGBlendModeNormal alpha:1.0];

        UIImage *mergedImage = UIGraphicsGetImageFromCurrentImageContext();

        UIGraphicsEndImageContext();
于 2013-08-16T09:25:34.473 回答