Get Bitmap from ActiveBaseDraw
-
On 15/11/2017 at 05:40, xxxxxxxx wrote:
Is it possible to get a bitmap from your Active or Render BaseDraw?
A screenshot so to speak, without using any rendermethods?Cheers & Thanks in advance,
Lasse -
On 15/11/2017 at 05:51, xxxxxxxx wrote:
You can use BaseDocument.GetDocPreviewBitmap() but as I know there is no way to directly have a screen shot(c4d.Bitmaps) from the BaseView wich is a bit sad.
Personnaly I did a c4d.documents.RenderDocument in hardware mode with custom filters. -
On 15/11/2017 at 05:54, xxxxxxxx wrote:
Yeah, sadly hardware mode gives me a different result.
I wanted to have an exact copy...There is no way to change or alter the dimensions of BaseDocument.GetDocPreviewBitmap(), right?
-
On 15/11/2017 at 06:40, xxxxxxxx wrote:
BaseDocument.GetDocPreviewBitmap() is actually not egual to the Viewport (take care of that), it should perfectly match but not all the time, I guess the preview is update at each save but not sure about that.
About size issue, if you get a c4d.BaseBitmap (wich is what BaseDocument.GetDocPreviewBitmap() return) you cna then size you bitmap as you will do for any c4d.BaseBitmap
https://developers.maxon.net/docs/py/2023_2/modules/c4d.bitmaps/BaseBitmap/index.html#BaseBitmap.ScaleBicubic
Or BaseBitmap.ScaleIt function.For more informations about c4d.BaseBitmap I suggest you to read the c++ manual that can give you some insight https://developers.maxon.net/docs/cpp/2023_2/page_manual_basebitmap.html
Btw, c4d.documents.RenderDocuments return also a basebitmap, so after that you are free to display it into the picture viewer or not (I told that because the first time I use this function I was sure it open the picture viewer, while it's doesn't)
-
On 16/11/2017 at 03:17, xxxxxxxx wrote:
Okay, first version that does the trick for now. (no undos etc.)
Rendering to PictureViewer of course gives the right result, so that did the trick ... I was initially confused because rendering in the EditorView gave me of course a different and unpleasing result.import c4d
from c4d import documents, bitmapsdef SetHardwarePreview(rd) :
preview=rd.GetClone()
preview.SetName("[Screenshot]")
preview[c4d.RDATA_RENDERENGINE]=300001061
preview[c4d.RDATA_FRAMESEQUENCE]=1
preview[c4d.VP_PREVIEWHARDWARE_ANTIALIASING]=4
preview[c4d.VP_PREVIEWHARDWARE_ENHANCEDOPENGL]=True
return preview
def main() :
rd=doc.GetActiveRenderData()
preview=SetHardwarePreview(rd)
doc.InsertRenderData(preview, rd)
prevrd = preview.GetData()
xres = int(prevrd[c4d.RDATA_XRES])
yres = int(prevrd[c4d.RDATA_YRES])
bmp = bitmaps.BaseBitmap()
bmp.Init(x=xres, y=yres, depth=24)
bc=c4d.BaseContainer()
res = documents.RenderDocument(doc, prevrd, bmp, c4d.RENDERFLAGS_EXTERNAL)
if res==c4d.RENDERRESULT_OK:
bitmaps.ShowBitmap(bmp)
c4d.CopyBitmapToClipboard(bmp, 0)
#bmp.Save("""%s/%s.jpg""" % (path, name), c4d.FILTER_JPG, bc, c4d.SAVEBIT_0)
preview.Remove()
c4d.EventAdd()if __name__=='__main__':
main() -
On 16/11/2017 at 08:56, xxxxxxxx wrote:
Hi,
good to see you are making progress. We actually have no better suggestions, at least there are no means to access the framebuffer content of the viewport directly.
I just wanted to add a bit of information (which admittedly will not add to the actual solution at all...).
The idea to use the document preview image (GetDocPreviewBitmap()) wouldn't work in all cases, as the preview depends on user settings and can even be set as an arbitrary image.
As long as RenderDocument() is called from the main thread, it can indeed directly render to Picture Viewer and also open the PV. Unfortunately the needed flags are missing in the Python documentation: RENDERFLAGS_CREATE_PICTUREVIEWER (to render to PV) and RENDERFLAGS_OPEN_PICTUREVIEWER (well... to open the PV).