如何使用 CATiledLayer 处理下载的图像

发布于 2024-10-09 15:11:35 字数 254 浏览 13 评论 0原文

新年快乐,

我正在编写一个应用程序,用户可以在线搜索高分辨率图像,然后下载这些大图像。我需要在 UIScrollView 中显示这些。

在 Apple 开发网站上,我在 UIScrollViews 上找到了 WWDC 2010 Session 104,它解释了如何在各种缩放级别将 CATiledLayer 与手动创建的图块集一起使用。

有没有办法从下载的高分辨率图像文件以编程方式生成图块?

有什么建议吗?

谢谢

Happy New Year,

I am writing an app where the user searches for high res images online and then downloads these large images. I need to show these in a UIScrollView.

On the Apple dev site I found the WWDC 2010 Session 104 on UIScrollViews that explains how I can use CATiledLayer with a manually created set of tiles at the various zoom levels.

Is there a way to generate the tiles programmatically from the downloaded high res image file?

Any recommendations?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱你不解释 2024-10-16 15:11:36

从 CGImage 开始(如果从 UIImage 开始,UIImage 有一个只读 CGImage 属性),您可以使用 CGImageCreateWithImageInRect 从原始文件创建图块。

要创建不同缩放级别的图块,您可能需要将缩放后的 CGImage 绘制到图形上下文,并使用 UIGraphicsGetImageFromCurrentImageContext 获取包含绘制图像的 UIImage,然后将其写入某些缓存。请参阅 iOS 绘图和打印指南中的“创建和绘图图像”

Starting with a CGImage (UIImage has a readonly CGImage property if you're starting with a UIImage) you can use CGImageCreateWithImageInRect to create tiles from the original.

To create tiles at different zoom levels you'll probably need to draw your scaled CGImage to a graphics context and use UIGraphicsGetImageFromCurrentImageContext to get a UIImage containing the drawn image which you can then write out to some cache. See "Creating and Drawing Images" in the Drawing and Printing Guide for iOS.

回眸一笑 2024-10-16 15:11:36

在一本涵盖核心动画的书中有一个例子( link )就涵盖了这一点。此外,这本书的其他东西也物有所值:-)

There's an example in a book covering Core Animation ( link ) covering just that. Besides, the book is worth the money for the other stuff as well :-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文