• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Off Screen bitmap drawing [iPhone]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Off Screen bitmap drawing [iPhone]


  • Subject: Re: Off Screen bitmap drawing [iPhone]
  • From: Development <email@hidden>
  • Date: Mon, 31 May 2010 11:17:19 -0700

Wow I'm sorry I should have mentioned I'm doing this on iPhone


On May 31, 2010, at 11:11 AM, Development wrote:

> Ok... I'm really new to coregraphics and i've run in to a problem i cant seem to figure out.
> I'm trying to take page data from a pdf and draw a thumbnail size preview... I'm first drawing this to a UIView, then creating CGImageRef from that and finally converting it to a UIImage.
>
> What I get is a black rectangle of scrambled colors and no discernible resemblance to the page data.
>
> 	self.backgroundColor = [UIColor whiteColor];
> 	float scale=1.0;
>
> 	CGRect pageRect = CGPDFPageGetBoxRect(thePage,0);
>
> 	if (pageRect.size.width > pageRect.size.height) {
>
> 		scale = self.imgSize/pageRect.size.width;
> 	}
>
> 	else {
> 		scale = self.imgSize/pageRect.size.height;
> 	}
>
>
> 	CGRect myBounds = self.bounds;
>
> 	myBounds.size.width =pageRect.size.width *scale;
> 	myBounds.size.height = pageRect.size.height *scale;
>
> 	self.bounds = myBounds;
>
> 	int bytesPerRow = myBounds.size.width*4;
> 	bytesPerRow += (16 - bytesPerRow);
> 	size_t byteSize = bytesPerRow * myBounds.size.height;
> 	void * bitmapData = malloc(byteSize); ag
>
>
> 	CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
>
> 	CGContextRef context = CGBitmapContextCreate(bitmapData,myBounds.size.width,myBounds.size.height,8,bytesPerRow,colorSpace,kCGImageAlphaNoneSkipFirst | kCGBitmapByteOrder32Little/*kCGImageAlphaPremultipliedFirst*/);
>
> 	CGContextTranslateCTM(context, 0.0, self.bounds.size.height);
> 	CGContextScaleCTM(context, 1.0, -1.0);
> 	CGContextSetPatternPhase(context, CGSizeMake(0,myBounds.size.height));
>
> 	CGAffineTransform pdfTransform = CGPDFPageGetDrawingTransform(thePage, kCGPDFCropBox, myBounds, 0, true);
> 	CGContextConcatCTM(context, pdfTransform);
> 	CGContextDrawPDFPage(context, thePage);
>
> 	CGImageRef testImage = CGBitmapContextCreateImage(context);
> 	thumb = [[UIImageView alloc]initWithImage:[UIImage imageWithCGImage:testImage]];
>
> 	CGColorSpaceRelease(colorSpace);_______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Off Screen bitmap drawing (From: Development <email@hidden>)

  • Prev by Date: Re: UIView retain past drawing?
  • Next by Date: Re: dynamic resolution
  • Previous by thread: Off Screen bitmap drawing
  • Next by thread: Re: Off Screen bitmap drawing
  • Index(es):
    • Date
    • Thread