gpt4 book ai didi

objective-c - 使用 NSData 从 int* 的 NSbitmapRep 创建 NSimage?

转载 作者:行者123 更新时间:2023-12-03 16:49:58 26 4
gpt4 key购买 nike

我有一个 int* 的 rgb 数据、宽度、高度和 scanlinestride,我想在其中创建 NSImage。

我环顾四周,发现我需要使用 NSData?

执行此操作的理想方法是什么?

最佳答案

使用此 NSBitmapImageRep 方法:

- (id)initWithBitmapDataPlanes:(unsigned char **)planes pixelsWide:(NSInteger)width pixelsHigh:(NSInteger)height bitsPerSample:(NSInteger)bps samplesPerPixel:(NSInteger)spp hasAlpha:(BOOL)alpha isPlanar:(BOOL)isPlanar colorSpaceName:(NSString *)colorSpaceName bitmapFormat:(NSBitmapFormat)bitmapFormat bytesPerRow:(NSInteger)rowBytes bitsPerPixel:(NSInteger)pixelBits

说真的。不过它很容易使用:

NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc]
initWithBitmapDataPlanes:(unsigned char **)&bitmapArray
pixelsWide:width pixelsHigh:height
bitsPerSample:8
samplesPerPixel:3 // or 4 with alpha
hasAlpha:NO
isPlanar:NO
colorSpaceName:NSDeviceRGBColorSpace
bitmapFormat:0
bytesPerRow:0 // 0 == determine automatically
bitsPerPixel:0]; // 0 == determine automatically

NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize(width, height)];

[image addRepresentation:bitmap];

关于objective-c - 使用 NSData 从 int* 的 NSbitmapRep 创建 NSimage?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2496113/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com