iOS:如何创建和绘制(并保存)大于屏幕的图像? [英] iOS: How to create and draw into (and save) an image larger than the screen?

查看:82
本文介绍了iOS:如何创建和绘制(并保存)大于屏幕的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在创建一个iOS照片应用。为此,我们必须创建动态尺寸最大为2500x1600px的图像。一旦创建了此图像,我们就希望在大图像上合理地绘制较小的图像。

We're creating an iOS photo app. In doing this, we have to create dynamically sized images up to about 2500x1600px. Once this image has been created, we want to draw smaller images on top of the big one reasonably quickly.

我们看到的问题是不可能获得大于屏幕分辨率的上下文。调用不会崩溃,但是会返回nil上下文。

The problem as we can see it is that it's impossible to get a context larger than the screen resolution. The call does not crash, but it returns a nil-context. How can such a seemingly simple task be achieved?

其次,一旦创建了上下文,最快的方法是在指定位置上绘制小图像的最快方法是

Secondly, once this context is created, what is the fastest way to draw a small image at a given position on top of the big one?

编辑:

我们找到了解决方案。 CGBitmapContextCreate返回nil,因为width和height参数设置为float而不是ints。有时候,解决方案就在您眼前,而您却视而不见。希望这个答案可以帮助其他人也遇到同样的问题。

We found the solution. CGBitmapContextCreate returns nil because the width and height parameters were set as floats, not ints. Sometimes the solution is right there in front of you, and you're too blind to see it. Hopefully this answer can help other people that somehow have the same problem.

推荐答案

请确保您指定整数宽度和高度作为参数到CGBitmapContextCreate,否则返回nil。否则,上下文的大小无关紧要,只要您可以为其分配足够的内存即可。

Make sure you specify integer widths and heights as the arguments to CGBitmapContextCreate, otherwise it returns nil. Otherwise, the size of the context should not matter as long as you can malloc enough memory for it.

这篇关于iOS:如何创建和绘制(并保存)大于屏幕的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆