dotNet to simulate Paint tool for Bitmap


#1

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…


#2

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.


#3

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


#4

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


#5

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.


#6

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


#7

Same, but use

lv.item.tag = dotNetMxsValue obj


#8

very thanks, this is a thing that i haven’t understood…


#9

… 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()
 )

#10

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

#11

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.


#12

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.


#13

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 )


#14

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.


#15

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


#16

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.


#17

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())
		)
	)

#18

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()
		)
	)

#19

thanks a lot !!
Now I will try to edit the images (zoom, palette, etc …) and I will ask you other things =)


#20

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
 (
 [i]	dotNetControl dnPictureBox "pictureBox" pos:[0,0] width:392 height:408[/i]
 
 	fn mesh_filter obj = superclassof obj == GeometryClass
 [i]	fn resizeImageDisplayed zf =
 	(
 		format "image = % x %
" 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()
 	)[/i]
 	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
 [i]	button btnZoomUp "Zoom[+]" pos:[280,408] width:56 height:24
 	button btnZoomDown "Zoom[-]" pos:[336,408] width:56 height:24[/i]
 	
 [i]	on btnZoomUp pressed do
 	(
 		ZoomFactor*=2.0
 		resizeImageDisplayed ZoomFactor
 	)[/i]
 [i]	on btnZoomDown pressed do
 	(
 		ZoomFactor/=2.0
 		resizeImageDisplayed ZoomFactor
 	)[/i]
 [i]	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
 
 	)[/i]
 	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
 )