bugGNUstep - Bugs: bug #38405, Drawing doesn't work with...


bug #38405: Drawing doesn't work with [NSGraphicsContext graphicsContextWithBitmapImageRep:]

Submitted by:  Vitaliy <vmyrik>
Submitted on:  Mon 25 Feb 2013 09:58:37 AM UTC  
Category:  Backend Severity:  3 - Normal
Item Group:  None Status:  None
Privacy:  Public Assigned to:  None
Open/Closed:  Open

Add a New Comment (Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


Mon 25 Feb 2013 09:58:37 AM UTC, original submission:  

I'm trying to draw some sample image. If I do it using default graphics context, its ok. But when I switch graphics context to draw directly on NSBitmapImageRep, it doesn't work - the result is an empty image (but works fine on Apple).

Here is example of my code:

[NSApplication sharedApplication];

NSRect imgRect = NSMakeRect(0.0, 0.0, 100.0, 100.0);
NSSize imgSize = imgRect.size;

NSBitmapImageRep *offscreenRep = [[[NSBitmapImageRep alloc]
                 bitsPerPixel:0] autorelease];

NSGraphicsContext *g = [NSGraphicsContext graphicsContextWithBitmapImageRep:offscreenRep];
NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:g];

NSBezierPath *path = [NSBezierPath bezierPathWithRect:NSMakeRect(10,10,50,50)];
[path setLineWidth:3.0];
[[NSColor redColor] set];
[path stroke];

[NSGraphicsContext restoreGraphicsState];

NSData *imageData = [offscreenRep representationUsingType:NSPNGFileType properties:nil];
[imageData writeToFile:@"result.png" atomically:YES];

Vitaliy <vmyrik>


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

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by vmyrik (Submitted the item)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.




    No changes have been made to this item

    Back to the top

    Powered by Savane 3.7