• 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: NSimage Problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSimage Problem


  • Subject: Re: NSimage Problem
  • From: John Stiles <email@hidden>
  • Date: Mon, 7 Aug 2006 13:48:41 -0700

redComponent/greenComponent/blueComponent return a float value between 0.0 and 1.0.


On Aug 7, 2006, at 1:25 PM, Linea Tessile srl wrote:



Hi people!

I need to transform a tiff image in a new image with different colors.

To do this I use the following code:

NSImage *immagine = [[NSImage alloc] initWithContentsOfFile: path];
float altezza = [immagine size].height;
float larghezza = [immagine size].width;
NSBitmapImageRep *bitmap1 = [NSBitmapImageRep imageRepWithData: [immagine TIFFRepresentation]];


    NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc]
        initWithBitmapDataPlanes:nil
                      pixelsWide:larghezza
                      pixelsHigh:altezza
                   bitsPerSample: [bitmap1 bitsPerSample]
                 samplesPerPixel: [bitmap1 samplesPerPixel]
                        hasAlpha: [bitmap1 hasAlpha]
                        isPlanar: NO
                  colorSpaceName: NSCalibratedRGBColorSpace
                     bytesPerRow: [bitmap1 bytesPerRow]
       unsigned char *imageBytes = [bitmap bitmapData];

    int x,y;
    float r,g,b;
    NSPoint where;

    for (y=altezza-1; y>=0; y--)
      {
        for (x=larghezza-1; x>=0; x--)
          {
            where = NSMakePoint(x,y);

where = [[finestra contentView] convertPoint: where fromView: sfondo];

            [self lockFocus];

            NSColor *pixelColor = NSReadPixel(where);

[self unlockFocus]; // always balance -lockFocus with an -unlockFocus.

            int pixIndex;
            NSColor *nuovoCol;
            int indice1;

            pixIndex = 3 * ((y*larghezza)+x);

	    // coloriOr is an array of possible color
	    nuovoCol = [coloriOr indexOfObject:pixelColor];

            r = [nuovoCol redComponent];
            g = [nuovoCol greenComponent];
            b = [nuovoCol blueComponent];

            imageBytes[pixIndex] = (int)r;
            imageBytes[pixIndex+1] = (int)g;
            imageBytes[pixIndex+2] = (int)b;
        }
}

     NSSize s;
    s.width=larghezza;
    s.height=altezza;

    NSImage* newImage=[[[NSImage alloc] initWithSize:s]autorelease];
    [newImage addRepresentation:bitmap];

    [bitmap release];

    [sfondo setImage:newImage];


But the image is drawed all black!!!

If instead I use direct value for the color It works fine!!!
For example:

                imageBytes[pixIndex] = 153;
                imageBytes[pixIndex+1] = 153;
                imageBytes[pixIndex+2] = 153;


Where is the error?


Thanks, Alessandra



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40blizzard.com


This email sent to 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
References: 
 >NSimage Problem (From: Linea Tessile srl <email@hidden>)

  • Prev by Date: NSimage Problem
  • Next by Date: Xcode version
  • Previous by thread: NSimage Problem
  • Next by thread: Xcode version
  • Index(es):
    • Date
    • Thread