如何使用 CATiledLayer 处理下载的图像
新年快乐,
我正在编写一个应用程序,用户可以在线搜索高分辨率图像,然后下载这些大图像。我需要在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从 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.
在一本涵盖核心动画的书中有一个例子( 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 :-)