how to draw text on a image from a UITextView consist of multiple line string?

i want to get a multiple line string from a UITextView and draw it on a image, the position of text in the image must exactly same as the position in UITextView but i dont want jus add the textView to UIImageView, i need a new image consists of those text, is it possible? any suggestion to do that?

-------------Problems Reply------------

You can capture the contents of any UIView into a UIImage. First, create an empty UIView and position your UIImageView and UITextView as subviews:

// Assumes you have UIImageView *myImageView and UITextField *myTextField
UIView *parentView = [[UIView alloc] initWithFrame:CGRectZero];
[parentView addSubview:myImageView];
[myImageView setFrame:CGRectMake(0, 0, 100, 100)];
[parentView addSubview:myTextField];
[myTextField setFrame:CGRectMake(20, 20, 80, 20)];
[parentView sizeToFit];

Now create a graphics context and draw parentView into it:

UIGraphicsBeginImageContext([parentView bounds].size);
[[parentView layer] renderInContext:UIGraphicsGetCurrentContext()];
UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

You now have a UIImage with the contents of your UIImageView and UITextField to display, save, or send over the network.

This was a good solution, thanks.

I would like to add that you need to add

#import <QuartzCore/QuartzCore.h>

To your imports so the warnings go away.

Category:iphone Views:0 Time:2009-09-09

Related post

  • How do I draw text at an angle using python's PIL? 2008-10-29

    Using Python I want to be able to draw text at different angles using PIL. For example, imagine you were drawing the number around the face of a clock. The number 3 would appear as expected whereas 12 would we drawn rotated counter-clockwise 90 degre

  • Draw Text Over Video in Managed DirectX with C# 2008-12-24

    How can I draw text Over Video in Managed DirectX with C#? --------------Solutions------------- You need one more component, DirectShow.Net. Since you're referring to MDX, I assume you're still using MDX v1.1, as 2.0 Beta is discontinued and has expi

  • How do I draw text with GLUT / OpenGL in C++? 2009-02-11

    How do I draw a text string onto the screen using GLUT / OpenGL drawing functions? --------------Solutions------------- There are two ways to draw strings with GLUT glutStrokeString will draw text in 3D and glutBitmapString will draw text facing the

  • How do I use glutBitmapString() in C++ to draw text to the screen? 2009-02-12

    I'm attempting to draw text to the screen using GLUT in 2d. I want to use glutBitmapString(), can someone show me a simple example of what you have to do to setup and properly use this method in C++ so I can draw an arbitrary string at an (X,Y) posit

  • How do you draw text in a custom view using Objective-C? 2009-03-03

    I've figured out how to use the NSBezierPath class to draw shapes in the drawRect function of my custom view class, however I can't seem to figure out how to draw text. The following code is what I have so far for drawing the text (located in the dra

  • How do you draw text on a tag in Safari 2009-04-05

    I've been experimenting with using the <canvas> tag for drawing simple diagrams and charts, and so far it's pretty easy to work with. I have one issue thought. I can't figure out how to draw text on a <canvas> in Safari. In Firefox 3.0, I

  • draw text with GLUT / OpenGL in Python 2009-04-08

    Hey, I m drawing text with OpenGL in Python. It all works ok, however the font is really bad. If I make it thick the letters start to look very occurred (especially the ones which are round like 'o' or 'g'. For the purpose of my program it must be th

  • What is the best way to draw text on an HTML canvas element? 2009-04-27

    The canvas element unfortunately doesn't handle text well. There are a bunch of approaches (see e.g. http://canvaspaint.org/blog/2006/12/rendering-text/ ), but they mostly seem like hacks. What can I do that is cross-platform and gives me the most fl

  • How to draw text on picturebox? 2009-05-11

    I googled for "Drawing text on picturebox C#" ,but I couldnt find anything useful.Then I googled for "Drawing text on form C#" and I found some code,but it doesnt work the way I want it to work. private void DrawText() { Graphics grf = this.CreateGra

  • How do I draw text into a subview? 2009-05-31

    I want to draw text into UIView's subview using drawInRect:withFont:lineBreakMode call but that operates on the current context only. Is it possible to draw text into a subview from current view? The subview is a generic UIView instance and I don't r

  • What is the best way to draw text along with geometry? 2009-06-24

    In WPF, I'm starting to use classes such as LineGeometry, EllipseGeometry, GeometryGroup, Path... in order to draw 2D graphics. I chose these over shapes because I saw it could be faster thanks to the freezing feature. I need to draw text along with

  • How do I use GDI to draw text around a circular path? 2009-07-01

    I need to draw text onto a window HDC along a circular path using C/C++, and I'm getting google-eyed from searching for several hours. Can someone point me to a good reference? --------------Solutions------------- Text on Path (Code Project) it uses

  • iPhone: how to draw text in a window? 2009-07-12

    Strange situation - examples from apple works, but after i change them a bit, text is not displayed. This bit of code correctly draws blue background but refuses to draw text on it no matter what i do: #import <UIKit/UIKit.h> @interface CWnd :

  • How to Draw Text Vertically with Compact Framework 2009-07-21

    I need to draw text VERTICALLY directly on to a Windows Mobile Form. This is a Compact Framework 2.0 application. I have the following test code working in a windows form application, but it does not work with the compact framework because there is N

  • iPhone - How to draw text in the middle of a rect 2009-08-19

    Is there a method to draw text in the middle of a rectangle. I can find various alignments, but nothing I have tried can vertically centre the text in a rect. Is there a simple method to do this, or is there some way to centre a rectangle and then dr

  • Draw text in OpenGL ES (Android) 2009-08-27

    I'm currently developing a small OpenGL game for the Android platform and I wonder if there's an easy way to render text on top of the rendered frame (like a HUD with the player´s score etc). The text would need to use a custom font also. I've seen a

  • drawing text within a JPanel 2009-12-02

    I'm looking for the most basic description of how to draw text within a JPanel. I know there are a billion tutorials out there but none of them are clicking with me and I have some specific questions which may help others who are confused. As a setup

  • Drawing text on a framebuffer in Linux from C 2009-12-08

    How can a program draw text on a frame buffer mapped in as an array? What is needed is both a means of representing the individual characters, and of drawing the characters pixel by pixel in a manner that is not too inefficient. The representation of

  • WPF Draw Text on window 2010-01-05

    I found this link: http://msdn.microsoft.com/en-us/library/system.windows.media.formattedtext.aspx It is an example of how to draw text by overriding the OnRender method. I've overridden the OnRender method of the Window by using the following code,

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.172 (s). 11 q(s)