Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-24-2011, 06:29 PM   #1 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 3
S. Mas is on a distinguished road
Default JPEG to pdf leaks (whereas PNG does not)

Good evening everybody,

I'm new to this forum and I'm trying to develop an application generating a PDF file from photo taken by the user. My problem is that when I draw a JPEG image in the PDF context, it works, but leaks, which does not if I use a PNG Image.

For sample, the following call leaks :

Code:
UIImage * destImage = [UIImage imageNamed:@"Image.JPG"];
[destImage drawInRect:drawingFrame];
whereas this one does not :
Code:
UIImage * destImage = [UIImage imageNamed:@"Image.png"];
[destImage drawInRect:drawingFrame];
I don't undestand ???

Thanks in advance
S. Mas is offline   Reply With Quote
Old 03-24-2011, 08:04 PM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,990
BrianSlick has a spectacular aura about
Default

How are you determining that it leaks?

Post the complete code from that method.
__________________
BriTer Ideas LLC - Professional iOS App Development. Available for hire.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
Definitive Guide To Properties | UITableView Series | Guide To Troubleshooting | Model Object Overview

Do you sit at a desk all day? Walk instead! Follow along with my treadmill desk adventures.
BrianSlick is offline   Reply With Quote
Old 03-25-2011, 02:21 PM   #3 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 3
S. Mas is on a distinguished road
Default

Good evening,

I use the Leaks instrument to identify the leak.

Here is a small test method which shows the problem.
Even if in both cases (JPG/PNG), the pdf file is correctly generated with the image in it, the leak only appears with the JPG version.


Code:
- (IBAction) run{

	// Using local pool for autorelease objects
	NSAutoreleasePool * localpool = [[NSAutoreleasePool alloc] init];
	
	// Creating the file path
	NSArray *documentsPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString * pdfFilePath = [[documentsPaths objectAtIndex:0] stringByAppendingPathComponent:@"MyFile.pdf"];
		
	// Creating PDF File and context
	UIGraphicsBeginPDFContextToFile(pdfFilePath, CGRectZero, nil);
		
	// New page
	CGRect pageRect = CGRectMake(0, 0, 612, 792);
	UIGraphicsBeginPDFPageWithInfo(pageRect, nil);
	
	// Image choice
	
	// JPEG -> Leak (Responsible caller : GImageReadCreateDataWithMappedFile)
	UIImage * destImage = [UIImage imageNamed:@"Image.jpg"];
	
	// PNG -> No leak
	//UIImage * destImage = [UIImage imageNamed:@"Image.png"];
	
	// Image drawing
	CGFloat width = 200;
	CGFloat height = 200 * destImage.size.height / destImage.size.width;
	CGRect drawingFrame = CGRectMake(10, 10, width, height);
	[destImage drawInRect:drawingFrame];
	
	
	// PDF Context closing / File writing
	UIGraphicsEndPDFContext();
	
	// Releasing local pool
	[localpool release];
	
}
S. Mas is offline   Reply With Quote
Old 03-29-2011, 04:01 AM   #4 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 3
2five7 is on a distinguished road
Talking Creating an image file from a PDF file with desired page number

Creates UIImage file from a PDF page of a PDF document & stores the image in the iPad Library.-

Code:
-(IBAction)pdf2image
{	
	// m_webView is a UIWebView
	UIGraphicsBeginImageContext(m_webView.frame.size); 
	CGContextRef context = UIGraphicsGetCurrentContext();
	CGContextTranslateCTM(context, 0.0, m_webView.frame.size.height);
	CGContextScaleCTM(context, 1.0, -1.0);

	// The file DemoPDF.pdf is in the Resource Folder of the Project
	CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("DemoPDF.pdf"), NULL, NULL); 
	CGPDFDocumentRef document = CGPDFDocumentCreateWithURL(pdfURL);

	// m_pnTf is the UITextField which is used to enter the desired page number
	int pageNumber = [m_pnTf.text intValue]; 
	CGPDFPageRef pdfPage = CGPDFDocumentGetPage(document, pageNumber);
	CGContextDrawPDFPage(context, pdfPage);
	UIImage *img = UIGraphicsGetImageFromCurrentImageContext();

	// The final image is saved in the iPad Library
	UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil); 
}

Last edited by 2five7; 03-29-2011 at 04:08 AM.
2five7 is offline   Reply With Quote
Old 04-27-2011, 03:23 PM   #5 (permalink)
Registered Member
 
Join Date: Mar 2011
Posts: 3
S. Mas is on a distinguished road
Default

What about image2pdf ?
S. Mas is offline   Reply With Quote
Reply

Bookmarks

Tags
context, jpeg, jpg, leak, pdf

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 370
12 members and 358 guests
condor304, dansparrow, Domele, dre, dreamdash3, ilmman, LezB44, michelle, Sami Gh, shagor012, thephotographer, tinamm64
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,119
Posts: 402,896
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:35 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0