gpt4 book ai didi

iphone - 将一个图像放在另一个图像之上

转载 作者:行者123 更新时间:2023-11-29 03:59:37 25 4
gpt4 key购买 nike

我想做的是以下内容。用户可以使用 iPhone 相机拍照。拍摄照片后,他们将在拍摄的照片上放置另一张图像。放置在顶部的图像也应旋转 25°。除了旋转之外,我还需要将顶部的图像降低到拍摄的照片下方一点。你可以在这里明白我的意思。

enter image description here

我有以下内容。

-(UIImage *)drawImage:(UIImage*)profileImage withBadge:(UIImage *)badge
{
UIGraphicsBeginImageContextWithOptions(profileImage.size, NO, 0.0f);
[profileImage drawInRect:CGRectMake(0, 0, profileImage.size.width, profileImage.size.height)];
[badge drawInRect:CGRectMake(profileImage.size.width - badge.size.width, profileImage.size.height - badge.size.height,badge.size.width,badge.size.height)];

UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resultImage;
}

-(void)captureImage {
UIImage *img1 = [cropFilter imageFromCurrentlyProcessedOutput];
UIImage *img2 = [UIImage imageNamed:@"genkonstage.jpg"];
UIImage *img = [self drawImage:img1 withBadge:img2];

//UIImage *img = [cropFilter imageFromCurrentlyProcessedOutput];
[stillCamera.inputCamera unlockForConfiguration];
[stillCamera stopCameraCapture];
[self removeAllTargets];

staticPicture = [[GPUImagePicture alloc] initWithImage:img
smoothlyScaleOutput:YES];

有人可以帮助我吗?

最佳答案

我建议这样:

#define DEGREES_TO_RADIANS(x) (M_PI * x / 180.0)

-(UIImage *)drawImage:(UIImage*)profileImage withBadge:(UIImage *)badge
{
UIGraphicsBeginImageContextWithOptions(profileImage.size, NO, 0.0f);
CGContextRef imageContext = UIGraphicsGetCurrentContext();
CGContextClearRect(imageContext, CGRectMake(0, 0, profileImage.size.width, profileImage.size.height)); // just in case let's clear the context
[profileImage drawInRect:CGRectMake(0, 0, profileImage.size.width, profileImage.size.height)];
float angle = DEGREES_TO_RADIANS(20);
CGContextSaveGState (imageContext); {
CGContextTranslateCTM(imageContext, profileImage.size.width - badge.size.width, profileImage.size.height - badge.size.height); // this will shift your context
CGAffineTransform rotationMatrix = CGAffineTransformMake(cos(angle), -sin(angle), sin(angle), cos(angle), 0, 0);
CGContextConcatCTM(imageContext, rotationMatrix); // this will rotate the context
// Now, having the context prepared (rotated and translated), draw the badge into it
[badge drawInRect:CGRectMake(0, 0, badge.size.width, badge.size.height)];
} CGContextRestoreGState (imageContext);
UIImage *resultImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return resultImage;
}

这段代码对我有用。

关于iphone - 将一个图像放在另一个图像之上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16062974/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com