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%16)%16;                
>       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 (Cocoa-dev@lists.apple.com)
> 
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/development%40fornextsoft.com
> 
> This email sent to developm...@fornextsoft.com

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to