I have my CGImageRef and i want to display it trough my NSView. But this code doesn't seem to work, i already have an CGImageRef from source path. Here's my code :
- (void)drawRect:(NSRect)rect {
NSString * thePath = [[NSBundle mainBundle] pathForResource: @"blue_pict"
ofType: @"jpg"];
NSLog(@"the path : %@", thePath);
CGImageRef myDrawnImage = [self createCGImageRefFromFile:thePath];
NSLog(@"get the context");
CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
if (context==nil) {
NSLog(@"context failed");
return;
}
//get the bitmap context
CGContextRef myContextRef = CreateARGBBitmapContext(myDrawnImage);
//set the rectangle
NSLog(@"get the size for imageRect");
size_t w = CGImageGetWidth(myDrawnImage);
size_t h = CGImageGetHeight(myDrawnImage);
CGRect imageRect = {{0,0}, {w,h}};
NSLog(@"W : %d", w);
myDrawnImage = CGBitmapContextCreateImage(myContextRef);
NSLog(@"now draw it");
CGContextDrawImage(context, imageRect, myDrawnImage);
char *bitmapData = CGBitmapContextGetData(myContextRef);
NSLog(@"and release it");
CGContextRelease(myContextRef);
if (bitmapData) free(bitmapData);
CGImageRelease(myDrawnImage);
}
Is anything wrong with the codes?
- Thanks & Regard -