• 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: Problem drawing directly to bitmap rep using NSGraphicsContext
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Problem drawing directly to bitmap rep using NSGraphicsContext


  • Subject: RE: Problem drawing directly to bitmap rep using NSGraphicsContext
  • From: Vinay Prabhu <email@hidden>
  • Date: Wed, 29 Nov 2006 11:17:52 +0530
  • Importance: Normal

I think that was unnecessary.

I have taken the sample code from following link
http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaDrawingGuide/
index.html#//apple_ref/doc/uid/TP40003290

The code is like this,
NSRect offscreenRect = NSMakeRect(0.0, 0.0, 500.0, 500.0);
NSBitmapImageRep* offscreenRep = nil;

offscreenRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:nil
                        pixelsWide:offscreenRect.size.width
                        pixelsHigh:offscreenRect.size.height
                        bitsPerSample:8
                        samplesPerPixel:4
                        hasAlpha:YES
                        isPlanar:NO
                        colorSpaceName:NSCalibratedRGBColorSpace
                        bitmapFormat:0
                        bytesPerRow:(4 * offscreenRect.size.width)
                        bitsPerPixel:32];

[NSGraphicsContext saveGraphicsState];
[NSGraphicsContext setCurrentContext:[NSGraphicsContext
                        graphicsContextWithBitmapImageRep:offscreenRep]];

// Draw your content...

[NSGraphicsContext restoreGraphicsState];

Any difference b/n this code and code suggested by you???

NSImageRep class has 3 drawing API's,
– draw
– drawAtPoint:
– drawInRect:

drawInRect will scale the image as required. I have written the code to draw
bitmap rep on NSView using NSImage as well as above mentioned API's. So I am
using drawInRect API to draw on another bitmap rep.
Since our application minimum system requirements has moved to Tiger, I am
using the technique to directly draw onto bitmap rep.
On OS Panther I have achieved this using NSImage lockFocus and unLockFocus.

I am here to discuss and get the solution to my problem , not to discuss my
programming abilities.

-----Original Message-----
From: cocoa-dev-bounces+vinayprabhu=email@hidden
[mailto:cocoa-dev-bounces+vinayprabhu=email@hidden]On
Behalf Of Erik Buck
Sent: Wednesday, November 29, 2006 12:04 AM
To: email@hidden
Subject: Re: Problem drawing directly to bitmap rep using
NSGraphicsContext


You seem very confused and on the wrong path.  No offence intended, but I am
trying to determine what level of assistance you need: Have you ever done
any programming before ?  Do you understand the concepts of variables,
storage, pointers, and global graphics state ?

  How about this code ?

  NSBitmapImageRep  *imageRep = [NSBitmapImageRep imageRepWithData:[NSData
dataWithContentsOfFile:path]];
NSGraphicsContext *imageRepContext = [NSGraphicsContext
graphicsContextWithBitmapImageRep:imageRep];
NSGraphicsContext *originalContext = [NSGraphicsContext currentContext];
  [NSGraphicsContext setCurrentContext:imageRepContext]; // Future drawing
goes to the image rep
// Do any drawing you want.  imageRep already contains the image loaded from
path
// based on your example, there is no more work to do.
[NSGraphicsContext setCurrentContext:originalContext]; // put things back
the way you found them

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
in

This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: Problem drawing directly to bitmap rep using NSGraphicsContext (From: Erik Buck <email@hidden>)

  • Prev by Date: exceptions, debug and deployment
  • Next by Date: Re: Binding an NSTextField to an NSNumber value fails with 'Switzerland (French)' localization
  • Previous by thread: Re: Problem drawing directly to bitmap rep using NSGraphicsContext
  • Next by thread: Re: Problem drawing directly to bitmap rep using NSGraphicsContext
  • Index(es):
    • Date
    • Thread