• 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
Questions about NSBitmapImageRep
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Questions about NSBitmapImageRep


  • Subject: Questions about NSBitmapImageRep
  • From: j o a r <email@hidden>
  • Date: Sat, 22 Sep 2001 18:52:41 -0700

Hello,

A couple of questions:

1) Why does initWithFocusedViewRect: (NSBitmapImageRep) and dataWithPDFInsideRect: (NSView) produce very much different images?

2) Why can I grab a bitmap representation of a view using dataWithPDFInsideRect:, but not a window? NSWindow has that method too.

3) Why do you lock / unlock views at all? I don't have any background on that and any pointers to documentation on the concepts would be great. The docks tells you when you should use them, and where in the code, but not why...

On to my problems:

//*********************************************************************
// This works fine:
//*********************************************************************
// Grab the content view of a window as an image
NSImage *contentViewImage = [[NSImage alloc] initWithData:[[myStartWindow contentView] dataWithPDFInsideRect:[[myStartWindow contentView] bounds]]];

// Create a bitmap representation from that image
NSBitmapImageRep *myBMIR = [NSBitmapImageRep imageRepWithData:[contentViewImage TIFFRepresentation]];

// Testing the bitmap representation
2001-09-22 18:24:19.055 TestApp[1883] bitsPerPixel: 32
2001-09-22 18:24:19.055 TestApp[1883] bytesPerRow: 1024
2001-09-22 18:24:19.055 TestApp[1883] samplesPerPixel: 4
2001-09-22 18:24:19.055 TestApp[1883] bitsPerSample: 8
2001-09-22 18:24:19.055 TestApp[1883] bytesPerPlane: 262144
2001-09-22 18:24:19.056 TestApp[1883] isPlanar: 0
2001-09-22 18:24:19.056 TestApp[1883] pixelsWide: 256
2001-09-22 18:24:19.056 TestApp[1883] pixelsHigh: 256
2001-09-22 18:24:19.153 TestApp[1883] length: 262338


//*********************************************************************
// This doesn't work as good
// (I get a EXC_BAD_ACCESS on CGImageGetWidth later in my code)
// If you look at the bitmap image representation you see that it's a completely
// different kind of image. I wonder why.
//*********************************************************************

NSBitmapImageRep *myBMIR;
[[myStartWindow contentView] lockFocus];
myBMIR = [[NSBitmapImageRep alloc] initWithFocusedViewRect:[[myStartWindow contentView] bounds]];
[[myStartWindow contentView] unlockFocus];

// Testing the bitmap representation
2001-09-22 18:26:32.804 TestApp[1923] bitsPerPixel: 24
2001-09-22 18:26:32.820 TestApp[1923] bytesPerRow: 768
2001-09-22 18:26:32.845 TestApp[1923] samplesPerPixel: 3
2001-09-22 18:26:32.879 TestApp[1923] bitsPerSample: 8
2001-09-22 18:26:32.912 TestApp[1923] bytesPerPlane: 196608
2001-09-22 18:26:32.932 TestApp[1923] isPlanar: 0
2001-09-22 18:26:32.943 TestApp[1923] pixelsWide: 256
2001-09-22 18:26:32.944 TestApp[1923] pixelsHigh: 256
2001-09-22 18:26:32.990 TestApp[1923] length: 196788


//*********************************************************************
// And I would really like to get this working
// It doesn't crash, and does indeed generate a bitmap image rep - as the print out shows
// but the when I display the image itself it's blank (or striped really). It's like it doesn't capture
// the views contained in the window
//*********************************************************************
// Grab the content view of a window as an image
NSImage *windowImage = [[NSImage alloc] initWithData:[myStartWindow dataWithPDFInsideRect:[myStartWindow frame]]];

// Create a bitmap representation from that image
NSBitmapImageRep *myBMIR = [NSBitmapImageRep imageRepWithData:[windowImage TIFFRepresentation]];

// Testing the bitmap representation
2001-09-22 18:32:49.565 TestApp[1967] bitsPerPixel: 32
2001-09-22 18:32:49.565 TestApp[1967] bytesPerRow: 1024
2001-09-22 18:32:49.580 TestApp[1967] samplesPerPixel: 4
2001-09-22 18:32:49.581 TestApp[1967] bitsPerSample: 8
2001-09-22 18:32:49.581 TestApp[1967] bytesPerPlane: 284672
2001-09-22 18:32:49.622 TestApp[1967] isPlanar: 0
2001-09-22 18:32:49.622 TestApp[1967] pixelsWide: 256
2001-09-22 18:32:49.623 TestApp[1967] pixelsHigh: 278
2001-09-22 18:32:49.653 TestApp[1967] length: 284866

j o a r


  • Follow-Ups:
    • Questions about NSBitmapImageRep [Follow Up]
      • From: j o a r <email@hidden>
  • Prev by Date: Re: NSDate & NSCalendarDate
  • Next by Date: Questions about NSBitmapImageRep [Follow Up]
  • Previous by thread: Re: NSDate & NSCalendarDate
  • Next by thread: Questions about NSBitmapImageRep [Follow Up]
  • Index(es):
    • Date
    • Thread