cuốn sách gpt4 ai đã làm

ios - 我如何以编程方式将一些 UIImage 组合在一起以获得一个大的 UIImage?

In lại Tác giả: Walker 123 更新时间:2023-11-28 19:02:25 27 4
mua khóa gpt4 Nike

Đây là mã của tôi:

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
{

// at this point the webView scrolled to the next section

// I save the offset to make the code a little easier to read
CGFloat offset = _webPage.scrollView.contentOffset.y;

UIGraphicsBeginImageContextWithOptions(_webPage.bounds.size, NO, 0);

[_webPage.layer renderInContext:UIGraphicsGetCurrentContext()];
viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();


UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);

// if we are not done yet, scroll to next section
if (offset < _webPage.scrollView.contentSize.height)
{
[_webPage.scrollView scrollRectToVisible:CGRectMake(0, _webPage.frame.size.height+offset, _webPage.frame.size.width, _webPage.frame.size.height) animated:YES];
}
}

我在其中通过滚动 web view 保存了未定义数量的屏幕截图 (UIImages)。这行得通,我的照片库中有网页的所有部分。但我不想要零件,我想要一个长的 UIImage。那么如何将我的 UIImage 放在一起(一个接一个?)?

câu trả lời hay nhất

你可以写一个 UIImage 类别来做到这一点

UIImage+Combine.h

#import 

@interface UIImage (Combine)

+ (UIImage*)imageByCombiningImage:(UIImage*)firstImage withImage:(UIImage*)secondImage;

@kết thúc

UIImage+Combine.m

#import "UIImage+Combine.h"


@implementation UIImage (Combine)

+ (UIImage*)imageByCombiningImage:(UIImage*)firstImage withImage:(UIImage*)secondImage {
UIImage *image = nil;

CGSize newImageSize = CGSizeMake(MAX(firstImage.size.width, secondImage.size.width), firstImage.size.height + secondImage.size.height);
if (UIGraphicsBeginImageContextWithOptions != NULL) {
UIGraphicsBeginImageContextWithOptions(newImageSize, NO, [[UIScreen mainScreen] scale]);
} khác {
UIGraphicsBeginImageContext(newImageSize);
}
[firstImage drawAtPoint:CGPointMake(roundf((newImageSize.width-firstImage.size.width)/2), 0)];
[secondImage drawAtPoint:CGPointMake(roundf(((newImageSize.width-secondImage.size.width)/2) ),
roundf((newImageSize.height-secondImage.size.height)))];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return image;
}

然后您可以在您的代码中调用该函数:

UIImage *img = [UIImage imageByCombiningImage:image1 withImage:image2];

这将绘制一个新图像,该图像具有两个图像中最大的宽度和两个图像组合的高度。 image1 将位于顶部,image2 位于其下方。

关于ios - 我如何以编程方式将一些 UIImage 组合在一起以获得一个大的 UIImage?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23649182/

27 4 0
Walker 123
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress