[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
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
You could use dotnet :hmm: !?
see http://forums.cgsociety.org/showpost.php?p=7718720&postcount=16 & http://forums.cgsociety.org/showthread.php?f=98&t=1031410
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.
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)
)
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)