How to create large images in UIImageView?

I am currently developing a postcard application. However, I am wondering how to save the image plus the frame (I have three frames depending on the resolution) and some text in a UITextView (transparent background).

I need to keep the original resolution of the photo, even if the frame or screen does not allow using more than 320 by 480 pixels (2: 3) and insert a frame and then text. I don't really like the text if I can save the image in a frame.

All I need is advice on how to approach this problem: I need framework classes and, possibly, hints on methods (functions, messages) that I can use either to work the image as a bitmap or as jpeg or png.

Unable to execute:

  • The idea of ​​the project manager: send it to the web page of the converter (I can’t remember the http address), in which God knows what format and God knows how to specify the web page to combine all types, and then wait until it returns to phone and save it. Creating a POST card should be done locally if iPad users want to create them and then save them to a PC or something like that (personally, I would like to exhaust all the resources from the iPhone development infrastructure that I can offer).

  • Get the current context that unites all three classes / subclasses of UIViews. Great for 320 by 480, but not for high resolutions.


Yes, thank you very much for your answer - this is my approach. I thought there was a better way to process image and text as raster data, raw data, or something else to better preserve the original information.

But I still have one small problem that makes me a little bit difficult: the image (inside the frame) should be selected from the image library or the camera controller, but hey, it brings you one object (the image size fits the screen) and a dictionary that surprisingly brings source image too. Now there are two objects. But the card must be generated in 4 different resolutions and bringing the four "versions" of the image will create huge memory overhead.

How can i avoid this? Should I use the link to the following vocabulary elements to remove them from memory, create a postcard, send it over the network and then destroy it?

NSString *const UIImagePickerControllerMediaURL; NSString *const UIImagePickerControllerReferenceURL; 

in an obj-c object, objects pointing to the source information ... I just want to reduce overhead by allocating and deallocating if necessary.

+4
source share
1 answer

You need to draw your postcard in a new image in mind. The easiest way to create a new image is with the UIGraphicsBeginImageContext() function. Then you can use UIKit drawing methods to render the background image, text, etc. Into a new image and get the resulting image using UIGraphicsGetImageFromCurrentImageContext() . Depending on your needs, you can also create JPEG / PNG from the resulting image and burn it to disk using UIImageJPEGRepresentation() .

Here is an example:

 UIImage *backgroundImage = [UIImage imageNamed:@"MyPostcardBackground.jpg"]; CGRect frameRect = CGRectMake(0, 0, backgroundImage.size.width, backgroundImage.size.height); UIGraphicsBeginImageContext(backgroundImage.size); [backgroundImage drawInRect:frameRect]; NSString *text = @"Caption here..."; [[UIColor whiteColor] set]; [text drawInRect:frameRect withFont:[UIFont boldSystemFontOfSize:35.0] lineBreakMode:UILineBreakModeWordWrap]; //... UIImage *postcardImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); 
+1
source

Source: https://habr.com/ru/post/1334395/


All Articles