• 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: Weird Problem With CGImage
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Weird Problem With CGImage


  • Subject: Re: Weird Problem With CGImage
  • From: Jean-Daniel Dupas <email@hidden>
  • Date: Fri, 25 Apr 2008 17:57:15 +0200


Using CGImageRef is not a realiable way to access pixel data of an image.
You should create a CGBitmapContextCreate() instead and draw the part you want in this context.


http://developer.apple.com/qa/qa2007/qa1509.html




Le 25 avr. 08 à 16:51, Carter R. Harrison a écrit :

This bug in my code has been driving me nuts for days, but I have finally isolated the issue - only problem now is I don't understand what I'm doing wrong.

I have a CGImage that I want to get the raw data bytes for. My code is below:

CGImageRef sectionToCache = CGImageCreateWithImageInRect(backingStore, CGRectMake(x, y, cx, cy));
NSLog(@"CGImage to cache has dimensions %d x %d and %d bytes per row", CGImageGetWidth(sectionToCache), CGImageGetHeight(sectionToCache), CGImageGetBytesPerRow(sectionToCache));
CFDataRef dataRef = CGDataProviderCopyData(CGImageGetDataProvider(sectionToCache));
NSLog(@"Length of cachedImage data: %d", CFDataGetLength(dataRef));


When the code runs, the log spits out the following:

CGImage to cache has dimensions 417 x 234 and 1668 bytes per row
Length of cachedImage data: 6672

What is killing me here is that the CGImage has dimensions 417x234 and 1668 bytes per row. That to me means that the CFDataRef that I am obtaining should be 390,312 bytes (234 x 1668). But the CFDataRef is only 6,672 bytes which is nowhere close to what I think I should be getting. So I must be doing something wrong in trying to get the bitmap data, but I'm not sure what else to do and I even found some Apple docs with an example doing the exact same thing that I am doing. Can anybody provide some insight on this? Thanks everybody.
_______________________________________________


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


  • Follow-Ups:
    • Re: Weird Problem With CGImage
      • From: "Adam R. Maxwell" <email@hidden>
References: 
 >Weird Problem With CGImage (From: "Carter R. Harrison" <email@hidden>)

  • Prev by Date: Re: Core Animation Flickering
  • Next by Date: Re: One pixel width. One.
  • Previous by thread: Weird Problem With CGImage
  • Next by thread: Re: Weird Problem With CGImage
  • Index(es):
    • Date
    • Thread