gpt4 book ai didi

ios - 从大 PNG 生成图 block

转载 作者:行者123 更新时间:2023-11-29 04:12:55 24 4
gpt4 key购买 nike

我希望使用 CATiledLayer 在 iOS 设备上显示巨大的 PNG 图像。为此,我需要在客户端将较大的图像分割为图 block (分别为 100%、50%、25% 和 12.5%)(不能在服务器端创建图 block )。

我可以看到有一些库(例如 libjpeg-turbo)可以使用,但是这些库适用于 JPEG,而我需要使用 PNG。

有谁知道我可以采用大 PNG (~20Mb) 并在设备上从中生成图 block 的方法吗?

如有任何指示或建议,我们将不胜感激!

谢谢!

最佳答案

您可以使用内置的 Core Graphics CGDataProviderCreateWithFilename 和 CGI​​mageCreateWithPNGDataProvider API 打开图像,然后通过执行以下操作来创建每个图 block :

const CGSize tileSize = CGSizeMake(256, 256);
const CGPoint tileOrigin = ...; // Calculate using current column, row, and tile size.
const CGRect tileFrame = CGRectMake(-tileOrigin.x, -tileOrigin.y, imageSize.width, imageSize.height);

UIGraphicsBeginImageContextWithOptions(tileSize, YES, 1);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextDrawImage(context, tileFrame, image.CGImage);

UIImage *tileImage = UIGraphicsGetImageFromCurrentImageContext();
[UIImagePNGRepresentation(tileImage) writeToFile:tilePath atomically:YES];
UIGraphicsEndImageContext();

您可能还想查看 UIScrollView 类引用下引用的相关示例项目(大图像缩小和 PhotoScroller)。

关于ios - 从大 PNG 生成图 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14142824/

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