Re: NSBitmapImageRep and 1-bit image
Re: NSBitmapImageRep and 1-bit image
- Subject: Re: NSBitmapImageRep and 1-bit image
- From: Heinrich Giesen <email@hidden>
- Date: Thu, 1 Dec 2005 11:24:39 +0100
On 01.12.2005, at 09:41, Timofey Sherudilo wrote:
Here is my problem: I try to create a 1-bit image representation,
like this:
some text omitted
Do I create the monochrome image right? Is something wrong in my code?
You didn't respect that a pixel needs one BIT not one BYTE !
This leads to some "nice" bitoperations:
In the creation of imageRep you should write bytesPerRow:0
or bytesPerRow:(width+7)/8 and not bytesPerRow:width.
The offset in -setPicColor:... is
int offset = x/8 + [imageRep bytesPerRow] * y; // x/8 NOT x
Somewhere in planeBitmap[offset] is the bit that shall become
1 or 0. To be precise, it is the bitnumber x%8 (the modulo
operation) counting from left. If you have black = (...) ? 1 : 0;
you can set the pixel (==bit)
if( black==0 )
planeBitmap[offset] &= ~(0x80 >> (x%8)); // clear
else
planeBitmap[offset] |= 0x80 >> (x%8); // set
--
Heinrich Giesen
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden