0

ITunes を介して 2 つの Ipad (IPAD1 と IPAD2 としましょう) に画像を同期しました。で、ALAssetLibraryブロックを使って画像を取得したところ、2台のiPadでファイルサイズが違う。

(IPAD1 ファイル サイズ: 0.024059、IPAD2 ファイル サイズ: 0.024325)。

IPAD1 と IPAD2 で同じファイルのサイズが異なるのはなぜですか?

ただし、Safariブラウザを介してIPAD1とIPAD2に画像を保存し、同じWebページから画像をタップして、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];    

 }

The NSLog(@"GOT ASSET, File size: %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

ありがとう。

4

1 に答える 1

1

実装の詳細です。それらが同一であるという保証はありません。たとえば、メタデータ (ハードウェア情報、シリアル番号、時刻など) はデバイス間で異なる場合があります。

達成しようとしているより広い目標を教えていただければ、ファイル サイズを比較する別の解決策を見つけるお手伝いができるかもしれません。

于 2011-11-23T16:16:02.250 に答える