Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Using GetViewportImage()

    General Talk
    2
    3
    599
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Danchyg1337D
      Danchyg1337
      last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • ManuelM
        Manuel
        last edited by

        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

        MAXON SDK Specialist

        MAXON Registered Developer

        Danchyg1337D 1 Reply Last reply Reply Quote 0
        • Danchyg1337D
          Danchyg1337 @Manuel
          last edited by

          @m_magalhaes Thanks a lot! That makes things clear.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post