Generating an image using Cocoa - ios

My iOS app needs to be able to generate an image to post to Facebook and Twitter. The image will be a representation of data added by the user. The image is not a direct representation of any view that will be displayed on screen. It is not necessary to include any other image resources in the image created - for the most part I need to format the style and layout some text, and maybe add some borders, lines, etc - but I would like the ability to add this later if it is simple.
What approach is best for something like this? Should I build a UIView and output it to a file somehow? Is there an HTML/CSS solution? Or some other approach?
Bonus points if you can recommend the file format and attributes optimized for posting to Facebook/Twitter.

Use UIGraphicsBeginImageContextWithOptions() to create a new image context.
Then, draw whatever you like into it using Core Graphics. You can draw text using Core Graphics or Core Text — the former is easier, but the latter gives you more opportunity for customisation.
Then, get a UIImage out of your context by using UIGraphicsGetImageFromCurrentImageContext().
You can then convert the UIImage into a PNG using UIImagePNGRepresentation().

Related

Export text and image in the same file

What I want to do is exporting some data from my app to a text file - say an RTF file. I found that converting text can be done through this classes, but is there a way to save an image also?
If you want to export text + images in the same document you can do it usig Core Graphics. Please search for CGPDFDocument Reference and Quartz 2D Programming Guide in Apple documentation.
However in order to do this you need to have an understanding of the PDF format and you should read the Adobe guide PDF Reference, Fourth Edition, Version 1.5
Using CGPDFContext you can create a UIView, draw your contents into it (using sub views to make life easy for text and images) and then render the views layer into the PDF context. Then save the resulting data to a file.

Create a ttf file on iOS

I want to create a simple ttf font within an iphone/ipad app. The concept is that the user will draw each letter and I will create a collection to build the ttf file.
Initially, I thought I would have to export the images from the app to a font editor such as fontforge on a server, but I am now convinced that it is possible to generate a ttf file on the device.
Here is what I think needs to happen:
1) Enable the drawing using OpenGL
2) Save the images. Is this in a vector format or as bitmap?
3) Organize the collection as a ttf file
Can someone point me in a successful direction?
1) Enable the drawing using OpenGL
And herein lies your first misconception. OpenGL is best thought as a one way device. You put drawing commands into it, and it produces a nice picture on the screen. But OpenGL is neither a geometry nor a math library.
2) Save the images
For the creation of a TTF the raw data you send to OpenGL is much more useful, than anything you could read back from OpenGL.
In particular you'll have a list of strokes, which you could convert into an outline, that then can be converted into a glyph.

What is the easiest way to create complex PDF in iOS?

I am trying to generate some complex invoice data in PDF format. I know two Technique:-
By converting Data into HTML data via UIWebView and generate its PDF accordingly. But it is having issue of showing data Blur or unreadable if Zoom, when data is long in size. Cause it actually first create Image from HTML data and generate pdf.
Using QuartzCore technique mentioned in Ray-Wenderlich tutorial:-
http://www.raywenderlich.com/6818/how-to-create-a-pdf-with-quartz-2d-in-ios-5-tutorial-part-2
Is there any way other then these above two? Also is it possible in the First technique to get data in UIWebView as vector based so that when it zoom it will not blur the data?
Thanks in Advance,
Vivek
Use the Quartz 2D framework as described in the tutorial. You don't want to create a pixel image from the html because it does not scale and can get large.
You can use a tableview with multi sections to create your invoice and convert it to an image(uiview----> image) and After that print that image to pdf (image--->pdf).

CGPathRef and PDF

It there a way to draw a complex shape with an application like CorelDraw or Adobe Flash, etc, save it or export it as a PDF and then open it with Core Graphics in iOS.
The idea is, to draw a shape, a vector, with CorelDraw - for example, and it is just the path. No color or fill. And then be able to open it directly by Core Graphics, add it as a CGPath to the context, and then be able to manipulate it, like fill it with solid color or gradient, or patterns.
The bottom line is, I am looking for a way to draw a complex shape in a user-friendly environment, like Corel or Flash, and export it, as a vactor, which can be manipulated in Core Graphics. And suggestions or help is really appreicated.
Thanks.
SVGKit doesn't work the exact same as I need either. Although I should say it is nicely done. There are also other resources, that I found and I'll leave them here for future references, if anyone stops by this post and is looking for a solution.
Converting SVG Paths to Objective-C Paths Good for simple paths; strokes and fills can be manipulated later by using protocols. Complex paths get mixed up.
SVGKit Good for creating images and animate them later through the course of the program. However, strokes, fills, paths can not be manipulated.
Opacity You can export as source code, hence you have more control over strokes, paths, and fills. As the path gets more complex, it is harder to manage the code manually. The other problem is by the time of export, the program adds resolution-dependent codes. It can be a pain to go through about 300+ lines of code to fix it so that it is not resolution dependent. By the final product wouldn't be mixed up, and can be manipulated by protocols. Layers are CGLayers, not CALayers.
If, as you say, you've got PDF files (from Corel, or another app), you can display them using CoreGraphics.
Take a look at the:
CGPDFDocument class
CGPDFPage class
Then, there is a CGContextDrawPDFPage function, that you can use to draw a PDF pages in a given graphic context, typically in the drawLayer: inContext: method of a UIView subclass.
There isn't really a built-in way to load CGPaths from files but you might want to take a look at SVGKit. Pretty much every modern vector drawing app can produce SVG files.

Where can I find an image watermark control for Delphi?

Is there a good image watermark control for Delphi? It would be nice if it could receive both text and images to insert in a base photo.
I would also prefer it was free.
I couldn't find any pre-packaged controls. But watermarking is not very hard at all. All you simply need to do is draw an image on top of another image with the use of alpha blending. This site has a whole section on alpha blending in Delphi. They provide links to graphics libraries which have implemented it.
However if you're using Delphi.NET, and can access the relevant classes in the framework, there is an easier way using only framework methods.
Take a look at Graphics32 together with GraphicEX.
Or see if PascalMagick does the trick.

Resources