1

私はカメラのオーバーレイ画像の上に画像(上部の画像など)を置くアプリを持っています。カメラ上の画像overlayViewは、ズーム、ピンチ、回転してから、カメラ画像と組み合わせることができます。私は正常に画像を回転させるコードをstackoverflowで見つけました。助けてください。ありがとうございます。私のコードは.

-(UIImage*)combineImage:(UIImage *)camImage withImage:(UIImage *)topImage
{

        UIImage *scaledTopImg = [self imageByScalingProportionallyToSize:imageView.frame.size withImage:topImage];

        UIGraphicsBeginImageContext(scaledTopImg.size); //scaling top image after resizing
        CGContextRef ctx = UIGraphicsGetCurrentContext();     
        CGContextTranslateCTM(ctx, imageView.frame.size.width*0.5f , imageView.frame.size.height*0.5f);                    

        CGFloat angle = atan2(imageView.transform.b, imageView.transform.a);
        CGContextRotateCTM(ctx, angle);

        [scaledTopImg drawInRect:CGRectMake(- scaledTopImg.size.width * 0.5f, -(scaledTopImg.size.height  * 0.5f), scaledTopImg.size.width, scaledTopImg.size.height)];

        UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        if ([[UIDevice currentDevice]orientation]==UIInterfaceOrientationLandscapeLeft ||[[UIDevice currentDevice]orientation]==UIInterfaceOrientationLandscapeRight) {
            UIGraphicsBeginImageContext(CGSizeMake( 1024,768));//Creating Camera image
            [camImage drawInRect:CGRectMake(0, 0, 1024, 768)];
        }
        else{
            UIGraphicsBeginImageContext(CGSizeMake(768, 1024));
            [camImage drawInRect:CGRectMake(0, 0, 768, 1024)];
        }

        CGRect rect = imageView.frame;

        [newImage drawInRect:CGRectMake(imageView.frame.origin.x, imageView.frame.origin.y,imageView.frame.size.width, imageView.frame.size.height)]; //Drawing scaled image over camera image 

        UIImage *newImage2 = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return newImage2;
}
4

0 に答える 0