Computing a UIImage to be saved to the photo album

风流意气都作罢 提交于 2020-01-06 02:39:04

问题


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.

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);

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.


回答1:


Oh, then you can just save the onscreen view after it has been rendered on screen:

 UIGraphicsBeginImageContext(myBigView.bounds.size);
    [view drawRect:myBigView.bounds];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

are you storing it back to an image?

UIImage *myBigImage = UIGraphicsGetImageFromCurrentImageContext();



回答2:


To do exactly what I wanted to do...

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.



来源:https://stackoverflow.com/questions/1488484/computing-a-uiimage-to-be-saved-to-the-photo-album

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!