I am working on an application whose job is to build an image(jpeg) that is a collage of selected images from gallery. I can crop the gallery images to needed size using the technique specified in the question here.
However, I want to create a collage that is 2400×1600 (configurable) pixels and arrange cropped images on white background.
I couldn’t find a right example to create a canvas and set its background color. I believe I need to create a core graphics context, create a canvas, set background to white, save as image and work on that image object. However am not able to find the right way to do it. Appreciate any help.
Edit:
Found this code to save view to image. Now the problem is reduced to creating a view that has a canvas of 2400×1600.
-(UIImage*) makeImage {
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return viewImage;
}
You should look up the methods in your example code.
self.view.bounds.sizeis a CGSize, so if you replace the call toUIGraphicsBeginImageContextwith the following, it’ll get you an image of the size you want:Good luck!