2

I need to create something like: http://t3.gstatic.com/images?q=tbn:ANd9GcQZu06WspVUaFTn-C-YD6Pzu_oWH5NLA1Q8nPUZEdemllFIAMNn

So I need to place a user input string over an image in a specified spot, then save it in the memory.

How can I do it?

Cajunluke
  • 3,103
  • 28
  • 28
Cla
  • 1,810
  • 3
  • 22
  • 36

3 Answers3

2
  1. Create a new bitmap image context. See this for help creating-and-drawing-on-a-new-uiimage
  2. Draw your UIImage in drawInRect
  3. Create black, rounded and transparent image. See this for help: resize-a-uiimage-the-right-way
  4. Draw black image drawInRect
  5. Draw your NSString text. see this for help how-to-display-text-using-quartz-on-the-iphone drawInRect or drawInPoint
Community
  • 1
  • 1
D.Enchev
  • 116
  • 1
  • 5
  • Tnx for the tips, but sorry I've not understood. Can you help me telling me how to crop (taking just an area) of an UIImage? – Cla Apr 05 '11 at 08:25
1

Here is a small code example for cropping an image.

- (UIImage *)croppedImageWithRect:(CGRect)bounds {
    CGImageRef imageRef = CGImageCreateWithImageInRect(scaleImage.CGImage, bounds);
    UIImage *croppedImage = [UIImage imageWithCGImage:imageRef];
    CGImageRelease(imageRef);
    return croppedImage;
}

Enjoy.

Besi
  • 22,579
  • 24
  • 131
  • 223
Rahul
  • 951
  • 3
  • 10
  • 16
0

use a UItextView over an image to show such string.

saadnib
  • 11,145
  • 2
  • 33
  • 54
  • And to save it, I'd make a screenshot out of it. `UIGraphicsBeginImageContext(view.size); CGContextRef ctx = UIGraphicsGetCurrentContext(); CGRect area = CGRectMake(0, 0, view.size.width, view.size.height); CGContextDrawImage(ctx, area, view.layer.CGImage); UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); ` I'm unsure if the code is correct, but it's about the idea ;) – Joetjah Apr 04 '11 at 12:34
  • I've do I've taken the code of the first reply and fixed a bit, but it take the screenshot, move it upside down, and scale to fit the size I've give. It should crop. CGSize quoteSize = CGSizeMake(320, 320); UIGraphicsBeginImageContext(quoteSize); CGContextRef ctx = UIGraphicsGetCurrentContext(); CGRect area = CGRectMake(0, 0, quoteSize.width, quoteSize.height); UIGraphicsBeginImageContext(self.view.bounds.size); [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); (continue) – Cla Apr 04 '11 at 19:57
  • (part 2) CGContextDrawImage(ctx, area, screenShot.CGImage); UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); // Save image to photos UIImageWriteToSavedPhotosAlbum(newImage, self, nil, nil); Do you know what the problem is? – Cla Apr 04 '11 at 19:59
  • Found! Use that code to crop: `CGImageRef imageRef = CGImageCreateWithImageInRect([screenShot CGImage], area); UIImage *croppedImage = [UIImage imageWithCGImage:imageRef]; CGImageRelease(imageRef);` – Cla Apr 05 '11 at 08:45