• 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: Rasterizing an NSString to a bitmap
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rasterizing an NSString to a bitmap


  • Subject: Re: Rasterizing an NSString to a bitmap
  • From: Dietmar Planitzer <email@hidden>
  • Date: Fri, 11 Jun 2004 20:33:31 +0200

On Jun 10, 2004, at 9:03 PM, p3consulting wrote:


Regarding the solution of Dietmar accessing the PixMapHandle, I have
done some testing and got strange result:
the PixBaseAddr is NOT the top-left pixel of the NSImage but the top
left pixel of the shared offscreen window
(using setCachedSeparately:YES doesn't guarantee a separate buffer)
this should not be a problem if the rectangle returned by GetPixBounds
was correct but it's not:
it's always at (top,left) = (0,0) ????
So I supposed there is something to do with the enclosing CGrafPtr
port's origin but for
an 512 x 512 offscreen I got port bounds = (0,0,512,512)
and rowbytes = 5120 !!! which is the size of my screen (1280 pixels x 4
bytes per pixel)
and trying to flood fill the image results in flood filling the menu
bar (nice effect but not what was expected !)
which obviously means pixBaseAddr was the base address of the screen
Any idea ????


Yep, my original code is indeed buggy. The correct way to access the window back buffer is this:

CGrafPtr grafPort = GetWindowPort([myWindow windowRef]);
PixMapHandle pixMapHnd;
long pixelType, bytesPerRow;
Rect pixMapBounds;
int width, height;
void * pixels;

LockPortBits(grafPort);
pixMapHnd = GetPortPixMap(grafPort);
pixelType = GetPixDepth(pixMapHnd);
GetPixBounds(pixMapHnd, &pixMapBounds);
width = pixMapBounds.right - pixMapBounds.left;
height = pixMapBbounds.bottom - pixMapBounds.top;

LockPixels(pixMapHnd);
pixels = GetPixBaseAddr(pixMapHnd);
bytesPerRow = GetPixRowBytes(pixMapHnd);

// Do something with pixels

UnlockPixels(pixMapHnd);
UnlockPortBits(grafPort);

The important point here is that it is necessary to call LockPortBits() before you can access the window back buffer. Otherwise you'll end up accessing the window front buffer aka screen aka framebuffer.

I've confirmed that it works at least with a Carbon window which I use as an offscreen window. Should work just as well with Cocoa windows because under the hood both Carbon and Cocoa windows are built on top of CoreGraphics windows.


Regards,

Dietmar Planitzer
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >Rasterizing an NSString to a bitmap (From: John Stiles <email@hidden>)
 >Re: Rasterizing an NSString to a bitmap (From: Marcel Weiher <email@hidden>)
 >Re: Rasterizing an NSString to a bitmap (From: p3consulting <email@hidden>)
 >Re: Rasterizing an NSString to a bitmap (From: Marcel Weiher <email@hidden>)
 >Re: Rasterizing an NSString to a bitmap (From: John Stiles <email@hidden>)
 >Re: Rasterizing an NSString to a bitmap (From: p3consulting <email@hidden>)
 >Re: Rasterizing an NSString to a bitmap (From: John Stiles <email@hidden>)
 >Re: Rasterizing an NSString to a bitmap (From: Dietmar Planitzer <email@hidden>)
 >Re: Rasterizing an NSString to a bitmap (From: John Stiles <email@hidden>)
 >Re: Rasterizing an NSString to a bitmap (From: Dietmar Planitzer <email@hidden>)
 >Re: Rasterizing an NSString to a bitmap (From: John Stiles <email@hidden>)
 >Re: Rasterizing an NSString to a bitmap (From: Marcel Weiher <email@hidden>)
 >Re: Rasterizing an NSString to a bitmap (From: p3consulting <email@hidden>)

  • Prev by Date: KVO for Java
  • Next by Date: debugging my first application
  • Previous by thread: Re: Rasterizing an NSString to a bitmap
  • Next by thread: Re: Rasterizing an NSString to a bitmap
  • Index(es):
    • Date
    • Thread