SOLVED Using GetViewportImage()

Hello! In R23 we got an interesting feature to play with, but there is not much of an info about how to use it properly. Im talking about BaseDraw::GetViewportImage().

This is what i tried.

AutoAlloc<BaseBitmap> bmp;
maxon::ImageRef imgr = maxon::ImageClasses::IMAGE().Create() iferr_return;
const maxon::PixelFormat rgbFormat = maxon::PixelFormats::RGB::U8();
const auto storageType = maxon::ImagePixelStorageClasses::Normal();

imgr.Init(optW, optH, storageType, rgbFormat) iferr_return;
bmp->Init(optW, optH);
bmp->GetImageRef(SAVEBIT::NONE, true, imgr);
doc->GetActiveBaseDraw()->GetViewportImage(imgr);

ShowBitmap(bmp);

Bitmap is just black, which leads me to conclusion that im using it the wrong way.
How to use this new function properly and save to bitmap?

hi,

bmp->GetImageRef will retrieve the imageRef used internally.

this is how it's done internally. You have to transfert the data from the imageRef to the bitmap.

	BaseDraw* bd = doc->GetActiveBaseDraw();
	CheckState(bd);

	// Get the viewport image from the viewport renderer
	maxon::ImageRef img;
	bd->GetViewportImage(img);
		

	if (img == nullptr)
		return maxon::NullptrError(MAXON_SOURCE_LOCATION);

	// Transform ImageRef to BaseBitmap in order to show it in the PictureViewer
	const Int w = img.GetWidth();
	const Int h = img.GetHeight();

	AutoAlloc<BaseBitmap> bitmap;
	CheckState(bitmap);

	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()) iferr_return;

	maxon::PixelMutableBuffer imageBuffer(line.GetFirst(), rgbf.GetBitsPerPixel());
	maxon::GetPixelHandlerStruct getpixel = img.GetPixelHandler(rgbf, rgbf.GetChannelOffsets(), maxon::ColorProfile(), maxon::GETPIXELHANDLERFLAGS::NONE, nullptr) iferr_return;

	for (Int y = 0; y < h; y++)
	{
		getpixel.GetPixel(maxon::ImagePos(0, y, w), imageBuffer, maxon::GETPIXELFLAGS::NONE) iferr_return;
		bitmap->SetPixelCnt(0, (Int32)y, (Int32)w, line.GetFirst(), (Int32)rgbf.GetBitsPerPixel().GetBytes(), bitsPerColor == 32 ? COLORMODE::RGBf : COLORMODE::RGB, PIXELCNT::NONE);
	}

	ShowBitmap(bitmap);

Cheers,
Manuel

hi,

bmp->GetImageRef will retrieve the imageRef used internally.

this is how it's done internally. You have to transfert the data from the imageRef to the bitmap.

	BaseDraw* bd = doc->GetActiveBaseDraw();
	CheckState(bd);

	// Get the viewport image from the viewport renderer
	maxon::ImageRef img;
	bd->GetViewportImage(img);
		

	if (img == nullptr)
		return maxon::NullptrError(MAXON_SOURCE_LOCATION);

	// Transform ImageRef to BaseBitmap in order to show it in the PictureViewer
	const Int w = img.GetWidth();
	const Int h = img.GetHeight();

	AutoAlloc<BaseBitmap> bitmap;
	CheckState(bitmap);

	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()) iferr_return;

	maxon::PixelMutableBuffer imageBuffer(line.GetFirst(), rgbf.GetBitsPerPixel());
	maxon::GetPixelHandlerStruct getpixel = img.GetPixelHandler(rgbf, rgbf.GetChannelOffsets(), maxon::ColorProfile(), maxon::GETPIXELHANDLERFLAGS::NONE, nullptr) iferr_return;

	for (Int y = 0; y < h; y++)
	{
		getpixel.GetPixel(maxon::ImagePos(0, y, w), imageBuffer, maxon::GETPIXELFLAGS::NONE) iferr_return;
		bitmap->SetPixelCnt(0, (Int32)y, (Int32)w, line.GetFirst(), (Int32)rgbf.GetBitsPerPixel().GetBytes(), bitsPerColor == 32 ? COLORMODE::RGBf : COLORMODE::RGB, PIXELCNT::NONE);
	}

	ShowBitmap(bitmap);

Cheers,
Manuel

@m_magalhaes Thanks a lot! That makes things clear.