PDA

View Full Version : dotNet to simulate Paint tool for Bitmap


johnwhile
09-28-2010, 04:47 PM
Hi, i read some "How To...." in Maxscript help to build a bitmap tool but i understand that the size of bitmap scene or rollout must be fixed, so there aren't the possibility to zoom or scroll the view like Paint, and this way is very complicated....

So i read some thing about dotNet, i read about dotNet.assemply and i want know how and if there are the possibility to create a tool like Paint or like some similar free programm example:
http://www.freedownloadscenter.com/Multimedia_and_Graphics/Screen_Capture_Tools/Paint_Express.html

I also look in the "How To..." the example of browser version !! where a can find some manual about dotNet ? because with the maxscript help i don't understand how find all function of system. et...

PEN
09-28-2010, 05:13 PM
This is very possible as you can track your mouse over forms and get all the user feed back that you will need. From there you can use GDI drawing methods to draw into the form and then save it as a bitmap.

You can get information about GDI drawing on my site as well other dotNet/MXS information here.
http://www.penproductions.ca/tutorials/dotNet/dotNet.htm

There are a number of other sites that have some good information on it as well. Using the methods above I have had good luck getting a prototype working. Next thing is sorting out tablet pressure but I'm not sure how to go about that as of yet.

johnwhile
09-28-2010, 09:13 PM
Oh, thanks, it's exactly that i want ... but i look now the tutorial and is very complicated, is similar the C++ GUI.
There is a complete manual ? Because i understand your tutorial but now i want build a simple Paint tool (because i must work with pixel to build a pathfinding for a game tool) but I don't know how start T_T

johnwhile
09-29-2010, 07:29 PM
Ok, i understand somethings of this dotNet , now i can convert my script for Max64bit !!!
(example: http://www.treddi.com/forum/index.php?app=core&module=attach&section=attach&attach_id=58302)

i found all information that i need here:
http://msdn.microsoft.com/en-us/library/k50ex0x9.aspx
but i have spent two hours to find the listView in dotnet format

PEN
09-30-2010, 06:24 PM
Should work in 64 bit without a problem. There is no complete manual for Max script and dotNet, you just need to try and follow C# or other languages and convert to Max script. And ask lots of questions here as I have.

johnwhile
09-30-2010, 09:54 PM
Should work in 64 bit without a problem. There is no complete manual for Max script and dotNet, you just need to try and follow C# or other languages and convert to Max script. And ask lots of questions here as I have.
ok, only a question:
in the ActiveXControl for ListView then i want link a item to an objects i put:
obj = box()
lv.item.tag = obj
But in DotNet ???
obj = box()
and then if i utilize tag property don't work

PEN
10-01-2010, 12:13 AM
Same, but use

lv.item.tag = dotNetMxsValue obj

johnwhile
10-01-2010, 10:37 AM
Same, but use

lv.item.tag = dotNetMxsValue obj
very thanks, this is a thing that i haven't understood...

johnwhile
10-01-2010, 02:13 PM
... i make some first experiment, example, if i want add a menu how can i add it ?
(
--form.close()
dnForm=dotNetObject "System.Windows.Forms.form"
dnForm.text = "NameOfTool"

dnMenu = dotnetObject "System.Windows.Forms.MainMenu"
dnMenuItem1 = dotnetObject "System.Windows.Forms.MenuItem"
dnMenuItem1.text = "File"
dnMenu.MenuItems.Clear()
dnMenu.MenuItems.Add dnMenuItem1

formatProps DnForm

DnForm.show()
)

johnwhile
10-01-2010, 02:23 PM
ah ok resolved with these:
dnForm=dotNetObject "System.Windows.Forms.form"
dnForm.text = "NameOfTooll"

dnForm.menu = dotnetObject "System.Windows.Forms.MainMenu"
dnMenuItem1 = dotnetObject "System.Windows.Forms.MenuItem"
dnMenuItem1.text = "File"
dnForm.menu.MenuItems.Clear()
dnForm.menu.MenuItems.Add dnMenuItem1

johnwhile
10-11-2010, 10:44 AM
hi, i have a problem, how can I add a bitmap image to pictureBox dotnetcontrol ???
i put the script and the file containing the image data.
My problem is in:
...
rollout PathRollout "PathFinding Editor" width:512 height:440
(
dotNetControl dnPictureBox "pictureBox" pos:[0,0] width:400 height:392
...
...
on ChList selected index do
(
chanel = index
if TGA!=undefined then
(
paintPath.bitmap = TGA[index]
bmpDisplayed = dotNetObject "System.Drawing.Bitmap" TGA[index] -- BUT TGA[n] is a maxscript bitmap value, not a file
)
)
...
i want add a bitmap image via dotnet because maxscript bitmap editor is not good.... but i want add without save a temporary bmp file.

PEN
10-11-2010, 12:51 PM
First off I'm going to suggest that you will want to use a dotNet form to contain the picture box if you are trying to do what you have asked. I say that because you will run into issues at some point with the limits of how you can manage the dotNet in a Max rollout.

As for the bitmap have a look at the backGroundImage property or you can also use GDI to draw it in with the paint event. Have a look on my site for information on how to do this.

johnwhile
10-11-2010, 01:02 PM
thanks, I've already seen the tutorial about "paint event", it create the image when rollout open, but I want to load images after, in second moment, and i don't want that the file are saved in a temporaney bmp file.
In Maxscript you can utilize a internal bitmap value, (but i must save in bmp to show the texture map )

LoneRobot
10-11-2010, 02:27 PM
hi john,

to avoid saving to a temporary bitmap, try saving the max bitmap to the clipboard using setclipboardbitmap <bitmap> and then using (dotnetclass "clipboard").getimage() to retrieve it in the dotnetcontrol

you can also use Paul's advice on using GDI+ to draw the temp image to an 'in-memory' dotnet image, like how you mentioned.

johnwhile
10-11-2010, 06:34 PM
hi john,
to avoid saving to a temporary bitmap, try saving the max bitmap to the clipboard using setclipboardbitmap <bitmap> and then using (dotnetclass "clipboard").getimage() to retrieve it in the dotnetcontrol
you can also use Paul's advice on using GDI+ to draw the temp image to an 'in-memory' dotnet image, like how you mentioned.
Perfect!! is a very good idea. Now the script can load in the pixtureBox a maxscript bitmap, i make this code:
on ChList selected index do
(
chanel = index
if TGA!=undefined then
(
paintPath.bitmap = TGA[index]
btnCreate.caption = "create_ch:" + chanel as string
-------------------------dotnet-------------
setclipboardBitmap TGA[index]
clipboardClass = dotNetClass "System.Windows.Forms.Clipboard"
theImage = clipboardClass.getImage()
--clipboardClass.setImage theImage
--dnBitmap = getclipboardBitmap()
dnPictureBox.image = dotnetObject "System.Drawing.Image" theImage
)
)
Now i can create some function like Windows Paint

LoneRobot
10-11-2010, 06:52 PM
Hi john,

That looks the ticket - the only thing you might want to look at s that you're declaring the image twice. There's no need to retrieve the clipboard and pass it to a dotnet image constructor, as it is already one. You can call the picturebox's image function with the clipboard.getiimage() call to bypass this step. For the tool that you want to make it would be a good idea to keep it as optimised as possible to keep performance as high as possible.

johnwhile
10-11-2010, 08:35 PM
Hi john,

That looks the ticket - the only thing you might want to look at s that you're declaring the image twice. There's no need to retrieve the clipboard and pass it to a dotnet image constructor, as it is already one. You can call the picturebox's image function with the clipboard.getiimage() call to bypass this step. For the tool that you want to make it would be a good idea to keep it as optimised as possible to keep performance as high as possible.
sorry but DotNet for me is a esoteric things and i don't understand very well.
Do you mean : ?
on ChList selected index do
(
chanel = index
if TGA!=undefined then
(
btnCreate.caption = "create_ch:" + chanel as string
setclipboardBitmap TGA[index]
clipboardClass = dotNetClass "System.Windows.Forms.Clipboard"
dnPictureBox.image = dotnetObject "System.Drawing.Image" (clipboardClass.getImage())
)
)

LoneRobot
10-11-2010, 09:15 PM
hi john,

pretty much, you just don't need the image constructor. if you see what each function returns, you'll see that you can pass the dotnet bitmap from the clipboard to the picturebox image property.

clipboardClass = dotNetClass "Clipboard"
dotNetClass:System.Windows.Forms.Clipboard
b = bitmap 50 50 color:red
BitMap:
setclipboardBitmap b
true
clipboardClass.containsimage()
true
img = clipboardClass.getImage()
dotNetObject:System.Drawing.Bitmap
show img
.Flags : <System.Int32>, read-only
.FrameDimensionsList : <System.Guid[]>, read-only
.Height : <System.Int32>, read-only
.HorizontalResolution : <System.Single>, read-only
.Palette : <System.Drawing.Imaging.ColorPalette>
.PhysicalDimension : <System.Drawing.SizeF>, read-only
.PixelFormat : <System.Drawing.Imaging.PixelFormat>, read-only
.PropertyIdList : <System.Int32[]>, read-only
.PropertyItems : <System.Drawing.Imaging.PropertyItem[]>, read-only
.RawFormat : <System.Drawing.Imaging.ImageFormat>, read-only
.Size : <System.Drawing.Size>, read-only
.Tag : <System.Object>
.VerticalResolution : <System.Single>, read-only
.Width : <System.Int32>, read-only
true

rollout u "" width:162 height:162
(
local clipboardClass = dotNetClass "Clipboard"

dotnetcontrol pb1 "picturebox" pos:[6,5] width:150 height:122
button btn1 "Bitmap > Image" pos:[6,134] width:149 height:22

on u open do pb1.sizemode = pb1.sizemode.CenterImage

on btn1 pressed do
(
b = bitmap 50 50 color:red
setclipboardBitmap b
pb1.image = if clipboardClass.containsimage() then clipboardClass.getImage()
)
)
createdialog u



so in your case, you could use

(
chanel = index
if TGA!=undefined then
(
btnCreate.caption = "create_ch:" + chanel as string
setclipboardBitmap TGA[index]
clipboardClass = dotNetClass "Clipboard"
dnPictureBox.image = if clipboardClass.containsimage() then clipboardClass.getImage()
)
)

johnwhile
10-12-2010, 07:12 AM
thanks a lot !!
Now I will try to edit the images (zoom, palette, etc ...) and I will ask you other things =)

johnwhile
10-14-2010, 02:14 PM
Ok, now i have tried to create a zoom, the idea is preserve the original Bitmap (TGA[n]) and paint only a new Bitmap with reside dimension.
But now, how i can change the view with scrool bar ? and you think is a good way of my script to build a similar-Paint tool or i must build other version ?

-- TGA array = #(Bitmap ,Bitmap , ... )
Local clipboardClass = dotNetClass "Clipboard"
Local Chanel= 1
Local ZoomFactor = 1

rollout PathRollout "PathFinding Editor" width:512 height:440
(
dotNetControl dnPictureBox "pictureBox" pos:[0,0] width:392 height:408

fn mesh_filter obj = superclassof obj == GeometryClass
fn resizeImageDisplayed zf =
(
format "image = % x %\n" dnPictureBox.image.Width dnPictureBox.image.Height
TGAzoom = bitmap (TGA[chanel].width * ZoomFactor) (TGA[chanel].height * ZoomFactor)
copy TGA[chanel] TGAzoom
setclipboardBitmap TGAzoom
dnPictureBox.image = if clipboardClass.containsimage() then clipboardClass.getImage()
)
bitmap paintPath "MaxScript Bmp" pos:[424,304] width:80 height:80
button btnDraw "PaintObj" pos:[416,272] width:48 height:24 enabled:false
pickbutton btnPick "Add" pos:[464,272] width:40 height:24 --filter:mesh_filter
dropdownList ChList "Show by channel" pos:[416,8] width:88 height:40 items:#("no-channel")
button btnCreate "<create>" pos:[416,56] width:64 height:16 enabled:false
listbox lbxPlaneList "Object Used" pos:[416,88] width:88 height:12
progressBar ProgBar "ProgressBar" pos:[408,393] width:104 height:15
button btnZoomUp "Zoom[+]" pos:[280,408] width:56 height:24
button btnZoomDown "Zoom[-]" pos:[336,408] width:56 height:24

on btnZoomUp pressed do
(
ZoomFactor*=2.0
resizeImageDisplayed ZoomFactor
)
on btnZoomDown pressed do
(
ZoomFactor/=2.0
resizeImageDisplayed ZoomFactor
)
on PathRollout open do
(
dnPictureBox.backColor=(dotNetClass "system.drawing.color").gray
dnPictureBox.Dock = dotNetClass "DockStyle.Fill"
dnPictureBox.BorderStyle = dotNetClass "BorderStyle.FixedSingle"
dnPictureBox.SizeMode = dotNetClass "PictureBoxSizeMode.Zoom"

dnVScrollBar = dotNetObject "VScrollBar"
dnHScrollBar = dotNetObject "HScrollBar"
dnPictureBox.Controls.AddRange #(dnVScrollBar,dnHScrollBar)
--
dnVScrollBar.Dock = dotNetClass "DockStyle.Right"
dnVScrollBar.Location = dotNetObject "Drawing.Point" (392-16) 0
dnVScrollBar.size = dotNetObject "Drawing.Size" 16 392
--
dnHScrollBar.Dock = dotNetClass "DockStyle.Bottom"
dnHScrollBar.Location = dotNetObject "Drawing.Point" 0 392
dnHScrollBar.size = dotNetObject "Drawing.Size" (392-16) 16

print dnPictureBox.Bottom
print dnPictureBox.Right

)
on btnDraw pressed do
(
if paintPath.bitmap!= undefined then
(
thePlane[chanel].material = Standard diffusemap:(bitmapTexture filename:(getFileName chanel))
showTextureMap thePlane[chanel].material true
)
else messageBox "Invalid : no bitmap image loaded !"
)
on btnPick picked obj do
(
ListArray = for i=1 to lbxPlaneList.items.count where (getNodeByName lbxPlaneList.items[i])!=undefined collect lbxPlaneList.items[i]
lbxPlaneList.items = ListArray
if obj!=undefined then
(
thePlane[chanel] = obj
btnDraw.enabled = true
)
append ListArray obj.name
lbxPlaneList.items = ListArray
)
on ChList selected index do
(
chanel = index
if TGA!=undefined then
(
isEnabled = true
btnCreate.caption = "create_ch:" + chanel as string
setclipboardBitmap TGA[index]
dnPictureBox.image = if clipboardClass.containsimage() then clipboardClass.getImage()
--if isChecked do zooming 10.0
)
)
on btnCreate pressed do
(
img = TGA[chanel]
setTempBmpFile img chanel
obj =plane realWorldMapSize:false width:( img.width*2) length:( img.height*2) widthsegs:1 lengthsegs:1 transform:(matrix3 [-1,0,0] [0,1,0] [0,0,1] [0,0,0]) name =("channel_" + ch as string)
obj.material = Standard diffusemap: (bitmapTexture filename:(getFileName chanel))
showTextureMap obj.material true
thePlane[chanel] = obj
)
)
createDialog PathRollout menu:theMenu
)

johnwhile
10-15-2010, 07:46 PM
i make a little experiments but when i try to sroll the scroll bars the bitmap are demaged...
rollout PathRollout "PathFinding Editor" width:512 height:440
(
dotNetControl dnPictureBox "pictureBox" pos:[0,0] width:392 height:392
dotNetControl dnVScrollBar "VScrollBar" pos:[392,0] width:16 height:392
dotNetControl dnHScrollBar "HScrollBar" pos:[0,392] width:392 height:16
fn mesh_filter obj = superclassof obj == GeometryClass
fn moveImage =
(
dnPictureBox.Left = -dnHScrollBar.Value
dnPictureBox.Top = -dnVScrollBar.Value
dnPictureBox.Update()
)
fn resizeImageDisplayed zf =
(
img = TGA[chanel]
pbWidth = dnPictureBox.Width
pbHeight = dnPictureBox.Height
newWidth = img.width * ZoomFactor
newHeight = img.height * ZoomFactor

newTGA = bitmap newWidth newHeight
copy img newTGA
setclipboardBitmap newTGA
dnPictureBox.image = if clipboardClass.containsimage() then clipboardClass.getImage()


dnVScrollBar.Maximum = newWidth-pbWidth
dnHScrollBar.Maximum = newHeight-pbHeight

--format "large:% ; small:% ; max:%\n" dnVScrollBar.LargeChange dnVScrollBar.SmallChange dnVScrollBar.Maximum
)
bitmap paintPath "MaxScript Bmp" pos:[424,304] width:80 height:80
button btnDraw "PaintObj" pos:[416,272] width:48 height:24 enabled:false
pickbutton btnPick "Add" pos:[464,272] width:40 height:24 --filter:mesh_filter
--filter:mesh_filter
dropdownList ChList "Show by channel" pos:[416,8] width:88 height:40 items:#("no-channel")
button btnCreate "<create>" pos:[416,56] width:64 height:16 enabled:false
listbox lbxPlaneList "Object Used" pos:[416,88] width:88 height:12
progressBar ProgBar "ProgressBar" pos:[408,393] width:104 height:15
button btnZoomUp "Zoom[+]" pos:[280,408] width:56 height:24
button btnZoomDown "Zoom[-]" pos:[336,408] width:56 height:24

on dnVScrollBar ValueChanged EventArgs do
(
--format "Vscrool.Value=%\n" dnVScrollBar.value
moveImage()
)
on dnHScrollBar ValueChanged EventArgs do
(
--format "Hscrool.Value=%\n" dnHScrollBar.value
moveImage()
)
on PathRollout open do
(
dnPictureBox.backColor=(dotNetClass "system.drawing.color").gray

)
on btnDraw pressed do
(
if paintPath.bitmap!= undefined then
(
thePlane[chanel].material = Standard diffusemap:(bitmapTexture filename:(getFileName chanel))
showTextureMap thePlane[chanel].material true
)
else messageBox "Invalid : no bitmap image loaded !"
)
on btnPick picked obj do
(
ListArray = for i=1 to lbxPlaneList.items.count where (getNodeByName lbxPlaneList.items[i])!=undefined collect lbxPlaneList.items[i]
lbxPlaneList.items = ListArray
if obj!=undefined then
(
thePlane[chanel] = obj
btnDraw.enabled = true
)
append ListArray obj.name
lbxPlaneList.items = ListArray
)
on ChList selected index do
(
chanel = index
if TGA!=undefined then
(
isEnabled = true
btnCreate.caption = "create_ch:" + chanel as string
setclipboardBitmap TGA[index]
dnPictureBox.image = if clipboardClass.containsimage() then clipboardClass.getImage()
--if isChecked do zooming 10.0
)
)
on btnCreate pressed do
(
img = TGA[chanel]
setTempBmpFile img chanel
obj =plane realWorldMapSize:false width:( img.width*2) length:( img.height*2) widthsegs:1 lengthsegs:1 transform:(matrix3 [-1,0,0] [0,1,0] [0,0,1] [0,0,0]) name =("channel_" + ch as string)
obj.material = Standard diffusemap: (bitmapTexture filename:(getFileName chanel))
showTextureMap obj.material true
thePlane[chanel] = obj
)
on btnZoomUp pressed do
(
ZoomFactor*=2.0
resizeImageDisplayed ZoomFactor
)
on btnZoomDown pressed do
(
ZoomFactor/=2.0
resizeImageDisplayed ZoomFactor
)
)
createDialog PathRollout menu:theMenu
)

CGTalk Moderation
10-15-2010, 07:46 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.