bugGNUstep - Bugs: bug #34467, -[NSView...

Group
 
 

bug #34467: -[NSView bitmapImageRepForCachingDisplayInRect:] broken

Submitter:  julian <julian_>
Submitted:  Mon 03 Oct 2011 06:18:24 PM UTC
   
 
Category:  Gui/AppKit Severity:  3 - Normal
Item Group:  Bug Status:  Confirmed
Privacy:  Public Assigned to:  None
Open/Closed:  Open
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 03 Oct 2011 09:45:33 PM UTC, comment #4: 

initWithFocusedViewRect: should not be affected - if you could file another bug, that would be great.

Eric Wasylishen <ericw>
Group Member
Mon 03 Oct 2011 08:38:05 PM UTC, comment #3: 

is the underlying bug also responsible for the fact that the following method (works on OS X) to get the pixel data of a NSImage doesn't work - or should i file a separate bug?


NSImage *theImg = [[NSImage alloc] initWithContentsOfURL:_url];
NSBitmapImageRep* bitmap = [NSBitmapImageRep alloc];
NSSize imgSize = [theImg size];


[theImg lockFocus];
[bitmap initWithFocusedViewRect:NSMakeRect(0.0, 0.0, imgSize.width, imgSize.height)];
[theImg unlockFocus];

char _data = (char )calloc( imgSize.width 4 imgSize.height, 1);              
memcpy(_data, [bitmap bitmapData], imgSize.width 4 imgSize.height);

julian <julian_>
Mon 03 Oct 2011 08:06:05 PM UTC, comment #2: 

thanks for investigating

i can confirm that the workaround works...when removing the views just after taking the snapshot the user won't even see anything


julian <julian_>
Mon 03 Oct 2011 07:43:20 PM UTC, comment #1: 

Thanks for reporting.

As a workaround, you can get it to work by adding the view you snapshot to the window content view before taking the snapshot, and ordering-front the window before taking the snapshot.

-[NSView bitmapImageRepForCachingDisplayInRect:] and -[NSView cacheDisplayInRect:toBitmapImageRep:] probably shouldn't rely on being able to lock focus on the view (self), but rather should use [NSGraphicsContext graphicsContextWithBitmapImageRep:] to create a context which can draw directly on the bitmap, and then just call the view's display method. The only problem is, [NSGraphicsContext graphicsContextWithBitmapImageRep:] isn't implemented currently.

Another potential bug this revealed is it seems you can't lock focus on a view before its window has been ordered front... that sounds wrong to me.

Eric Wasylishen <ericw>
Group Member
Mon 03 Oct 2011 06:18:24 PM UTC, original submission:  

i am trying to use the following category (works on Mac OS X) to capture the contents of an NSView including subviews as an NSImage but it doesn't work as there is an exception somewhere deep in bitmapImageRepForCachingDisplayInRect:


@implementation NSView (NSView_Snapshot)

- (NSImage *)snapshotIncludingSubviews
{
    NSBitmapImageRep *imageRep = [self bitmapImageRepForCachingDisplayInRect:self.bounds];
    NSImage *renderedImage = [[NSImage alloc] initWithSize:[imageRep size]];

    [self cacheDisplayInRect:self.bounds toBitmapImageRep:imageRep];
    [renderedImage addRepresentation:imageRep];

    return [renderedImage autorelease];
}
@end

minimal runnable sample project to illustrate the issue attached

issue occurs in SVN trunk as of today as well as a few months ago.

julian <julian_>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #24089:  GNUstepTest.tar.gz added by julian_ (2KiB - application/x-gzip)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by ericw (Posted a comment)
  • -email is unavailable- added by julian_ (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2011-10-03 ericw CategoryNone Gui/AppKit
        Item GroupNone Bug
        StatusNone Confirmed
    2011-10-03 julian_ Attached File- Added GNUstepTest.tar.gz, #24089

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code