2

中に がありUIScrollViewますUIImageView。ユーザーは、scrollView 内で画像をパンおよびズームできます。

UIImageViewメイン ビュー (scrollView の上) にもあり、ユーザーはその画像を画面上で移動できます。

CISourceOverCompositing を使用して、両方を結合しています。

-(UIImage *) compositeFinalImage {

    CIImage *foregroundImage = [CIImage imageWithCGImage:foregroundImageView.image.CGImage];

    CIFilter *composite =[CIFilter filterWithName:@"CISourceOverCompositing"];
    [composite setValue: foregroundImage forKey: @"inputImage"];
    [composite setValue: [CIImage imageWithCGImage:backgroundImage.CGImage] forKey: @"inputBackgroundImage"];

    CIContext *context = [CIContext contextWithOptions:nil];
    CIImage *finalImage = [composite valueForKey:@"outputImage"];

    return [UIImage imageWithCGImage:[context createCGImage:finalImage fromRect:finalImage.extent] scale:1.0 orientation:userImageOrientation];    
}

...しかし、画像を にすると、画像の位置と縮尺が失われCIImage、前景画像が常に左下に表示されます。

だから私imageByApplyingTransformは前景画像の位置を移動するために使用しようとしました(そして最終的にはスケール変換も適用する必要があります)が、ImageViewから位置を取得しますが、座標は背景画像のネイティブ解像度である必要がありますそれ自体...しかし、背景画像は動き回っています(これはContentOffset、どういうわけか考慮に入れる必要があることを意味すると思います)、背景画像には特定のスケールがあり、前景画像には特定のスケールがあります...

各画像のさまざまなスケール、回転、および位置変数に関して、すべての変換を再生成する必要があるのは奇妙に思えます...

これは、私がやろうとしていることの基本的な考え方です (左側はメイン ビュー座標で、右側はネイティブ イメージ座標です)。

どんな助けでも大歓迎です!

ありがとう!

全体計画

4

0 に答える 0