Snapshot of plugin instance gui


#1

hi there i’m trying to get screenshots of the plugin guis from plugin isntances.
createing component snapshot via Componenets method does not work, and a little look inside revealed why.
seems not to work for native windows.

i also tried to retrieve the handle of the vst (im workign vst/windows) and convert it to an image with. this code

				VSTPluginWindow* comp = (VSTPluginWindow*)pluginWindow->getContentComponent();
				int w = comp->getWidth();
				int h = comp->getHeight();

				HWND nativePluginWindow = comp->pluginHWND;
				HDC nativePluginDC = GetDC(nativePluginWindow);
				HDC hCaptureDC = CreateCompatibleDC(nativePluginDC);
				HBITMAP hCaptureBitmap = CreateCompatibleBitmap(nativePluginDC, w, h);
				SelectObject(hCaptureDC,hCaptureBitmap);
				BitBlt(hCaptureDC,0,0,w,h,nativePluginDC,0,0,SRCCOPY);

				Image * img = createImageFromHBITMAP(hCaptureBitmap);
				FileOutputStream fo(File("c:\\text.png"));
				PNGImageFormat png;
				png.writeImageToStream(*img,fo);
				fo.flush();
				delete img;
								
				ReleaseDC(nativePluginWindow,nativePluginDC);
				DeleteDC(hCaptureDC);
				DeleteObject(hCaptureBitmap);

no luck so far…white image :(.
any ideas how to archive this?
if it is not possible rigth now it might be good to add mehods to plugin instance for retrieving native window handle and/or image.
i’d do it and share. (windows / linux (osx maybe))

peace.


#2

I used the following code to do this:

new method in class Win32ComponentPeer (build/win32/platform…/juce_Win32Windowing.cpp):

Image* const getSnapshot ()
{
	int x, y, w, h;
	getBounds(x, y, w, h);
	WindowsBitmapImage* const bitmap = new WindowsBitmapImage(Image::RGB, w, h, true);
	bitmap->blitFromWindow (hwnd, w, h);
	return bitmap;
}

uses new method in class WindowsBitmapImage (same file):

void blitFromWindow (HWND hWnd, int width, int height) throw()
{
    HDC hdcWindow = GetDC(hWnd);
    BitBlt(hdc,
               0,0,
               width, height,
               hdcWindow,
               0,0,
               SRCCOPY);
    ReleaseDC(hWnd,hdcWindow);
}

#3

hey, cool.
thanks for sharing my friend :slight_smile:

peace!

jm