[Closed] NEWBIE – Changing Bitmap Size with Slider
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?
Thanks.
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)
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
)
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:\ emp\ em_01.jpg” “?
Cheers
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)
Cheers!!
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.
This last code is not working for me, it is too much flickering as you say
Going to see imgtag.
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 )
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.
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