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

Group
 
 

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

Submitter:  Vitaliy <vmyrik>
Submitted:  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
* Mandatory Fields

Add a New Comment Rich Markup
   

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]
     initWithBitmapDataPlanes:NULL
                   pixelsWide:imgSize.width
                   pixelsHigh:imgSize.height
                bitsPerSample:8
              samplesPerPixel:4
                     hasAlpha:YES
                     isPlanar:NO
               colorSpaceName:NSDeviceRGBColorSpace
                  bytesPerRow:0
                 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:
   
   
Comment:
   

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)
  •  

    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.

     

    No changes have been made to this item

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code