我正在Mac上实现一个Photoshop插件,我正在使用Cocoa。到目前为止一切正常,但下一步是提供一个“预览”图像,作为我的插件窗口的一部分,我被卡住了。我是一个n00b的Obj-C程序员,实际上没有帮助:-)
到目前为止,我有这样的事情:
int dataSize = gFilterRecord->bigDocumentData->wholeSize32.v *
gFilterRecord->bigDocumentData->wholeSize32.h *
gFilterRecord->planes;
NSData *inData = [[NSData alloc] initWithBytesNoCopy:gFilterRecord->inData length:dataSize freeWhenDone:NO];
NSLog(@"LoadImageFromSDK : Data created");
NSImage *imageTmp = [[NSImage alloc] initWithData:inData];
NSLog(@"LoadImageFromSDK : Image created");
//Save to PNG file as a test of this image creation
[[imageTmp TIFFRepresentation] writeToFile:@"/tmp/imageTmp.tif" atomically:YES];
NSLog(@"LoadImageFromSDK : Wrote image to disk");
此刻,它可怕地崩溃:
09/07/22 10:23:32 AM Adobe Photoshop Elements [46628] *** NSCopyMemoryPages(0x0,0x245f4000,2265088)失败
我可能错误地计算了inData的大小。救命?
另外,NSImage是否能够正确解释图像数据blob?或者我应该放弃它,只是逐像素映射到NSImage?
答案 0 :(得分:0)
好吧,这比我预想的更痛苦。另外,感谢NVidia发布此PDF,这是对Photoshop SDK过滤器记录的更好解释,而不是实际的SDK文档。
除了用于调试目的的示例tif文件之外,这段代码实际上读取了inData并产生了一个可用的NSImage(大量的日志记录只是为了弄清楚它在做什么,随意删除)。
NSLog(@"Entering LoadImageFromSDK");
unsigned char *bitmapPlanes[4];
bitmapPlanes[0] = (unsigned char *) (gFilterRecord->inData);
NSLog(@"Params to create bitmap");
NSLog(@"pixelsWide = %d", gFilterRecord->bigDocumentData->imageSize32.h );
NSLog(@"pixelsHigh = %d", gFilterRecord->bigDocumentData->imageSize32.v );
NSLog(@"bitsPerSample = %d", gFilterRecord->depth );
NSLog(@"samplesPerPixel = %d", gFilterRecord->planes );
NSLog(@"hasAlpha = %d", NO );
NSLog(@"isPlanar = %d", NO );
NSLog(@"colorSpaceName = %@", mapImageModeToColorSpace(gFilterRecord->imageMode) );
NSLog(@"bytesPerRow = %d", gFilterRecord->inRowBytes );
NSLog(@"bitsPerPixel = %d", gFilterRecord->depth*gFilterRecord->planes );
NSBitmapImageRep *bitmapTmp = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:bitmapPlanes
pixelsWide:gFilterRecord->bigDocumentData->imageSize32.h
pixelsHigh:gFilterRecord->bigDocumentData->imageSize32.v
bitsPerSample:gFilterRecord->depth
samplesPerPixel:gFilterRecord->planes
hasAlpha:NO
isPlanar:NO
colorSpaceName:mapImageModeToColorSpace(gFilterRecord->imageMode)
bytesPerRow:gFilterRecord->inRowBytes
bitsPerPixel:gFilterRecord->depth*gFilterRecord->planes];
NSLog(@"LoadImageFromSDK : Bitmap created = %@", bitmapTmp);
[[bitmapTmp TIFFRepresentation] writeToFile:@"/Users/someuser/temp/sample.tif" atomically:YES];
NSImage *imageTmp = [[NSImage alloc] initWithSize:[bitmapTmp size]];
[imageTmp addRepresentation:bitmapTmp];
NSLog(@"LoadImageFromSDK : Image created = %@", imageTmp);