我已经通过ITunes将图像同步到2个Ipads(让我们说IPAD1和IPAD2)。 然后,当我使用ALAssetLibrary块检索图像时,2个Ipads中的文件大小不同。
(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图像的代码是:
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,文件大小:%f”,[rep size] /(1024.0f * 1024.0f));在不同设备中为同一文件打印不同的值。
控制台日志详细信息
IPAD1
GOT ASSET,文件大小:0.024059 图像CRC是:2659650838
IPAD2
GOT ASSET,文件大小:0.024325 @@@@@@@@ image CRC是:331786167
IPAD版本细节
IPAD1: 版本:4.2.1(8C148) 型号:MB292LL
IPAD2: 版本:4.3.5(8L1) 型号:MB292LL
感谢。
答案 0 :(得分:1)
这是一个实现细节。不能保证他们会完全相同。例如,设备之间的元数据(例如硬件信息,序列号,时间等)可能会有所不同。
如果您告诉我们您要实现的更广泛的目标,我们可以帮助您找到比较文件大小的替代解决方案。