在我的iOS应用中,我必须对UIImage
进行一些修改,例如在其上添加水印。之后,我想使用原始元数据保存图像,但如果我尝试使用writeImageDataToSavedPhotosAlbum:metadata:completionBlock:
,则生成的图像中没有任何内容。
由于我必须修改图像,因此我必须使用以下方法传递NSData
metadata:
部分:UIImageJPEGRepresentation(UIImage *, float)
。
在保存图像之前,元数据就像:
Meta: {
ApertureValue = "2.526068811667587";
BrightnessValue = "-1.807443054797895";
ExposureMode = 0;
ExposureProgram = 2;
ExposureTime = "0.05882352941176471";
FNumber = "2.4";
Flash = 16;
FocalLenIn35mmFilm = 33;
FocalLength = "4.12";
ISOSpeedRatings = (
800
);
LensMake = Apple;
LensModel = "iPhone 5c back camera 4.12mm f/2.4";
LensSpecification = (
"4.12",
"4.12",
"2.4",
"2.4"
);
MeteringMode = 3;
PixelXDimension = 3264;
PixelYDimension = 2448;
SceneType = 1;
SensingMethod = 2;
ShutterSpeedValue = "4.058917734171294";
WhiteBalance = 0;
"{GPS}" = {
Altitude = "147.9932";
DOP = "76.42908";
Latitude = "45.7398";
LatitudeRef = N;
Longitude = "126.6266";
LongitudeRef = E;
TimeStamp = "2013:12:23 08:45:30";
};
那么,这里有什么问题?
答案 0 :(得分:0)
试试这个,
UIImage *newImage = self.yourOriginalImage;
UIImage *anotherImage = @"waterMark.png";
CGImageRef imageRef = anotherImage.CGImage;
CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(imageRef),
CGImageGetHeight(imageRef),
CGImageGetBitsPerComponent(imageRef),
CGImageGetBitsPerPixel(imageRef),
CGImageGetBytesPerRow(imageRef),
CGImageGetDataProvider(imageRef), NULL, false);
CGImageRef maskedImage = CGImageCreateWithMask([newImage CGImage], mask);
self.imageView.image = [UIImage imageWithCGImage: maskedImage];
答案 1 :(得分:0)
假设您有一个名为myEditedImage的UIImage以及名为“metadata”的NSDictionary(或NSMutableDictionary ...)中的元数据:
ALAssetsLibrary *library;
ALAssetsLibraryWriteImageCompletionBlock completionBlock = ^(NSURL *assetURL, NSError *error) {};
float compressionLevel = 0.75; // Or whatever you want
NSData *dataIn = UIImageJPEGRepresentation(myEditedImage, compressionLevel);
[library writeImageDataToSavedPhotosAlbum: dataIn
metadata: metadata
completionBlock:completionBlock];