计算一个UIImage保存到相册 [英] Computing a UIImage to be saved to the photo album

查看:225
本文介绍了计算一个UIImage保存到相册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基本上想从一堆源图像自动创建一个平铺图像,然后是保存到用户的相册。我没有任何成功绘制了一堆小的UIImage的进入一个大的UIImage。什么是实现这一目标的最佳途径?目前我使用UIGraphicsBeginImageContext()和[UIImage的drawAtPoint],等等。所有我曾经结束了是512×512的黑色正方形。我应该怎么做呢?我期待CGLayer的等似乎也有很多的选择,但没有说特别容易的工作。

I basically want to automatically create a tiled image from a bunch of source images, and then save that to the user's photo album. I'm not having any success drawing a bunch of small UIImage's into one big UIImage. What's the best way to accomplish this? Currently I'm using UIGraphicsBeginImageContext() and [UIImage drawAtPoint], etc. All I ever end up with is a 512x512 black square. How should I be doing this? I'm looking to CGLayer's, etc. seems there are a lot of options but none that work particularly easily.

让我居然把我的code的:

Let me actually put my code in:

CGSize size = CGSizeMake(512, 512);
UIGraphicsBeginImageContext(size);
UIGraphicsPushContext(UIGraphicsGetCurrentContext());
for (int i = 0; i < 4; i++)
{
    for (int j = 0; j < 4; j++)
    {
        UIImage *image = [self getImageAt:i:j];
        [image drawAtPoint:CGPointMake(i*128,j*128)];
    }
}
UIGraphicsPopContext();
UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageWriteToSavedPhotosAlbum(result, nil, nil, nil);

我要指出,其实上面的是的的东西在我的code究竟发生。真正的情况是,我打电话之前每一行与包括UIGraphicsPushContext,然后在动画计时器我慢慢递增图纸,绘制上下文。再经过这一切都做了以后我叫一切从UIGraphicsPopContext。

I should note that actually the above is not what happens in my code exactly. What really happens is that I call every line before and including to UIGraphicsPushContext, then in an animation timer I slowly increment the drawing and draw to the context. Then after it's all done I call everything from UIGraphicsPopContext onward.

推荐答案

要怎么做我想做的事...

To do exactly what I wanted to do...

请您GLView一样大,你想要的总的事情。另外,还要确保glOrtho和你的视口有合适的尺寸。然后,只需画任何你想要的,无论你想,并采取单一的OpenGL屏幕截图。然后,你不必担心结合起来,在多个OpenGL渲染一个传递的UIImage,这是毫无疑问的是什么导致了我的问题。

Make your GLView as big as the total thing you want. Also make sure glOrtho and your viewport have the right size. Then just draw whatever you want wherever you want, and take a single OpenGL screenshot. Then you don't need to worry about combining to a single UIImage over multiple OpenGL rendering passes, which is no doubt what was causing my issue.

这篇关于计算一个UIImage保存到相册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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