Hi everyone,
I have a bit of a tricky problem.
I am writing an application plugin, In this case it is mostly a C and C++ project, which produces .bundle that is then loaded by the host application.
As part of the plugin i need to draw a image/bitmap into a view supplied by the host application.
The host application provides me with a NSImage* that I am supposed to draw into..... But HOW??
I have created an NSImage from the Image data, and i am trying to load it into the NSview, but i cannot for the life of me get it to display?
My code is as follows,
NSImage* pImage = [[NSImage alloc] initWithCGImage:iref size:NSMakeSize(width, height)];
if (pImage)
{
NSSize imageSize = [pImage size];
NSRect tFrame = [hostNSView frame];
printf("Image Size is %d x %d. \n", (int)imageSize.width, (int)imageSize.height);
printf("View tFrame Origin: %d x %d. Size: %d x %d \n", (int)tFrame.origin.x, (int)tFrame.origin.y, (int)tFrame.size.width, (int)tFrame.size.height);
tFrame.size.width = MAX(tFrame.size.width, imageSize.width);
tFrame.size.height = MAX(tFrame.size.height, imageSize.height);
[hostNSView setFrame:tFrame];
[hostNSView setNeedsDisplay:YES];
[hostNSView display];
}
This code runs, and does not produce any errors that i can see, But it is also not displaying the image in the region i am expecting to see it?
Historically i am C/C++ programmer so i am unfamiliar with the design patterns of cocoa and general OSX GUI-ness,
so please excuse, but highlight any obvious errors or mis-understandings.
Cheers,
Hi all,
so i finally found a solution that works.
In the end i needed to get the current context and draw into it via
CGContextDrawImage(cgcontext, [pView bounds], image);
However i also needed to make sure to use the
[[NSGraphicsContext currentContext] flushGraphics];
command to ensure that the image would get drawn correctly.
Anyway thanks to everyone for their help!