• 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: How can I draw into a NSImage instance?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How can I draw into a NSImage instance?


  • Subject: Re: How can I draw into a NSImage instance?
  • From: Andreas Monitzer <email@hidden>
  • Date: Sun, 5 Aug 2001 12:31:24 +0200

On Sunday, August 5, 2001, at 12:08 , Nicolai wrote:

All I want to do is to set step by step the color of every pixel
of a NSImage instance.
If someone could give me a hint how to write the following function,
it will help me much!

drawPixelIn:(NSImage*)image withColor:(NSColor*)color at:(NSPoint*)point

Here's the code I wrote for somebody else some time ago. It uses a subclass of NSImageView:

--- myImageView.h ---
#import <Cocoa/Cocoa.h>

@interface myImageView : NSImageView
{
NSBitmapImageRep *myBitmapRep;
}
@end
---------------------

-- myImageView.m ---
#import "myImageView.h"

@implementation myImageView

- (void)awakeFromNib {
NSSize imageSize={200,200};
int i,j;
unsigned char *picture;

myBitmapRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:nil
pixelsWide:imageSize.width
pixelsHigh:imageSize.height
bitsPerSample:8
samplesPerPixel:3
hasAlpha:NO
isPlanar:NO
colorSpaceName:NSCalibratedRGBColorSpace
bytesPerRow:0
bitsPerPixel:24];

picture=[myBitmapRep bitmapData];

for(i=0;i<imageSize.height;i++)
for(j=0;j<imageSize.width;j++) {
picture[3*(i*(int)imageSize.width+j)]=j;
picture[3*(i*(int)imageSize.width+j)+1]=0;
picture[3*(i*(int)imageSize.width+j)+2]=0;
}
[self setNeedsDisplay:YES];
}

- (void)dealloc {
[myBitmapRep release];
}

- (void)drawRect:(NSRect)rect {
[myBitmapRep drawAtPoint:NSZeroPoint];
}

@end
---------------------

this code draws a nice gradient effect (in red).


andy
--
Discussion forthcoming.


References: 
 >How can I draw into a NSImage instance? (From: Nicolai <email@hidden>)

  • Prev by Date: How can I draw into a NSImage instance?
  • Next by Date: Help, in Framework Hell!
  • Previous by thread: How can I draw into a NSImage instance?
  • Next by thread: Help, in Framework Hell!
  • Index(es):
    • Date
    • Thread