Capturing the viewport according to render resolution.
Another snippet!
For Rig Studio, I was faced with the problem of providing a method to not only render the view to the design surface, but capture it also. I felt that sometimes a full render wouldn’t be neccesary and users would want the option of performing a viewport capture for the UI background. If you have ever used the command
gw.getViewportDib()
to retrieve a bitmap of the current viewport, you’ll notice that even if you have the safe frames/ livearea turned on, it still returns the whole viewport.
I worked out a function to calculate the correct crop margin to return a viewport bitmap according to the current render resolution.
Fn LR_CaptureRenderAspectViewport = ( local ViewCap=undefined local cv = getViewSize() local ratio = undefined case of ( (cv.x > cv.y):(ratio = cv.y/cv.x) (cv.x = cv.y):(ratio = 1) (cv.x < cv.y):(ratio = cv.x/cv.y) ) VptDib =gw.getViewportDib(); ViewCap = bitmap renderwidth renderheight color:white ViewportRatio = VptDib.width/VptDib.height as float RenderRatio = renderwidth/renderheight as float case of ( (ViewportRatio <= RenderRatio):( CapturetoRenderHeightRatio =VptDib.width/RenderRatio as float TopEdge = ((VptDib.Height-CapturetoRenderHeightRatio)/ 2.0) as integer FullViewcap = bitmap vptdib.width CapturetoRenderHeightRatio color:white pasteBitmap VptDib FullViewcap (box2 0 TopEdge VptDib.width VptDib.height) [0,0] Copy FullViewcap ViewCap) (ViewportRatio > RenderRatio):( CapturetoRenderHeightRatio =VptDib.height*RenderRatio as float LeftEdge = ((VptDib.width-CapturetoRenderHeightRatio)/ 2.0) as integer FullViewcap = bitmap CapturetoRenderHeightRatio VptDib.height color:white pasteBitmap VptDib FullViewcap (box2 LeftEdge 0 VptDib.width VptDib.height) [0,0] Copy FullViewcap ViewCap) default:() ) close VptDib gc() if viewcap != undefined then (setclipboardbitmap viewcap;close ViewCap;return true)else(return false) ) tempbmp = LR_CaptureRenderAspectViewport() display (getclipboardbitmap())
I hope this is useful.
Tags: homepost
Categories
- 3dsMax (35)
- Characters (11)
- DotNet (47)
- Imaging (9)
- Maxscript (22)
- News (3)
- pipeline (3)
- Program Automation (4)
- Rigging (8)
- Technical Research (14)
- Tips and Tricks (9)
- User Controls (17)
Recent Posts
- SliderMan – Does everything that a slider can
- Grabbing The Material Preview
- The Path of the Righteous
- I Don’t Need Regular Expressions
- Kinetic Energy
- What we are today comes from our thoughts of yesterday
- Autodesk Webinar
- Two Clicks From Amsterdam
- WindowBox Replanted
- SpeechBot – A handy script to load and save morpher keys