Iphone 使用ALASET块检索时,IPAD1和IPAD2中的相同文件大小不同

Iphone 使用ALASET块检索时,IPAD1和IPAD2中的相同文件大小不同,iphone,xcode,ipad,file,alasset,Iphone,Xcode,Ipad,File,Alasset,我已经通过ITunes将一张图像同步到2台iPad(比如IPAD1和IPAD2)。 然后,当我使用ALAssetLibrary块检索图像时,2台iPad中的文件大小不同 (IPAD1文件大小:0.024059,IPAD2文件大小:0.024325) 请问,为什么IPAD1和IPAD2中的相同文件大小不同 然而,我通过safari浏览器将图像保存到IPAD1和IPAD2,通过点击同一网页上的图像,我在通过ALAssetLibarary检索时获得了IPAD1和IPAD2中图像的相同文件大小 请告诉我

我已经通过ITunes将一张图像同步到2台iPad(比如IPAD1和IPAD2)。 然后,当我使用ALAssetLibrary块检索图像时,2台iPad中的文件大小不同

(IPAD1文件大小:0.024059,IPAD2文件大小:0.024325)

请问,为什么IPAD1和IPAD2中的相同文件大小不同

然而,我通过safari浏览器将图像保存到IPAD1和IPAD2,通过点击同一网页上的图像,我在通过ALAssetLibarary检索时获得了IPAD1和IPAD2中图像的相同文件大小

请告诉我你的宝贵建议

用法


我用于检索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(@“已获取资产,文件大小:%f”,[rep size]/(1024.0f*1024.0f));在不同的设备中为同一文件打印不同的值

控制台日志详细信息


Ipad1


已获取资产,文件大小:0.024059 图像CRC为:2659650838

Ipad2


已获取资产,文件大小:0.024325 @@@@@@@@图像CRC为:331786167

IPAD版本详细信息


IPAD1: 版本:4.2.1(8C148) 型号:MB292LL

IPAD2: 版本:4.3.5(8L1) 型号:MB292LL


谢谢。

这是一个实现细节。不能保证它们是一样的。元数据(例如硬件信息、序列号、一天中的时间等)可能在设备之间有所不同


如果您告诉我们您试图实现的更广泛的目标,我们可能会帮助您找到比较文件大小的替代解决方案。

我想补充一点,CRC校验和不足以确保两个图像是相同的!的确鸽子洞原理告诉我们,n位的散列不能区分超过2*n*的值,图像的长度几乎总是超过32位。“任意数据之间发生冲突的风险非常高,这是意料之中的”。@JonathanGrynspan@JustSid对我来说,也发现了同样的问题。我还在Ipad PhotoLibrary中进行图像比较。每当图像传输请求来自另一个设备时,我必须测试PhotoLibrary中是否存在图像文件。那么我可以知道如何测试它吗?在PhotoLibrary图像文件存在检查过程中,我需要从发送设备传输到学习者的所有图像细节是什么?那么,客观上,是什么使两个图像彼此相等?我只是通过iTunes将一个图像同步到不同的iPad(IPAD1和IPAD2)。当我通过WI-Fi将同步图像从IPAD1传输到IPAD2时,只需检查IPAD2 photolibrary中是否存在图像文件。在我们的例子中,图像文件是存在的(因为我们很早就同步到了两台iPad),所以我需要从IPAD2获取当前对应的图像URL。这就是问题所在
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];    

 }