NSImage from a 1D pixel array?

后端 未结 3 680
独厮守ぢ
独厮守ぢ 2021-02-04 22:42

I have a large 1D dynamic array in my program that represents a FITS image on disk i.e. it holds all the pixel values of the image. The type of the array is double

3条回答
  •  执念已碎
    2021-02-04 22:54

    Here's the solution with your code. This was extended to support all 3 channels. Each channel is 16 bits. Note that I assign imageArray[i] to each channel. This is only because I currently haven't written the code which can read colour FITS files, so to test things out I'm just assigning the image to each channel. The result is, of course, a grayscale image on screen. But if one wants, it can easily be modified such that Red is assigned to Red and so on.

    NSBitmapImageRep *colorRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:nil
                                                                            pixelsWide:width
                                                                            pixelsHigh:height
                                                                         bitsPerSample:16
                                                                       samplesPerPixel:3
                                                                              hasAlpha:NO
                                                                              isPlanar:NO
                                                                        colorSpaceName:NSCalibratedRGBColorSpace
                                                                           bytesPerRow:(3*2*width)
                                                                          bitsPerPixel:48];
    
        rowBytes = [greyRep bytesPerRow];
        NSLog(@"Row Bytes: %d",rowBytes);
        pix = [colorRep bitmapData];
    
        for(i=0;i

提交回复
热议问题