[Closed] Character GUI Maker
Thank you :)
The whole app is C# it uses just a few maxscript lines... as for the screencap no prob...
Basically the easiest way to do it is to grab a whole screen, put it in PictureBox thats docked inside a borderless form that's same size as the screen then you can use box selection to grab any part of it.
You can also do it by using COM interop but there is probably no need to complicate things because this way works great.
This is how you do it....
So like i said you make a form that's borderless and dock a picturebox in it so it fills the window..
next u do...
Size res = SystemInformation.PrimaryMonitorSize; this.Size = res; pictureBox1.Size = res; pictureBox1.Location = new Point(0, 0); Bitmap screenshot; Rectangle region = Screen.AllScreens[0].Bounds; screenshot = new Bitmap(res.Width, res.Height, PixelFormat.Format32bppArgb); Graphics screenGraphics = Graphics.FromImage(screenshot); screenGraphics.CopyFromScreen(region.Left, region.Top, 0, 0, region.Size); Image img = (Image)screenshot; pictureBox1.BackgroundImage = img;
You can put this in the constructor under InitializeComponent();
This gets your primary monitor size in case you have two or more monitors you can set it up so it maybe asks you what monitor image you want to grab then sets up picture box to be the size of monitor and positions it at 0,0. After that you declare bitmap and set it the size of first monitor and just grab the screenshot and convert it to Image that you set as background image of pictureBox...
So this gives you picture of your desktop in a picturebox with the size of your monitor so basically it looks all the same and you can now draw a selection box to grab your region. That is done by using mouse down, mouse move and mouse up event args for the PictureBox.
Mouse down event arg:
if (e.Button == MouseButtons.Left) { selecting = true; selection = new Rectangle(new Point(e.X, e.Y), new Size()); selectionStartPoint = new Point(e.X, e.Y); }
So when you click your mouse down we set selecting var to true to indicate that selection is taking place, initialize new rectangle selection and take starting point in selectionStartPoint
Mouse move event arg:
if (selecting) { if (selectionStartPoint.X < e.X) { selection.X = selectionStartPoint.X; selection.Width = e.X - selectionStartPoint.X; } else { selection.X = e.X; selection.Width = selectionStartPoint.X - e.X; } if (selectionStartPoint.Y < e.Y) { selection.Y = selectionStartPoint.Y; selection.Height = e.Y - selectionStartPoint.Y; } else { selection.Y = e.Y; selection.Height = selectionStartPoint.Y - e.Y; } pictureBox1.Refresh(); }
In mouse move event we say if selecting is active set the width and height of the rectangle depending of the mouse movement and call refresh for pictureBox so the Paint method gets called and we can actually draw our rectangle.
So the paint event should look like this:
if (selecting) { Pen pen = new Pen(Color.Green, 2); pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; e.Graphics.DrawRectangle(pen, selection); e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(100, 66, 159, 255)), selection); }
Here we again check if selection is in progress by querying status of selecting var then we do the actual drawing, in order to look nicer i actually draw two rectangles one filled and slightly transparent and the other with just dashed outline so you get nice selection box.
So we click, move mouse and draw rectangle... now we need to save our region and that happens with mouse up event
if (e.Button == MouseButtons.Left) { selecting = false; pictureBox1.Refresh(); GetImage(); }
Here we check is the mouse up left mouse button then set selecting to false to indicate that selection process has finished, do the refresh of pictureBox so it redraws this time without rectangle because selecting var is now false and call GetImage() method that saves our image:
Bitmap screenshot = new Bitmap(pictureBox1.BackgroundImage); Bitmap croped = screenshot.Clone(selection, screenshot.PixelFormat); Image img = (Image)croped; pictureBox1.BackgroundImage = img; if (File.Exists(@"tmp.jpg")) { File.Delete(@"tmp.jpg"); } img.Save(@"tmp.jpg"); img.Dispose(); screenshot.Dispose(); croped.Dispose(); this.Close();
This last method is kinda adapted to my needs it creates new bitmap using as size our selection rectangle and then converts all that into Image type with this line: Image img = (Image)croped; you can then do whatever you like with it… i save it as temp file that later gets handled further in the application.
That is it… i hope it helps:)
Wow, awesome man! I’m working through it right now though and found an issue, but I figured it out.
In the line
screenshot = new Bitmap(res.Width, res.Height, PixelFormat.Format32bppArgb);
I had to do instead,
screenshot = new Bitmap(res.Width, res.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
I will keep going. But I got it taking a screenshot now at my dekstop res
I think you may have forgot a part for the selecting bit? I’m trying to figure out where/how to setup the mouse events. Maybe I’m wrong…
If you add on top
System.Drawing.Imaging;
You wont have to type all that and you will get access to enum PixelFormat
As for the mouse events i just figured you did C# before so i did not want to bother u with details.
for mouse event args you can add in your class constructor, under the InitializeComponent();
pictureBox1.MouseDown += new MouseEventHandler(pictureBox1_MouseDown); pictureBox1.MouseUp += new MouseEventHandler(pictureBox1_MouseUp); pictureBox1.MouseMove += new MouseEventHandler(pictureBox1_MouseMove);
Then you just declare your eventargs, for mouse move you would do:
void pictureBox1_MouseMove(object sender, MouseEventArgs e) { }
And so on....
Hope this gets you back on right track.
Ah ok, thanks alot man. I’ve done a little C#, but am quite new to it, sorry :P. I understand now. I will keep messing with it