Notifications
Clear all

[Closed] Load image from memory into picturBox

 PEN

So I have

dotNetControl pic "system.windows.forms.pictureBox" width:100 height:100

And I can load an image from a file but not sure if or how to go about it from memory maybe starting with bitMap, something like…

pic.image=bitmap 100 100 color:blue

Any sugestions?

9 Replies
 PEN

I think that I have to use the setPixel method. Works just the same as doing it with bitMap in Max really.

 PEN

I’m trying to recreate the bitmap joy stick control using system.windows.forms.pictureBox, all is going well except it is slow. im currently doing something like what is below. the bitMap is b and I’m setting the pixel using setPixel then just setting the image property of the control to the bitmap. It doesn’t flash like imgTag but it is far slower. Again, any suggestions?

	fn boxControl control:undefined width:100 height:100 pos:[0,0]=
	(

		for i = 0 to (width-1) do 
		(
			b.SetPixel i pos.y c.red
		)
		for i = 0 to (height-1) do 
		(
			b.SetPixel pos.x i c.black
		)

		control.image=b
	)
1 Reply
 PEN
(@pen)
Joined: 2 years ago

Posts: 0

Edit: I should mention I’m calling this from the on mouseMove handler.

 PEN

Also another thing that I tried is to work with the .image property directly by using the setPixel method but nothing happens. Doesn’t complain but I don’t see the changes.

Also is there a fast way to clear the image?

Forgive me, I know nuuuuthing about using .net from inside 3ds, but is there an approach based on this msdn link?

      Which translates roughly as:

          theBitmap = dotNetObject "system.drawing.bitmap" 100 100 
          
          theGraphicsClass =  dotNetClass "System.Drawing.Graphics"
          theGraphics = theGraphicsClass.FromImage theBitmap 
          
          dotNetColor = dotNetClass "system.drawing.Color" 
          theColor = dotNetColor.FromArgb 150 150 200
          
          theBrush = dotNetObject "system.drawing.SolidBrush" theColor 
          
          theGraphics.FillRectangle theBrush 0 0 100 100
          
          rollout testPbox "testPbox" height:110 width:110 
          (
      	dotNetControl pic "system.windows.forms.pictureBox" width:100 height:10 align:#center
       
      	on pic mousedown arg do 
      	(
          	   pic.image = theBitmap 
      	)	
          )
          createdialog test escapeEnable:true
          
      ... and similar access to all the other system.drawing.graphics methods, thereafter
 PEN

Ah thanks, Hadn’t seen the brush type stuff.

Interesting thing if any one is interested. When I’m calling my draw function from the mouseMove event the drawing isn’t taking place if the mouse is moving to quickly. So to get around this I have add a timer that I use to call the drawing, I don’t get the flicker that I did with the imgTag and it is fast now. I wonder what is causing the bitmap not to draw when using the mouseMove event?

 PEN

I’m using System.Drawing.Bitmap and saving it to the drive. How to I release it from memory? I need to currently close Max to do that. Looks like it is hanging around on me.

With the same resevations as earlier about calling from 3ds, I’m pretty sure yourBitmap.dispose() [font=Verdana]will force .net to release [/font]yourBitmap’[font=Verdana]s resources[/font][font=Verdana], (leaving the variable in an unusable state).

…re the interesting thing, a possibility: if you’re depending on the mousemove event x & y to ‘pick up’ the joystick (i.e. be within a certain range of the last x & y to move it) then it could get ahead of the target, mousemove events being flushed during the redraw. If this is the problem, you would normally use the mousedown to check the proximity, and go into a ‘drawing’ state if close enough. Redraw on mousemove if in that state (without checking proximity), and leave the drawing state on mouseup. This probably ain’t it, you’re already doing this.
[/font]

 PEN

I’ll try the dispose and see what happens.

As for the other issue I don’t think that is affecting it. I’ll play with it more another day but right now using a timer is working great. One mouse down a set a group of variables by reference and a flag to go ahead and draw and it is working smoothly.