Hi, I have been exploring the possibility of using Mozilla's graphics library to generate image thumbnails in C++. I would like for this implementation to be multiplatform, so no using platform-specific code in the GFX library. Also, it needs to support all image formats handled by GFX. I should say up front that I while I'm an experienced C++ programmer, I've never used the Mozilla graphics libraries so I'm a bit clueless.
After hours of trawling the web for information, I've concluded that the probable best approach looks something like this: 1. Instantiate an image loader (imgILoader interface) using the "@mozilla.org/image/loader;1" component. 2. Load the image for which we want the thumbnail from a file using imgILoader::LoadImage. This returns an imgIRequest interface. 3. Get the imgIContainer interface by accessing the imgIRequest::image property. 4. Create a device context for the screen. Perhaps like this: static NS_DEFINE_IID(kDeviceContextCID, NS_DEVICE_CONTEXT_CID); nsresult rv = nsComponentManager::CreateInstance(kDeviceContextCID, nsnull, NS_GET_IID(nsIDeviceContext), (void **)&dx); 5. Call nsIDeviceContext::CreateRenderingContextInstance to get an nsIRenderingContext interface. 6. Call nsIRenderingContext::DrawScaledImage to draw a thumbnail image of the appropriate size to the rendering context from the image container. 7. Get the drawing surface associated with the rendering context by calling nsIRenderingContext::GetDrawingSurface. 8. Use nsIDrawingSurface::Lock to retrieve the actual thumbnail image. But I'm unsure about a few things: - Isn't there a way to load an image from a file directly and get an nsIImage interface? It seems like the approach outlined above is designed for asynchronous loading of images over the wire, and also has extra baggage because of the need to handle multiple frames (I guess for video). - Is the approach I proposed for instantiating the device context correct for creating an in-memory rendering context? Will it use pixel-based metrics? - Is nsIRenderingContext::DrawScaledImage the right way to generate a thumbnail image or is there an approach that is more suited to creating a high-quality thumbnail rather than just a smaller version of the image? - Can I get at the image using nsIRenderingContext::GetDrawingSurface and then nsIDrawingSurface::Lock? If so, what format will the image be in? The same format as the original image or is there some default format used internally when I draw to a rendering context? Any guidance on this questions would be greatly appreciated. In particular, if anyone has code that does any or all of this, that would be hugely helpful. I couldn't find anything in the Mozilla codebase that draws images without having a document and/or window, but it's very possible I missed something. Matt _______________________________________________ mozilla-layout mailing list [email protected] http://mail.mozilla.org/listinfo/mozilla-layout
