View Full Version : NEWBIE - Changing Bitmap Size with Slider

02 February 2009, 05:06 PM
Ok, now i have the "Gamma Thing" solved thanks to ZeBoxx2 and Piflik.

Now i have another problem.

if you test the script i have below you will notice that as long as i modify the width of the bitmap with the slider the bitmap moves from left to right instead of cropping the picture.

Can someone help me with that?



rollout test "Test" width:294 height:121

bitmap bitm "Bitmap" pos:[10,30] bitmap:(getLastRenderedImage()) width:renderWidth height:renderHeight
slider size "" pos:[10,(renderHeight)+30] width:((renderWidth)+10) height:44 range:[0,(renderWidth),(renderWidth)]

on size changed val do (
bitm.width = val
bitm.bitmap = getLastRenderedImage()

createDialog test (((renderWidth))+20) ((renderHeight)+80)


02 February 2009, 06:11 PM
The MaxScript Bitmap control always centers the bitmap assigned.. There's two main ways you can deal with this..

A. Ditch the MaxScript Bitmap control
e.g. use an imgtag (with style #bmp_tile) or a .NET Image control (which has similar style options) instead

B. Crop the bitmap before setting it.
Have a peek at the pasteBitmap command for that one. You can define a rectangle to copy and paste into the destination bitmap. E.g.

on size changed val do (
bitm.width = val
inBmp = getLastRenderedImage()
outBmp = bitmap bitm.width bitm.height
pasteBitmap inBmp outBmp (Box2 0 0 bitm.width bitm.height) [0,0]
bitm.bitmap = outBmp

02 February 2009, 06:19 PM
Testing it as we speak, i works perfectly in the example script, now trying to insert in the complete script :)

Is there some difference between using "getLastRenderedImage()" and using " openBitmap "c:\\temp\\tem_01.jpg" "?


02 February 2009, 06:20 PM
I answer myself...there is no difference :)

02 February 2009, 06:26 PM
Thanks ZeBoxx2!!

Working like a charm!

Now that the main script is working i'm going to try the imgtag instead biptmap, i don't want to do it with .net because i want some retrocomp with max 9/2008 nad mybe with 8 (i'm not sure with this one)


02 February 2009, 06:27 PM
if you want something a little more efficient (though I'd still go with imgtag/.net) and less memory consuming (max just crashed here - too many new bitmaps being constructed, I guess - maybe add a 'gc light:true' if you go with the pastebitmap route), but a lot more flickering...

on size changed val do (
local oldSize = bitm.width
if (val > oldSize) then (
bitm.width = bitm.bitmap.width
bitm.bitmap = bitm.bitmap
bitm.width = val

On the topic of getLastRenderedImage() , there is one big difference. If you haven't rendered yet, getLastRenderedImage() will return 'undefined'. You can't assign 'undefined' as a bitmap value to a bitmap control so you'll have to trap for that.

02 February 2009, 06:30 PM
This last code is not working for me, it is too much flickering as you say :)

Going to see imgtag.

02 February 2009, 06:36 PM
imgtag is working great, but i cannot see any option to disable the "transparent" feature (apart from setting a rare color...but in 3d you might have this color even if you don't notice)

Is there some way to do this?

P.D.: i'm creating blank files before loading the bitmaps to avoid the error and to have an option to recall this bitmaps, as soon as it's finished i'll post the script in the forum and in scriptspot :) )

02 February 2009, 07:12 PM
ZeBoxx2 is there some way to put a limit of bitmaps being constructed, so we can prevent max from crashing? because the second solution is not working fine for me.

Also imgtag it's finally not working fine for my case.

02 February 2009, 07:23 PM
I found the answer.

Calling the garbage collector with the "light" option to true i prevent the memory to be flushed with a lot of waste bitmaps i think, at least it seems to work.

The command is

"gc light:true"

I do this inside the function of the slider that modify the width of the bitmap, and it seems to be worgin, after use this command i had 5gb's or ram eated by max, and now i'm in a normal quantity of ram.

Cheers :)

02 February 2009, 07:54 PM
imgtag's transparency - 'fraid not, at least not that I can think of. Maybe you can set a negative color or so.. never tried so I'm not sure if that just ends up remapping to some other color. Alternatively, stick a bitmap control (you might want the edges anyway) or so behind it which has the color that you're using for transparency. *hack hack hack* :)

.NET? ;)

02 February 2009, 08:11 PM
.net have the problem that is not compatible with Max9 i think, and i don't understand .net very well at my current level.

I started scripting last week(not yesterday :P ), and i don't know anything about programming hehe

02 February 2009, 09:51 PM
.NET support was introduced in Max9, actually :) .NET is pretty simple mainly because you're just dealing with objects, not with programming language bits (which would be more the domain of, C#, etc.) so much - though if you've got a solution now, no particularly need to delve into it.

There were some changes since Max9, mostly to do with some datatype conversion (Max9/Max2008 you often had to explicitly declare a number as Int32, for example), but most things should work.

The major down side is that you'll have to temporarily store your bitmap to a file and then load that into the .NET control. The reason for this is that 1. setClipboardBitmap isn't available in 3ds Max 9, so you can't use the (clipboard-data-destroying) clipboard copy/paste hack and 2. transferring pixel data over otherwise is *slow*.

Though I just found out that the default controls aren't double-buffered so you'll have the same flickering with a typical .NET control (such as PictureBox) unless you grab a third party one.

*sigh* :)

02 February 2009, 09:59 PM
I'm storing the bitmaps, because i want to have some kind of cache, but now i have another question with this thing.

i posted a new message, check it :)


CGTalk Moderation
02 February 2009, 09:59 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.