• 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: render to 128x128 image
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: render to 128x128 image


  • Subject: Re: render to 128x128 image
  • From: Don Murta <email@hidden>
  • Date: Sun, 11 Nov 2001 23:37:13 -0700

On Sunday, November 11, 2001, at 10:27 PM, Jake wrote:
So here, i passed NULL in the init and had the call allocate space for me.
There is no pointer math here really. By making the bitmap planar(as the
illustration above) prepares it for the vector code. *grin* that shall
come later. at any rate. given the above allocation, one should be able to
fill the entire 128x128 image red by
<snip>

Quickly modifying something I've been working on gives me the following, now one little quirk i've found with NSBitmapImageRep is that if you make one
smaller that 231x231 pixels, you have to zero your own data, otherwise its zeroed for you, not bad for consistency eh? :) That may have just been your problem come to think of it cause it would mess up all your colors and alpha, but then again, it still could be in your loops.
Anyway I hope this helps.

-don-

// theView is NSImageView

#define RENDER_SPACE_WIDTH 128
#define RENDER_SPACE_HEIGHT 128
#define RGBA 4
- (void)someFunc
{
NSRect theRect;
NSImage *theImage;
NSBitmapImageRep *theRep;
int i,j,k;
unsigned char *data[5];

// setup the bitmap to render
theRect= [theView frame];
theImage = [[NSImage alloc] initWithSize: NSMakeSize( NSWidth
( theRect ), NSHeight( theRect ) )];
[theImage setDataRetained:YES];
theRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
pixelsWide:RENDER_SPACE_WIDTH
pixelsHigh:RENDER_SPACE_HEIGHT
bitsPerSample:8
samplesPerPixel:RGBA
hasAlpha:YES
isPlanar:YES
colorSpaceName:NSDeviceRGBColorSpace
bytesPerRow:0
bitsPerPixel:0 ];

[theRep getBitmapDataPlanes:data];

for( i = 0; i < RENDER_SPACE_HEIGHT; i++ )
{
for( j = 0; j < RENDER_SPACE_WIDTH; j++ )
{
data[0][i*RENDER_SPACE_WIDTH+j] = 255; // set full red
for( k = 1; k < 3; k++ )
{
data[k][i*RENDER_SPACE_WIDTH+j] = 0; // we have to zero data
}
data[3][i*RENDER_SPACE_WIDTH+j] = 255; // set full alpha
}
}

[theImage addRepresentation:theRep];
[theView setImage:theImage];
}


  • Follow-Ups:
    • Making an image NSCalibratedWhiteColorSpace
      • From: Gideon King <email@hidden>
References: 
 >Re: render to 128x128 image (From: Jake <email@hidden>)

  • Prev by Date: Re: render to 128x128 image
  • Next by Date: Re: Suggestion: A Getting Started FAQ
  • Previous by thread: Re: render to 128x128 image
  • Next by thread: Making an image NSCalibratedWhiteColorSpace
  • Index(es):
    • Date
    • Thread