次のコードを使用して、DCMTK フレームワークを使用して dicom 画像を読み取り、UIImage ビューに表示しています。
NSString *dcmFilename = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"dcm"];
const void* buffer = dcmFilename;
// Set the dimensions of the current context
size_t width = 250; // set manually, but correct
size_t height = 252;
// 1 byte per component
size_t bitsPerComponent = 8;
bitsPerComponent *= 2; // short = 2 byte
size_t bitsPerPixel, bytesPerRow;
CGColorSpaceRef colorSpace;
CGBitmapInfo bitmapInfo;
CGDataProviderRef theDataProvider;
CFDataRef theDataReference;
bool shouldInterpolate = NO;
CGColorRenderingIntent theIntent;
bitsPerPixel = bitsPerComponent * 1; // because of grayscale image
colorSpace = CGColorSpaceCreateDeviceGray();
bitmapInfo = kCGImageAlphaNone | kCGBitmapByteOrder32Big;
// cg data provider to build the cg image
const UInt8* rawData = static_cast<const UInt8*>(buffer);
// For some reason initiating a CGImage uses BITS per pixel, so we need to divide by 8 to get BYTES
// per pixel
bytesPerRow = (bitsPerPixel/8) * width;
theDataReference = CFDataCreate(NULL,
rawData,
(bytesPerRow*height));
theDataProvider = CGDataProviderCreateWithCFData(theDataReference);
// Finally create the image reference
CGImageRef theImageRef = CGImageCreate(width,
height,
bitsPerComponent,
bitsPerPixel,
bytesPerRow,
colorSpace,
bitmapInfo,
theDataProvider,
nil,
shouldInterpolate,
theIntent);
// Construct an output image
UIImage *myImage = [UIImage imageWithCGImage:(theImageRef)];
NSLog(@"image-- %@", myImage);
patientImageView.image = myImage;
私はこのように出力を得ています。DCM 画像の処理でどこが間違ったのですか???