Notifications
Clear all

[Closed] Resizing a bitmap

I must be blind, because I’m having trouble finding this. Is there a built in maxscript function that reads a bitmap from file and then resizes it?

  • Neil
15 Replies

You can use rendermap.
It will produce better result because filtering can be used(or not).

Other way is to create new map with desired dimension and use COPY(there are an example by Bobo in the forum) to paste the original map to the new one.

Would you happen to know where the bobo thread is?

I don’t think I can use rendermap because I’d have to add textures to the material editor which will be slow.

  • Neil
1 Reply
(@miauu)
Joined: 11 months ago

Posts: 0

RenderMap is slow, but produces image with better quality.
This is the thread.

I think like this


theFiles= getFiles ("E:\\Photos\\133_1410\\New folder"+"\\"+"*")
theFiles.count

fn resizeImg arrImg= ---dadi single 
(	
	st = timestamp()
	for i = 1 to arrImg.count do
	(
	myNewPath="E:\\Photos\\133_1410\\New folder\\resized"	
	new_file_name = myNewPath +"\\"+ (getfilenameFile arrImg[i]) + ".jpg"
		
	t_bmp = try (openbitmap arrImg[i]) catch()
	bmp_w = t_bmp.width
	bmp_h = t_bmp.height


		if bmp_w > 156 or bmp_h > 156 then
			(
			aspect_bmp = bmp_w / bmp_h as float
			if aspect_bmp > 1 then 
				(
				bmp_w = 156
				bmp_h = 156/aspect_bmp
				bmp_h = bmp_h as integer
				)
				else
				(
				bmp_h = 156
				bmp_w = 156*aspect_bmp
				bmp_w = bmp_w as integer
				)
		txt = "Bitmap " + (filenamefrompath (arrImg[i])) + " resized from " + t_bmp.width as string +"x"+t_bmp.height as string + " to " + bmp_w as string +"x"+bmp_h as string +"."
		format "%
" txt
			)
		
	n_bmp = bitmap bmp_w bmp_h filename:new_file_name
	n_bmp.gamma =2.2	
	copy t_bmp n_bmp
	save n_bmp
	close n_bmp
	close t_bmp
	)
	format "Resizing Image take : % ms
" (timestamp()-st)		
)

resizeImg theFiles

its raw but you got the idea. from scraped script that I found long ago, I think it made by bobo. Thank to him. I think the better part of it is, it can open and resize any picture/texture that max support, altho dont know bout sbasr, never tried it.

Thanks for all the options guys!

  • Neil

Depending on the needs I usually go with this or similar:

(
	fn resizeBitmap bitmp width height = (
		bitResized = bitmap width height
		copy bitmp bitResized	
		bitResized
	)
	
	fn resizeBitmapScale bitmp bscale = (
		bitResized = bitmap (bitmp.width*bscale) (bitmp.height*bscale)
		copy bitmp bitResized
		bitResized
	)
	
	bm = viewport.getViewportDib()
	
	rbm = resizeBitmapScale bm 0.5
	
	display(rbm)
)

that’s quite a “rustic” method Kameleon.

Whatever gets the job done, right!

i prefer a little more subtlety

fn ResizeBitMap bmap factor =
(
	setclipboardBitmap bmap;	
	clipboard = dotnetclass "Clipboard";
	image = clipboard.GetImage();
	
	pformat  = image.PixelFormat
	 width  = image.Width * factor
	 height = image.Height * factor
 
	 dest = dotnetobject "System.Drawing.Bitmap" width height pformat;
	 graphic = (dotnetclass "System.Drawing.Graphics").fromImage dest;
	 
	 graphic.CompositingQuality = graphic.CompositingQuality.HighQuality
	 graphic.SmoothingMode = graphic.SmoothingMode.HighQuality
	 graphic.InterpolationMode = graphic.InterpolationMode.HighQualityBicubic	
	 
	 rect = dotnetobject "System.Drawing.Rectangle" 0 0 width height
	 graphic.DrawImage image rect;
	
	clipboard.SetImage dest;
	image.Dispose();
	 dest.Dispose();
	 graphic.Dispose();
	
	getclipboardBitmap() ;
)	

display(resizeBitmap  (viewport.getViewportDib()) 0.5)
Page 1 / 2