Hello! I asked about GetViewportImage() in this topic few days ago. Code worked as it should, but it seems like it only gets image from active document, even tho BaseDraw is different.
Here is my code.
BaseDocument* doc = GetFirstDocument();
while (doc) {
BaseDraw* bd = doc->GetActiveBaseDraw();
if (!bd) {
doc = doc->GetNext();
continue;
}
AutoAlloc<BaseBitmap> bitmap;
// Get the viewport image from the viewport renderer
maxon::ImageRef img;
bd->GetViewportImage(img);
if (img == nullptr) {
doc = doc->GetNext();
continue;
}
// Transform ImageRef to BaseBitmap in order to show it in the PictureViewer
const Int w = img.GetWidth();
const Int h = img.GetHeight();
maxon::PixelFormat rgbf = img.GetPixelFormat();
Int32 bitsPerColor = (Int32)(rgbf.GetBitsPerPixel().Get() / rgbf.GetChannelCount());
bitmap->Init((Int32)w, (Int32)h, bitsPerColor == 32 ? 96 : 32);
maxon::BaseArray<UChar> line;
line.Resize(w * rgbf.GetBitsPerPixel().GetBytes()).GetValue();
maxon::PixelMutableBuffer imageBuffer(line.GetFirst(), rgbf.GetBitsPerPixel());
maxon::GetPixelHandlerStruct getpixel = img.GetPixelHandler(rgbf, rgbf.GetChannelOffsets(), maxon::ColorProfile(), maxon::GETPIXELHANDLERFLAGS::NONE, nullptr).GetValue();
for (Int y = 0; y < h; y++)
{
getpixel.GetPixel(maxon::ImagePos(0, y, w), imageBuffer, maxon::GETPIXELFLAGS::NONE).GetValue();
bitmap->SetPixelCnt(0, (Int32)y, (Int32)w, line.GetFirst(), (Int32)rgbf.GetBitsPerPixel().GetBytes(), bitsPerColor == 32 ? COLORMODE::RGBf : COLORMODE::RGB, PIXELCNT::NONE);
}
ShowBitmap(bitmap);
doc = doc->GetNext();
}
Each showed bitmap contains only active document viewport.
I also tried to switch document with SetActiveDocument() and then call DrawViews() before getting viewport image, but that didnt work.
Is there a way to get viewpirt image of inactive documents?