Monotouch: Combine 4 images into 1 (UIImage)
I have 4 UIImages (A,B,C,D), each the same 500x500
How can I combine them into a grid 1000x1000 like this:
AB
CD
So开发者_运维技巧 that the I have a single UIImage "E"
You have to create a new image context with the size of the final image:
UIGraphics.BeginImageContext(new SizeF(1000, 1000));
Then, draw each image in the appropriate rectangle:
image.Draw(new RectangleF(0,0,image.Size.Width,image.Size.Height));
//image2.Draw...
You then get the image:
UIImage finalImage = UIGraphics.GetImageFromCurrentImageContext();
And finally, you must end the image context:
UIGraphics.EndImageContext();
I don't specifically know how but I do know that Apple's PhotoScroller sample code might help? It's a pretty cool trick they have that might work for yours too. Let me know.
Remember that you can't use UIGrahpics.BeginImageContext() in a sub-thread, it has to be the main thread. If you want to do it in a sub-thread you have to use CGBitmapContext(), which is a little harder to deal with.
精彩评论