Jump to content

Screenshot Program

- - - - -

  • Please log in to reply
7 replies to this topic

#1
Myvision

Myvision

    Newbie

  • Members
  • Pip
  • 6 posts
Hi,

Anyone knows how to make a screen shot program in Visual Basics, PHP, etc.
A screen shot program like this Instantly Snap and Share Screenshots.

Basically the screen shot program will have 4 buttons or so.

Full Screen Snap
Fixed Region Snap
Active Window Snap

and

Save Image
-----------------

Here is just a vb tutorial that I found here, it works but is not what I am looking for.


Posted Image


The Code for Button 1(Take a ScreenShot ) is


 Dim bounds As Rectangle

        Dim screenshot As System.Drawing.Bitmap

        Dim graph As Graphics

        bounds = Screen.PrimaryScreen.Bounds

        screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)

        graph = Graphics.FromImage(screenshot)

        graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)

        PictureBox1.Image = screenshot


and for the button 2 ( SAVE ) is


  Dim savefiledialog1 As New SaveFileDialog

        Try

            savefiledialog1.Title = "Save File"

            savefiledialog1.FileName = "*.bmp"

            savefiledialog1.Filter = "Bitmap |*.bmp"

            If savefiledialog1.ShowDialog() = DialogResult.OK Then

                PictureBox1.Image.Save(savefiledialog1.FileName, System.Drawing.Imaging.ImageFormat.Bmp)

            End If

        Catch ex As Exception 'Do Nothing

        End Try

Tutorial Link: http://forum.codecal...nshot-tool.html
By: mendin


Thank you.

#2
Simonxz

Simonxz

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts
I did a similar project in C# not long ago, it lets you crop an image of the desktop, here's the code for the image capture, maybe it'll help you.

https://github.com/S...CaptureImage.cs

#3
LuthfiHakim

LuthfiHakim

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 765 posts
In this tutorial: http://forum.codecal...elphi-code.html I had explained how to capture screen in Windows environment. Although the codes is in Delphi/Pascal, but since I also explained the theory behind them (including which windows APIs to use), I believe it will be very easy to convert to other language.

  • Full Screen Snap
    Fully explained in the tutorial
  • Fixed Region Snap
    Just capture the whole screen and then crop or copy the region to other bitmap.
  • Active Window Snap
    Instead of using Win API GetDesktopWindows, use GetForegroundWindow to get to the currently active window and follow the rest of the tutorial.

Enjoy!

#4
Myvision

Myvision

    Newbie

  • Members
  • Pip
  • 6 posts

Simonxz said:

I did a similar project in C# not long ago, it lets you crop an image of the desktop, here's the code for the image capture, maybe it'll help you.

https://github.com/S...CaptureImage.cs

Thank you for the reply unfortunately I am getting this error when I compile the code:

Posted Image

Is it possible to add a crop image button to the program above. So it will have 3 buttons: Take Screen Shot, Crop Image, Save. thx

#5
Myvision

Myvision

    Newbie

  • Members
  • Pip
  • 6 posts
Sorry guys I am really new to programming, well at school I am currently in grade 10. Learning c++ and Java, I also can work with php, html.. Just really new to visual basics.

#6
Myvision

Myvision

    Newbie

  • Members
  • Pip
  • 6 posts

LuthfiHakim said:

In this tutorial: http://forum.codecal...elphi-code.html I had explained how to capture screen in Windows environment. Although the codes is in Delphi/Pascal, but since I also explained the theory behind them (including which windows APIs to use), I believe it will be very easy to convert to other language.

  • Full Screen Snap
    Fully explained in the tutorial
  • Fixed Region Snap
    Just capture the whole screen and then crop or copy the region to other bitmap.
  • Active Window Snap
    Instead of using Win API GetDesktopWindows, use GetForegroundWindow to get to the currently active window and follow the rest of the tutorial.

Enjoy!

Sorry I am just really new and have no idea what Delphi/Pascal is but thx so much for the reply and taking ur time to write all that.

#7
Simonxz

Simonxz

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts
I adapted it for you


using System.Drawing;

using System.Drawing.Imaging;

using System.Reflection;

using System.Resources;

using System.Threading;

using System.Windows.Forms;

using System.IO;


namespace YourNamespace

{

    public class CaptureImage : Form

    {

        private bool bHaveMouse;

        private Point ptOriginal = new Point();

        private Point ptLast = new Point();

        private Rectangle selection;

        private PictureBox pictureBox;


        public CaptureImage()

        {

            Cursor = Cursors.Cross;

            FormBorderStyle = FormBorderStyle.None;

            Text = "Capture Image";

            WindowState = System.Windows.Forms.FormWindowState.Maximized;

            KeyPress += new KeyPressEventHandler(CaptureImageKeyPress);


            pictureBox = new PictureBox();

            pictureBox.Image = CaptureScreen();

            pictureBox.Dock = DockStyle.Fill;

            pictureBox.MouseDown += new MouseEventHandler(PictureBoxMouseDown);

            pictureBox.MouseMove += new MouseEventHandler(PictureBoxMouseMove);

            pictureBox.MouseUp += new MouseEventHandler(PictureBoxMouseUp);

            Controls.Add(pictureBox);


            SetStyle(ControlStyles.DoubleBuffer, true);

            SetStyle(ControlStyles.AllPaintingInWmPaint, true);

            SetStyle(ControlStyles.ResizeRedraw, true);

            SetStyle(ControlStyles.UserPaint, true);

            SetStyle(ControlStyles.SupportsTransparentBackColor, true);

        }


        private Bitmap CaptureScreen()

        {

            Thread.Sleep(100);

            Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);

            Graphics graphics = Graphics.FromImage(bitmap);

            graphics.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);

            return bitmap;

        }


        private void DrawRectangle(Point p1, Point p2)

        {

            p1 = PointToScreen(p1);

            p2 = PointToScreen(p2);

            if (p1.X < p2.X)

            {

                selection.X = p1.X;

                selection.Width = p2.X - p1.X;

            }

            else

            {

                selection.X = p2.X;

                selection.Width = p1.X - p2.X;

            }

            if (p1.Y < p2.Y)

            {

                selection.Y = p1.Y;

                selection.Height = p2.Y - p1.Y;

            }

            else

            {

                selection.Y = p2.Y;

                selection.Height = p1.Y - p2.Y;

            }

            ControlPaint.DrawReversibleFrame(selection, Color.Black, FrameStyle.Dashed);

        }


        private void PictureBoxMouseDown(object sender, MouseEventArgs e)

        {

            bHaveMouse = true;

            ptOriginal.X = e.X;

            ptOriginal.Y = e.Y;

            ptLast.X = -1;

            ptLast.Y = -1;

        }


        private void PictureBoxMouseMove(object sender, MouseEventArgs e)

        {

            Point ptCurrent = new Point(e.X, e.Y);

            if (bHaveMouse)

            {

                if (ptLast.X != -1)

                    DrawRectangle(ptOriginal, ptLast);

                ptLast = ptCurrent;

                DrawRectangle(ptOriginal, ptCurrent);

            }

        }


        private void PictureBoxMouseUp(object sender, MouseEventArgs e)

        {

            if (selection.Width != 0 && selection.Height != 0)

            {

                Bitmap bitmap = pictureBox.Image as Bitmap;

                Close();

                FileStream fileStream = File.Create("image.png");

                fileStream.Flush();

                fileStream.Close();

                bitmap.Clone(selection, bitmap.PixelFormat).Save("image.png");

            }

        }


        private void CaptureImageKeyPress(object sender, KeyPressEventArgs e)

        {

            if (e.KeyChar == (char)27) //Esc

                Close();

        }

    }

}


This will create an image and save it in the .exe's directory

#8
CrazyVB

CrazyVB

    Newbie

  • Members
  • PipPip
  • 20 posts
Hi, Simonxz
1 week ago I started to make a screenshot program, I named it "Screen Picture 1.0", yesterday I finished it, so you san se the script and all here:
>HERE<
It is as a solution, i made it in VB 2010 express, I think it works in 2008 or 06 too. Hope it helps.

CrazyVB




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users