Gray image

tommyaltaïr

Membre confirmé
5 Mars 2008
25
0
Slt, cela fait plusieurs jours que je me casse la tête avec le code qui suit. L'image obtenue est initialisée que sur sa moitié (les 8 premières lignes), mais pire encore, mes pixels ne correspondent pas à la valeur que j'écris (123 à la place de 140). Par conte mon image est bonne si destData[x] = 255;

Voilà le code :

int width = 16;
int height = 16;
int bpp = 8;
int x;
unsigned char *destData;
NSBitmapImageRep* MyImageRep

MyImageRep = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:NULL
pixelsWide:width
pixelsHigh:height
bitsPerSample:bpp
samplesPerPixel:1
hasAlpha:NO
isPlanar:NO
colorSpaceName:NSCalibratedWhiteColorSpace
bytesPerRow:0
bitsPerPixel:bpp];


destData = [MyImageRep bitmapData];

for ( x = 0; x < width * height; y++ )
{
destData[x] = 140;
}


NSImage* imageFromBundle = [[NSImage alloc] init];
[imageFromBundle addRepresentation: MyImageRep];
[imageFromBundle autorelease];


// save file
NSArray *representations;
NSData *bitmapData;

representations = [imageFromBundle representations];

bitmapData = [NSBitmapImageRep representationOfImageRepsInArray:representations
usingType: NSBMPFileType properties:nil];

[bitmapData writeToFile:mad:"AnaAlta.bmp" atomically:YES];
// save file
 
Je pense que le forum Développement sera plus approprié.