Getting getViewportDib() to a file ?

How can you retrieve an image of a viewport and then save it to a file without using the "Grab Viewport" macro. After a bit researching I found that getViewportDib() or view.getViewportDib() will get the bitmap image of the view but how can you save this to a file name, location, and type, jpeg or png, with no dialog boxes ?
Any help would be appreciated, thanks.

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
chuck666's picture

Thanks, those methods worked

Thanks, those methods worked like a charm. A little off topic but why the fudge can't programming languages like maxscript, auto and visual lisp, corelscript and probably many others simply cannot read a text file, skip down to a line, then replace that line with new content and be on your way. Its absurd how you have to read a line, then write it to a separate open file over and over just to change one line, makes no sense to me all. You can open a file and append to the end of it ?? Is there technical reason that makes this seem impossible to do ?

Thanks for the saving viewport to a file info.

jahman's picture

.

appending is easy. check mxs reference on reading/writing to filestream.

(
	f = createfile @"C:/test.tmp"
	for i=1 to 10 do format "line #%\n" i to:f
	close f
 
	f = openfile @"C:/test.tmp" mode:"a+"
	for w in #( "I", "like","to","append!" ) do format "%\n" w to:f
	close f
 
 
	format "%\n" ((dotNetClass "system.io.file").readalltext @"C:/test.tmp")
)
miauu's picture
miauu's picture

.

(
	saveToPath = @"D:\\"
 
	grab_viewpBMP = gw.getViewportDib()
 
	tempBMP = bitmap grab_viewpBMP.width grab_viewpBMP.height
 
	pasteBitmap grab_viewpBMP tempBMP (box2 0 0 grab_viewpBMP.width grab_viewpBMP.height) [0,0] 
 
 
 
	tempBMP.filename = (saveToPath + "MyViewportSnapshot.jpg")
 
	save tempBMP
	close tempBMP
	close grab_viewpBMP
	tempBMP = undefined
	grab_viewpBMP = undefined
	freeSceneBitmaps()
)
jahman's picture

.

:)

(
 
	bm = gw.getViewportDib()
	bm.filename = @"C:/tmp_bitmap.png"
	save bm
 
)
miauu's picture

.

Yep, shorter. :)
When the snapshot must be bigger than the actual viewport the pasteBitmap can't be avoided. :)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.