3

シナリオ: iPhone のカメラ ロールに画像があります。を使用してアクセスしALAssetLibrary、オブジェクトを取得しALAssetます。次のコードのようなものを使用して、そこからオブジェクトを取得しUIImageます。NSData

ALAssetRepresentation *rep = [myasset defaultRepresentation];
CGImageRef iref = [rep fullResolutionImage];
if (iref)
{
    UIImage *largeimage = [UIImage imageWithCGImage:iref ];
    NSData * data = UIImageJPEGRepresentation(largeimage, 1.0f);
}

次に、イメージ キャプチャを使用してカメラ ロールからイメージを Mac にコピーします。次にNSImage、Mac コードで を使用して、コピーした画像を開き、NSData次のコードを使用して表現を取得しようとします。

NSImage * image = [[NSImage alloc] initWithContentsOfURL:fileURL];
NSBitmapImageRep *imgRep = [[image representations] objectAtIndex: 0];
NSData *data = [imgRep representationUsingType: NSJPEGFileType properties: nil];

問題: 残念ながら、NSData得られる 2 つの表現は大きく異なります。どちらの場合も同じ表現を取得できるようにしたいNSData(同じファイルであるため)。次に、NSDataオブジェクトをハッシュし、ハッシュを比較して、2 つが (おそらく) 同じ画像であると結論付けます。理想的には、次の 2 つの機能が必要です。

//In iOS
-(NSData *) getDataFromALAsset:(ALAsset*)asset;
//or 
-(NSData *) getDataFromUIImage:(UIImage*)image;

//In OS X
-(NSData *) getDataFromFileAtURL:(NSURL*)url;
//or 
-(NSData *) getDataFromNSImage:(NSImage*)image;

OS X と iOS で取得した NSData* 表現は、同じソース イメージから取得したものであるため、まったく同じです。

私が試したこと:

I have tried to play around with how I get the UIImage object from the ALAsset object, I have tried to UIImagePNGRepresentation (and the corresponding for getting NSData in OS X). I have also tried to play around with different parameters for getting the representation in OS X but nothing has come through. I have also tried to create a CGIImageRef on both platforms, convert that to Bitmaps and read them pixel by pixel and even those seem to be off (and yes I do realise that the NSBitmapImageRep has different co-ordinate system).

4

1 に答える 1