我已经通过 iTunes 将图像同步到 2 个 Ipad(比如说 IPAD1 和 IPAD2)。然后,当我使用 ALAssetLibrary 块检索图像时,2 个 Ipad 中的文件大小不同。
(IPAD1 文件大小:0.024059,IPAD2 文件大小:0.024325)。
我可以知道,为什么相同的文件在 IPAD1 和 IPAD2 中的大小不同?
但是,我通过 safari 浏览器将图像保存到 IPAD1 和 IPAD2,通过点击同一网页中的图像,当我通过 ALAssetLibarary 检索时,Ipad1 和 Ipad2 中的图像文件大小相同。
请告诉我您的宝贵建议......
用法
I am doing the image comparison in Ipad PhotoLibrary.
Whenever an Image transfer request is coming from another device, i have to test the image file exist in PhotoLibrary.
So mentor image request will have CRC code of the requested image which will uneque for the same image file and i am generating the CRC code for all my photoLibrary images and comparing it with the requested image CRC code.
So whenever these 2 CRC's are equal , i can easily identify the files are same.
我用于检索 PhotoLibrary Image 的代码是:
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
ALAssetRepresentation *rep = [myasset defaultRepresentation];
NSLog(@"GOT ASSET, File size: %f", [rep size] / (1024.0f*1024.0f));
uint8_t* buffer = malloc([rep size]);
NSError* error = NULL;
NSUInteger bytes = [rep getBytes:buffer fromOffset:0 length:[rep size] error:&error];
if (bytes == [rep size])
{
defaultRepresentationData = [[NSData dataWithBytes:buffer length:bytes] retain];
CGImageRef iref = [rep fullResolutionImage];
UIImage *photLibraryImage = [UIImage imageWithCGImage:iref];
NSData *imageData = UIImagePNGRepresentation(photLibraryImage); //convert image into .png format.
const int imageCRC = [self CRCForImage:imageData]]; //getting CRC value for image data
NSLog([NSString stringWithFormat:@"@@@@@@@@ image CRC is:%u",imageCRC ]);
}
else
{
NSLog(@"Error '%@' reading bytes from asset: '%@'", [error localizedDescription]); //assetURL);
}
free(buffer);
// notifies the lock that "all tasks are finished"
};
//
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
NSLog(@"NOT GOT ASSET");
};
NSURL *asseturl = [NSURL URLWithString:fileName];
ALAssetsLibrary* assetslibrary = [[[ALAssetsLibrary alloc] init] autorelease];
[assetslibrary assetForURL:asseturl resultBlock:resultblock failureBlock:failureblock];
}
NSLog(@"GOT ASSET, File size: %f", [rep size] / (1024.0f*1024.0f)); 在不同设备中为同一文件打印不同的值。
控制台日志详细信息
Ipad1
GOT 资产,文件大小:0.024059 图像 CRC 为:2659650838
iPad2
GOT 资产,文件大小:0.024325 @@@@@@@@image CRC 为:331786167
IPAD 版本详情
IPAD1:版本:4.2.1(8C148) 型号:MB292LL
IPAD2:版本:4.3.5(8L1) 型号:MB292LL
谢谢。