Get the same NSData of PHAsset after save
Do you know is there any way to get the same NSData of Image ( JPG , PNG ) after save with PHPhotoLibrary
or no?
OfC, iOS will modify some metadata and EXIF
-- > ( Timestamp,... )data after save but, I'm asking about UIImage Data (include same EXIF data).
I didn't copy the exif in in my code here but it doesn't work
so Let's talk over the code:
Save Image and get hash
UIImage * tmp = [[UIImage alloc] initWithData:tmpData];
tmpData =UIImageJPEGRepresentation(tmp, 1.0);
self.str1 = [tmpData MD5];
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetResourceCreationOptions *options = [[PHAssetResourceCreationOptions alloc] init];
options.originalFilename = @"XXX";
PHAssetCreationRequest * createReq = [PHAssetCreationRequest creationRequestForAsset];
[createReq addResourceWithType:PHAssetResourceTypePhoto data:tmpData options:options];
} completionHandler:^(BOOL success, NSError * _Nullable error) {
NSLog(@":%d",success);
}];
Load same Image :
[asset requestContentEditingInputWithOptions:0 completionHandler:^(PHContentEditingInput * _Nullable contentEditingInput, NSDictionary * _Nonnull info) {
PHImageRequestOptions * option = [[PHImageRequestOptions alloc] init];
option.synchronous = YES;
option.version = PHImageRequestOptionsVersionOriginal;
option.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
option.resizeMode = PHImageRequestOptionsResizeModeNone;
[[PHImageManager defaultManager] requestImageDataForAsset:asset options:option resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
UIImage * image = [UIImage imageWithData:imageData];
NSData * tmpDAt = UIImageJPEGRepresentation(image, 1.0);
NSString * md5 = [tmpDAt MD5];
if ([md5 isEqualToString:self.str1]) {
NSLog(@"My Expextation");
}
}];
The Intresting thing that I found is if I crop my image to 1*1
for test, I receive some error ( JPEGDecompressSurface : Picture decode failed:
) during save (It seems OS can't modify image) so I get the same hash before and after save :) !
ios objective-c phasset phphotolibrary
add a comment |
Do you know is there any way to get the same NSData of Image ( JPG , PNG ) after save with PHPhotoLibrary
or no?
OfC, iOS will modify some metadata and EXIF
-- > ( Timestamp,... )data after save but, I'm asking about UIImage Data (include same EXIF data).
I didn't copy the exif in in my code here but it doesn't work
so Let's talk over the code:
Save Image and get hash
UIImage * tmp = [[UIImage alloc] initWithData:tmpData];
tmpData =UIImageJPEGRepresentation(tmp, 1.0);
self.str1 = [tmpData MD5];
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetResourceCreationOptions *options = [[PHAssetResourceCreationOptions alloc] init];
options.originalFilename = @"XXX";
PHAssetCreationRequest * createReq = [PHAssetCreationRequest creationRequestForAsset];
[createReq addResourceWithType:PHAssetResourceTypePhoto data:tmpData options:options];
} completionHandler:^(BOOL success, NSError * _Nullable error) {
NSLog(@":%d",success);
}];
Load same Image :
[asset requestContentEditingInputWithOptions:0 completionHandler:^(PHContentEditingInput * _Nullable contentEditingInput, NSDictionary * _Nonnull info) {
PHImageRequestOptions * option = [[PHImageRequestOptions alloc] init];
option.synchronous = YES;
option.version = PHImageRequestOptionsVersionOriginal;
option.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
option.resizeMode = PHImageRequestOptionsResizeModeNone;
[[PHImageManager defaultManager] requestImageDataForAsset:asset options:option resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
UIImage * image = [UIImage imageWithData:imageData];
NSData * tmpDAt = UIImageJPEGRepresentation(image, 1.0);
NSString * md5 = [tmpDAt MD5];
if ([md5 isEqualToString:self.str1]) {
NSLog(@"My Expextation");
}
}];
The Intresting thing that I found is if I crop my image to 1*1
for test, I receive some error ( JPEGDecompressSurface : Picture decode failed:
) during save (It seems OS can't modify image) so I get the same hash before and after save :) !
ios objective-c phasset phphotolibrary
add a comment |
Do you know is there any way to get the same NSData of Image ( JPG , PNG ) after save with PHPhotoLibrary
or no?
OfC, iOS will modify some metadata and EXIF
-- > ( Timestamp,... )data after save but, I'm asking about UIImage Data (include same EXIF data).
I didn't copy the exif in in my code here but it doesn't work
so Let's talk over the code:
Save Image and get hash
UIImage * tmp = [[UIImage alloc] initWithData:tmpData];
tmpData =UIImageJPEGRepresentation(tmp, 1.0);
self.str1 = [tmpData MD5];
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetResourceCreationOptions *options = [[PHAssetResourceCreationOptions alloc] init];
options.originalFilename = @"XXX";
PHAssetCreationRequest * createReq = [PHAssetCreationRequest creationRequestForAsset];
[createReq addResourceWithType:PHAssetResourceTypePhoto data:tmpData options:options];
} completionHandler:^(BOOL success, NSError * _Nullable error) {
NSLog(@":%d",success);
}];
Load same Image :
[asset requestContentEditingInputWithOptions:0 completionHandler:^(PHContentEditingInput * _Nullable contentEditingInput, NSDictionary * _Nonnull info) {
PHImageRequestOptions * option = [[PHImageRequestOptions alloc] init];
option.synchronous = YES;
option.version = PHImageRequestOptionsVersionOriginal;
option.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
option.resizeMode = PHImageRequestOptionsResizeModeNone;
[[PHImageManager defaultManager] requestImageDataForAsset:asset options:option resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
UIImage * image = [UIImage imageWithData:imageData];
NSData * tmpDAt = UIImageJPEGRepresentation(image, 1.0);
NSString * md5 = [tmpDAt MD5];
if ([md5 isEqualToString:self.str1]) {
NSLog(@"My Expextation");
}
}];
The Intresting thing that I found is if I crop my image to 1*1
for test, I receive some error ( JPEGDecompressSurface : Picture decode failed:
) during save (It seems OS can't modify image) so I get the same hash before and after save :) !
ios objective-c phasset phphotolibrary
Do you know is there any way to get the same NSData of Image ( JPG , PNG ) after save with PHPhotoLibrary
or no?
OfC, iOS will modify some metadata and EXIF
-- > ( Timestamp,... )data after save but, I'm asking about UIImage Data (include same EXIF data).
I didn't copy the exif in in my code here but it doesn't work
so Let's talk over the code:
Save Image and get hash
UIImage * tmp = [[UIImage alloc] initWithData:tmpData];
tmpData =UIImageJPEGRepresentation(tmp, 1.0);
self.str1 = [tmpData MD5];
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
PHAssetResourceCreationOptions *options = [[PHAssetResourceCreationOptions alloc] init];
options.originalFilename = @"XXX";
PHAssetCreationRequest * createReq = [PHAssetCreationRequest creationRequestForAsset];
[createReq addResourceWithType:PHAssetResourceTypePhoto data:tmpData options:options];
} completionHandler:^(BOOL success, NSError * _Nullable error) {
NSLog(@":%d",success);
}];
Load same Image :
[asset requestContentEditingInputWithOptions:0 completionHandler:^(PHContentEditingInput * _Nullable contentEditingInput, NSDictionary * _Nonnull info) {
PHImageRequestOptions * option = [[PHImageRequestOptions alloc] init];
option.synchronous = YES;
option.version = PHImageRequestOptionsVersionOriginal;
option.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
option.resizeMode = PHImageRequestOptionsResizeModeNone;
[[PHImageManager defaultManager] requestImageDataForAsset:asset options:option resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
UIImage * image = [UIImage imageWithData:imageData];
NSData * tmpDAt = UIImageJPEGRepresentation(image, 1.0);
NSString * md5 = [tmpDAt MD5];
if ([md5 isEqualToString:self.str1]) {
NSLog(@"My Expextation");
}
}];
The Intresting thing that I found is if I crop my image to 1*1
for test, I receive some error ( JPEGDecompressSurface : Picture decode failed:
) during save (It seems OS can't modify image) so I get the same hash before and after save :) !
ios objective-c phasset phphotolibrary
ios objective-c phasset phphotolibrary
edited Nov 28 '18 at 21:13
Mo Farhand
asked Nov 19 '18 at 11:58
Mo FarhandMo Farhand
784519
784519
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
I presume the difference is due to your JPEGs having different timestamps (and possibly other differences) in their EXIF metadata.
Have you tried using UIImagePNGRepresentation
instead of UIImageJPEGRepresentation
? Hopefully PNG representations will match.
I was thinking about this too but what If I copy all of EXIF data for the new image ? (JPEG)
– Mo Farhand
Nov 21 '18 at 18:44
also, I tried withUIImagePNGRepresentation
also as you know PNG doesn't keep the orientation so I check the md5 results in all orientation and doesn't match with the original one. I think it can be related to timestamp and ... but not sure as I'm copy all of EXIF information for the new image
– Mo Farhand
Nov 21 '18 at 18:51
any idea? have you tried the same?
– Mo Farhand
Nov 23 '18 at 12:50
add a comment |
Jpeg compression is a Lossy form of compression. Every time you convert to Jpeg you will lose data. There is no way around it. Removing PHPhotoLibrary from the equation. If you run the following
UIImage * tmp = [[UIImage alloc] initWithData:tmpData];
tmpData =UIImageJPEGRepresentation(tmp, 1.0);
str1 = [tmpData MD5];
tmp = [[UIImage alloc] initWithData:tmpData];
tmpData =UIImageJPEGRepresentation(tmp, 1.0);
str2 = [tmpData MD5];
You will find that str1 and str2 are different.
If you want the same data you will have to either keep the original jpeg data that generated the image or use a loseless compression method like the one used within the PNG files.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374159%2fget-the-same-nsdata-of-phasset-after-save%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I presume the difference is due to your JPEGs having different timestamps (and possibly other differences) in their EXIF metadata.
Have you tried using UIImagePNGRepresentation
instead of UIImageJPEGRepresentation
? Hopefully PNG representations will match.
I was thinking about this too but what If I copy all of EXIF data for the new image ? (JPEG)
– Mo Farhand
Nov 21 '18 at 18:44
also, I tried withUIImagePNGRepresentation
also as you know PNG doesn't keep the orientation so I check the md5 results in all orientation and doesn't match with the original one. I think it can be related to timestamp and ... but not sure as I'm copy all of EXIF information for the new image
– Mo Farhand
Nov 21 '18 at 18:51
any idea? have you tried the same?
– Mo Farhand
Nov 23 '18 at 12:50
add a comment |
I presume the difference is due to your JPEGs having different timestamps (and possibly other differences) in their EXIF metadata.
Have you tried using UIImagePNGRepresentation
instead of UIImageJPEGRepresentation
? Hopefully PNG representations will match.
I was thinking about this too but what If I copy all of EXIF data for the new image ? (JPEG)
– Mo Farhand
Nov 21 '18 at 18:44
also, I tried withUIImagePNGRepresentation
also as you know PNG doesn't keep the orientation so I check the md5 results in all orientation and doesn't match with the original one. I think it can be related to timestamp and ... but not sure as I'm copy all of EXIF information for the new image
– Mo Farhand
Nov 21 '18 at 18:51
any idea? have you tried the same?
– Mo Farhand
Nov 23 '18 at 12:50
add a comment |
I presume the difference is due to your JPEGs having different timestamps (and possibly other differences) in their EXIF metadata.
Have you tried using UIImagePNGRepresentation
instead of UIImageJPEGRepresentation
? Hopefully PNG representations will match.
I presume the difference is due to your JPEGs having different timestamps (and possibly other differences) in their EXIF metadata.
Have you tried using UIImagePNGRepresentation
instead of UIImageJPEGRepresentation
? Hopefully PNG representations will match.
answered Nov 21 '18 at 15:39
ClafouClafou
12.2k54580
12.2k54580
I was thinking about this too but what If I copy all of EXIF data for the new image ? (JPEG)
– Mo Farhand
Nov 21 '18 at 18:44
also, I tried withUIImagePNGRepresentation
also as you know PNG doesn't keep the orientation so I check the md5 results in all orientation and doesn't match with the original one. I think it can be related to timestamp and ... but not sure as I'm copy all of EXIF information for the new image
– Mo Farhand
Nov 21 '18 at 18:51
any idea? have you tried the same?
– Mo Farhand
Nov 23 '18 at 12:50
add a comment |
I was thinking about this too but what If I copy all of EXIF data for the new image ? (JPEG)
– Mo Farhand
Nov 21 '18 at 18:44
also, I tried withUIImagePNGRepresentation
also as you know PNG doesn't keep the orientation so I check the md5 results in all orientation and doesn't match with the original one. I think it can be related to timestamp and ... but not sure as I'm copy all of EXIF information for the new image
– Mo Farhand
Nov 21 '18 at 18:51
any idea? have you tried the same?
– Mo Farhand
Nov 23 '18 at 12:50
I was thinking about this too but what If I copy all of EXIF data for the new image ? (JPEG)
– Mo Farhand
Nov 21 '18 at 18:44
I was thinking about this too but what If I copy all of EXIF data for the new image ? (JPEG)
– Mo Farhand
Nov 21 '18 at 18:44
also, I tried with
UIImagePNGRepresentation
also as you know PNG doesn't keep the orientation so I check the md5 results in all orientation and doesn't match with the original one. I think it can be related to timestamp and ... but not sure as I'm copy all of EXIF information for the new image– Mo Farhand
Nov 21 '18 at 18:51
also, I tried with
UIImagePNGRepresentation
also as you know PNG doesn't keep the orientation so I check the md5 results in all orientation and doesn't match with the original one. I think it can be related to timestamp and ... but not sure as I'm copy all of EXIF information for the new image– Mo Farhand
Nov 21 '18 at 18:51
any idea? have you tried the same?
– Mo Farhand
Nov 23 '18 at 12:50
any idea? have you tried the same?
– Mo Farhand
Nov 23 '18 at 12:50
add a comment |
Jpeg compression is a Lossy form of compression. Every time you convert to Jpeg you will lose data. There is no way around it. Removing PHPhotoLibrary from the equation. If you run the following
UIImage * tmp = [[UIImage alloc] initWithData:tmpData];
tmpData =UIImageJPEGRepresentation(tmp, 1.0);
str1 = [tmpData MD5];
tmp = [[UIImage alloc] initWithData:tmpData];
tmpData =UIImageJPEGRepresentation(tmp, 1.0);
str2 = [tmpData MD5];
You will find that str1 and str2 are different.
If you want the same data you will have to either keep the original jpeg data that generated the image or use a loseless compression method like the one used within the PNG files.
add a comment |
Jpeg compression is a Lossy form of compression. Every time you convert to Jpeg you will lose data. There is no way around it. Removing PHPhotoLibrary from the equation. If you run the following
UIImage * tmp = [[UIImage alloc] initWithData:tmpData];
tmpData =UIImageJPEGRepresentation(tmp, 1.0);
str1 = [tmpData MD5];
tmp = [[UIImage alloc] initWithData:tmpData];
tmpData =UIImageJPEGRepresentation(tmp, 1.0);
str2 = [tmpData MD5];
You will find that str1 and str2 are different.
If you want the same data you will have to either keep the original jpeg data that generated the image or use a loseless compression method like the one used within the PNG files.
add a comment |
Jpeg compression is a Lossy form of compression. Every time you convert to Jpeg you will lose data. There is no way around it. Removing PHPhotoLibrary from the equation. If you run the following
UIImage * tmp = [[UIImage alloc] initWithData:tmpData];
tmpData =UIImageJPEGRepresentation(tmp, 1.0);
str1 = [tmpData MD5];
tmp = [[UIImage alloc] initWithData:tmpData];
tmpData =UIImageJPEGRepresentation(tmp, 1.0);
str2 = [tmpData MD5];
You will find that str1 and str2 are different.
If you want the same data you will have to either keep the original jpeg data that generated the image or use a loseless compression method like the one used within the PNG files.
Jpeg compression is a Lossy form of compression. Every time you convert to Jpeg you will lose data. There is no way around it. Removing PHPhotoLibrary from the equation. If you run the following
UIImage * tmp = [[UIImage alloc] initWithData:tmpData];
tmpData =UIImageJPEGRepresentation(tmp, 1.0);
str1 = [tmpData MD5];
tmp = [[UIImage alloc] initWithData:tmpData];
tmpData =UIImageJPEGRepresentation(tmp, 1.0);
str2 = [tmpData MD5];
You will find that str1 and str2 are different.
If you want the same data you will have to either keep the original jpeg data that generated the image or use a loseless compression method like the one used within the PNG files.
answered Dec 11 '18 at 10:21
SpadsSpads
1,6261519
1,6261519
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53374159%2fget-the-same-nsdata-of-phasset-after-save%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown