Generate document thumbnails - iphone

I am trying to display a grid of documents (saved in the documents directory) but I don't know how to generate the thumbnails for the documents. The documents can be anything that a QLPreviewController can display. PDF's and Images are fine to do but other things like .doc's I don't know about. Any guidance would help.

Since you have an UIView that can display any of this documents you could just take a shortcut:
-Create an instance of your preview controller with displayed document
-Do not add this view/controller to anything
-Create image from its layer
This might help:
+ (UIImage *)imageFromView:(UIView *)view {
CALayer *layer = view.layer;
UIGraphicsBeginImageContext([layer frame].size);
[layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return outputImage;
}
Play around a bit with layers and initialization as I didn't test the code..

The better option of you can use a uiwebview in which you can just load the file giving the filepath. Then take the screen shot by using the code given above by Matic Oblak and you are done.

Related

Generate a pdf from opengles context in iphone/ipad

Hi am a noob at PDF generation and currently am displaying a 3d bar charts in my application in glview which is in side a uiview. Now i want to generate a PDF document from the uiview which contains a text view and a glview. Am able to generate a PDF from text but where as GL View am unable to proceed.even i tried for a possibility over the net but unable to get any info regarding this.Can someone help me by providing the solution whether this can be possible or not.Thanks in Advance
You can ask any UIView to give you an image (which might be a start) via something like:
- (UIImage *) imageRepresentation {
// render myself (or more correctly, my layer) to an image
UIGraphicsBeginImageContext(self.bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetShouldSmoothFonts(context, false);
CGContextSetShouldAntialias(context, false);
[self drawLayer:self.layer inContext:context];
[self.layer renderInContext:context];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
After that, you might be able to get a PDF representation of it, or investigate calls like CGPDFDocumentCreateWithURL to construct one yourself from the image.
You can use CoreGraphic's PDF-APIs to creating and drawing to a PDF.
See Apple's guide for more details.

ios dropbox, loading thumbnail of image in table view

I have picture in my dropbox, which i need to show in Uitable view. I am able to show the picture by name, using metadata filemetadata, and when i click on any of cell i am successfully able to view the image in image view, by using the call to loadthumbnail.
But now, I want to show the thumbnail of image together with, image name, so that user have idea of image before opening it.
So, what is the simple way of doing it.
You should resize (thumb) the original UIImage's prior to showing the UITableView and save them in your app cache folder.
Something like this (out the top of my head)
CGSize targetSize = (CGSize){ 100, 80 };
UIGraphicsBeginImageContext(targetSize);
CGRect thumbnailRect = (CGRect){ 0, 0, targetSize.width, targetSize.height };
[sourceImage drawInRect:thumbnailRect];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// After this you should store the UIImage (NSData) as a file, so you could use it later on.
Try to go to the Start Menu then look for My Documents and look for a folder named Downloads. This worked for me on a download i could not see.
Good Luck!

How to get iphone device screenshot when image animation is run on main thread?

I am perfoming image sequences animation is on main thread.
At the same time i want to take snapshot of device screen in back ground.
And by using that snapshots i want make video..
Thanks,
Keyur Prajapati
For taking the screenshots while running the image animations
use
[self.view.layer.presentationLayer renderInContext:UIGraphicsGetCurrentContext()];
instead of
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
it will take screenshots while runing animations
iOS uses Core Animation as the rendering system. Each UIView is backed by a CALayer. Each visible layer tree is backed by a presentation tree. The layer tree contains the object model values for each layer, i.e., values you set when you assign a value to a layer property (A and B). The presentation tree contains the values that are currently being presented to the user as an animation takes place (interpolated values between A and B).
If you're doing it in CoreAnimation you can render the layer contents into a bitmap using -renderInContext:. Have a look at Matt Longs Tutorial. It's for Objective-C on the Mac, but it can be easily converted for use on the iPhone.
Create one another thread where you can do this:
//Create rect portion for image if full screen then 320X480
CGRect contextRect = CGRectMake(0, 0, 320, 480);
// this is whate you need
UIGraphicsBeginImageContext(contextRect.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage* viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
viewImage is the image which you needed.
You can write this code in function which can be called timely bases like per 5 seconds or according to your requirements.
Hope this is what you needed.

Adding picture frame to a photo

I am making an app that adds a picture frame to a photo.I would like to know how to have my Save button save both Images (the photo, and the frame) as one Image.Right now it only saves one of the images.
In interface builder I have the save action saving the image that is loaded into an ImageView, with the frame ImageView overlaying that image.
I'd like to merge the two photos as one, so the save action can save the image with the frame.
Thanks!
In this may need to use the masking in the iphone where the unnecessary thing of the image is automatically remove and attach with the frame.
I think this help to implement best for the your applications
So you can refer the following link for Download and tutorial and Source also.
Reference link
You need to do some drawing using Core Graphics. This code should do what you want, possibly with some tweaks to the rectangles/sizes:
UIGraphicsBeginImageContext(image.size);
[image drawRect:CGRectMake(0, 0, image.size.width, image.size.height);
[frameImage drawRect:CGRectMake(0, 0, image.size.width, image.size.height);
UIImage *result = UIGraphicsGetImageFromCurrentImageContext();

Copying the bitmap contents of a UIView's context to that of another UIView

Basically what I want to do is copy the already rendered content (a PDF drawn into the UIView's graphics context using CGContextDrawPDFPage()) onto a similar UIView, without having to re render the PDF. The idea is, that I'd then be able to perform an animated transform on the UIView and later re render the PDF with more accuracy. For both UIViews I'm using a larger-than-screen CATiledLayer to make it easier to rerender the PDF once the user zooms in, if that makes any difference.
Any tips? I'm kind of lost here.
Assuming you have rendered a PDF page in a graphics context using code similar to the following
CGPDFDocumentRef document = CGPDFDocumentCreateWithURL (filename_url);
CGPDFPageRef page = CGPDFDocumentGetPage (document, pageNumber);
CGContextDrawPDFPage (context, page);
CGPDFDocumentRelease (document);
This code will save the contents of pdfView to a UIImage
UIGraphicsBeginImageContext(pdfView.bounds.size);
[pdfView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *pdfViewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();