display grid over jpg picture

Hello

does there exist a small script or program to display a grid over a picture ? it would be a tool for a painter
it should have following options :
-select # of vertical & horizontal lines to display
-select line color
-runs on all Windows versions XP and above

it should look like this :
taj
i know several programs have this option, but i don't wan to install more software

thanks!
LVL 93
nobusAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
Here's how to add a button to allow the selection of a different grid color:
Public Class Form1

    Private GridColor As Color = Color.Black

    Private WithEvents PB As New PictureBox
    Private WithEvents Rows As New NumericUpDown
    Private WithEvents Cols As New NumericUpDown
    Private WithEvents btnSelectFile As New Button
    Private WithEvents btnSelectColor As New Button

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Rows.Minimum = 2
        Cols.Minimum = 2

        Dim TLB As New TableLayoutPanel
        TLB.RowCount = 2
        TLB.RowStyles.Add(New RowStyle(SizeType.AutoSize))
        TLB.RowStyles.Add(New RowStyle(SizeType.Percent, 100))
        TLB.ColumnCount = 6
        TLB.ColumnStyles.Add(New ColumnStyle(SizeType.Percent, 20))
        TLB.ColumnStyles.Add(New ColumnStyle(SizeType.Percent, 20))
        TLB.ColumnStyles.Add(New ColumnStyle(SizeType.Percent, 20))
        TLB.ColumnStyles.Add(New ColumnStyle(SizeType.Percent, 20))
        TLB.ColumnStyles.Add(New ColumnStyle(SizeType.Percent, 20))
        TLB.ColumnStyles.Add(New ColumnStyle(SizeType.Percent, 20))

        Dim lbl As New Label
        lbl.Text = "Rows:"
        lbl.TextAlign = ContentAlignment.TopRight
        lbl.Dock = DockStyle.Bottom
        TLB.Controls.Add(lbl, 0, 0)
        TLB.Controls.Add(Rows, 1, 0)

        lbl = New Label
        lbl.Text = "Cols:"
        lbl.TextAlign = ContentAlignment.TopRight
        lbl.Dock = DockStyle.Bottom
        TLB.Controls.Add(lbl, 2, 0)
        TLB.Controls.Add(Cols, 3, 0)

        btnSelectFile.Text = "Pic"
        btnSelectFile.AutoSize = True
        btnSelectFile.Dock = DockStyle.Fill
        TLB.Controls.Add(btnSelectFile, 4, 0)

        btnSelectColor.Text = "Color"
        btnSelectColor.AutoSize = True
        btnSelectColor.Dock = DockStyle.Fill
        TLB.Controls.Add(btnSelectColor, 5, 0)

        PB.Dock = DockStyle.Fill
        PB.SizeMode = PictureBoxSizeMode.Zoom
        PB.BorderStyle = BorderStyle.FixedSingle
        TLB.Controls.Add(PB, 0, 1)
        TLB.SetColumnSpan(PB, 6)

        TLB.Dock = DockStyle.Fill
        Me.Controls.Add(TLB)
        Me.Text = "Image Grid Tool"
    End Sub

    Private Sub btnSelectFile_Click(sender As Object, e As System.EventArgs) Handles btnSelectFile.Click
        Static OFD As New OpenFileDialog
        OFD.Title = "Select an Image File"
        OFD.Filter = "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*"
        If OFD.ShowDialog = Windows.Forms.DialogResult.OK Then
            Try
                PB.Image = New Bitmap(Image.FromFile(OFD.FileName))
            Catch ex As Exception
                MessageBox.Show("File: " & OFD.FileName & vbCrLf & vbCrLf & ex.ToString, "Error Opening Image", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        End If
    End Sub

    Private Sub btnSelectColor_Click(sender As Object, e As System.EventArgs) Handles btnSelectColor.Click
        Static CD As New ColorDialog
        If CD.ShowDialog = Windows.Forms.DialogResult.OK Then
            GridColor = CD.Color
            PB.Refresh()
        End If
    End Sub

    Private Sub Rows_Cols_ValueChanged(sender As Object, e As System.EventArgs) Handles Rows.ValueChanged, Cols.ValueChanged
        PB.Refresh()
    End Sub

    Private Sub PB_SizeChanged(sender As Object, e As System.EventArgs) Handles PB.SizeChanged
        PB.Refresh()
    End Sub

    Private Sub PB_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles PB.Paint
        Using pn As New Pen(GridColor)
            Dim xValue, yValue As Integer
            For y As Integer = 1 To Rows.Value - 1
                yValue = y / Rows.Value * PB.Height
                e.Graphics.DrawLine(pn, 0, yValue, PB.Width, yValue)
            Next
            For x As Integer = 1 To Cols.Value - 1
                xValue = x / Cols.Value * PB.Width
                e.Graphics.DrawLine(pn, xValue, 0, xValue, PB.Height)
            Next
        End Using
    End Sub

End Class

Open in new window

0
 
käµfm³d 👽Commented:
does there exist a...program to display a grid over a picture ?
i don't wan to install more software
Aren't you contradicting yourself? How will users use the program if they don't install it?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You've listed "VB Script" as option.  Does this include VB.Net (or even C#)?  Both are free from Microsoft, and this would be quite easy to write.  Should the grid simply be temporary (just displayed onscreen), or should it have the option to save the file (to the same name or a new one) with the grid in it?

VS2012 Express:
http://www.microsoft.com/visualstudio/eng/products/visual-studio-express-for-windows-desktop#product-express-desktop

VS2010 Express:
http://www.microsoft.com/visualstudio/eng/downloads#d-2010-express

*Both are free but require you to register (it's a simple process).
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
nobusAuthor Commented:
kaufmed -  i'm referring to picasa, adobe, etc...or paint.net
IdleMind : it does not matter in what language it's written; and temporary is fine
are the VS versions needed for that solution? then it's not what i want

i am looking for something like a small  exe file, that runs on windows, or a small script
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Visual Studio would be needed to write and compile the solution.  Afterwards you'd have an executable that could run without Visual Studio.  You'd still need the .Net Framework installed on the computer, though, but it's on most systems already!
0
 
nobusAuthor Commented:
can somebody provide a script ? or tool ?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
This isn't really something a straight "script" could do!

Did you install Visual Studio Express?  This would allow you to create the necessary tool.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Here's a simple "grid tool"...
Image Grid Tool
Just paste this code into a standard WinForms project:
Public Class Form1

    Private WithEvents PB As New PictureBox
    Private WithEvents Rows As New NumericUpDown
    Private WithEvents Cols As New NumericUpDown
    Private WithEvents btnSelectFile As New Button

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Rows.Minimum = 2
        Cols.Minimum = 2

        Dim TLB As New TableLayoutPanel
        TLB.RowCount = 2
        TLB.RowStyles.Add(New RowStyle(SizeType.AutoSize))
        TLB.RowStyles.Add(New RowStyle(SizeType.Percent, 100))
        TLB.ColumnCount = 5
        TLB.ColumnStyles.Add(New ColumnStyle(SizeType.Percent, 20))
        TLB.ColumnStyles.Add(New ColumnStyle(SizeType.Percent, 20))
        TLB.ColumnStyles.Add(New ColumnStyle(SizeType.Percent, 20))
        TLB.ColumnStyles.Add(New ColumnStyle(SizeType.Percent, 20))
        TLB.ColumnStyles.Add(New ColumnStyle(SizeType.Percent, 20))

        Dim lbl As New Label
        lbl.Text = "Rows:"
        lbl.TextAlign = ContentAlignment.TopRight
        lbl.Dock = DockStyle.Bottom
        TLB.Controls.Add(lbl, 0, 0)
        TLB.Controls.Add(Rows, 1, 0)

        lbl = New Label
        lbl.Text = "Cols:"
        lbl.TextAlign = ContentAlignment.TopRight
        lbl.Dock = DockStyle.Bottom
        TLB.Controls.Add(lbl, 2, 0)
        TLB.Controls.Add(Cols, 3, 0)

        btnSelectFile.Text = "Image"
        btnSelectFile.AutoSize = True
        btnSelectFile.Dock = DockStyle.Fill
        TLB.Controls.Add(btnSelectFile, 4, 0)

        PB.Dock = DockStyle.Fill
        PB.SizeMode = PictureBoxSizeMode.Zoom
        PB.BorderStyle = BorderStyle.FixedSingle
        TLB.Controls.Add(PB, 0, 1)
        TLB.SetColumnSpan(PB, 5)

        TLB.Dock = DockStyle.Fill
        Me.Controls.Add(TLB)
        Me.Text = "Image Grid Tool"
    End Sub

    Private Sub btnSelectFile_Click(sender As Object, e As System.EventArgs) Handles btnSelectFile.Click
        Static OFD As New OpenFileDialog
        OFD.Title = "Select an Image File"
        OFD.Filter = "Image Files(*.BMP;*.JPG;*.GIF)|*.BMP;*.JPG;*.GIF|All files (*.*)|*.*"
        If OFD.ShowDialog = Windows.Forms.DialogResult.OK Then
            Try
                PB.Image = New Bitmap(Image.FromFile(OFD.FileName))
            Catch ex As Exception
                MessageBox.Show("File: " & OFD.FileName & vbCrLf & vbCrLf & ex.ToString, "Error Opening Image", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        End If
    End Sub

    Private Sub Rows_Cols_ValueChanged(sender As Object, e As System.EventArgs) Handles Rows.ValueChanged, Cols.ValueChanged
        PB.Refresh()
    End Sub

    Private Sub PB_SizeChanged(sender As Object, e As System.EventArgs) Handles PB.SizeChanged
        PB.Refresh()
    End Sub

    Private Sub PB_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles PB.Paint
        Dim xValue, yValue As Integer
        For y As Integer = 1 To Rows.Value - 1
            yValue = y / Rows.Value * PB.Height
            e.Graphics.DrawLine(Pens.Black, 0, yValue, PB.Width, yValue)
        Next
        For x As Integer = 1 To Cols.Value - 1
            xValue = x / Cols.Value * PB.Width
            e.Graphics.DrawLine(Pens.Black, xValue, 0, xValue, PB.Height)
        Next
    End Sub

End Class

Open in new window

0
 
nobusAuthor Commented:
thanks - but i have no project

let me rephrase my question -  is it possible to make a bat file for displaying a grid, over the picture, opened by something like Windows Photo viewer?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
As I said before:

    "This isn't really something a straight "script" could do!"

No batch file or VBScript is capable of doing this.

I think the closest you could get would be to write an HTA application:
"Introduction to HTML Applications (HTAs)"
http://msdn.microsoft.com/en-us/library/ms536496(v=vs.85).aspx
*You'd basically write a web page with access to your desktop.  I'm not a web developer, though, and it sounds like you are not a developer at all.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Wit the code I gave you above, you can literally create your own tool.  Visual Studio Express is free...
0
 
nobusAuthor Commented:
Idlemind - i'm willing to learn; but before starting, what will be the order to follow?
-install VSE
-create  a project
-insert the code
and then?  does it make an "executable" that can be run on any pc?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Create the project, insert the code, save, and then compile.  In the project folder there will be two subfolders called "bin" and "release".  The EXE will be in one of those folders depending upon which mode you are when you compiled.  For a simple app like this you can simply copy that EXE and place it anywhere you want.  As long as the .Net Framework is installed on the system it will work.
0
 
nobusAuthor Commented:
ok - i'll test it out. and post back
0
 
nobusAuthor Commented:
ok i installed VSE - when i select new project, what to choose ?vse
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You want the first one called "Windows Forms Applications".

Once it loads up, hit F7 to view the code behind the default Form1.  Copy paste the code I supplied previously over everything you see there.

Then hit F5 or press the green triangle to run the app.

If that does what you want then save it, run it again (or compile), then look in the "debug" subfolder of the "bin" folder in your projects saved location.

*Normally you wouldn't create all the controls at run-time like I did here, but that makes it easier for someone to copy/paste/run.  In a regular project you'd manually drag/drop controls from the ToolBox onto your form so you can see what it will look like.
0
 
nobusAuthor Commented:
yes, that is what i used to do in Visual basic, some time ago (make buttons for it)
0
 
nobusAuthor Commented:
OK I TRIED TO COPY HTE CODE? BUT I DON4T GET THE PASTE OPTION
sorry for caps
here is what i got :
vse
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
From my previous instructions:

    "Once it loads up, hit F7 to view the code behind the default Form1.  Copy paste the code I supplied previously over everything you see there."

You can also get to the code by Right Clicking somewhere in Form1 and selecting "View Code".
0
 
nobusAuthor Commented:
that's what i did : hit F7 - and thats what i got
i'll try the view code option too - can be different
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Maybe the hotkeys have changed in the latest Visual Studio.

Here's what you should have when you get to the code editor:
The Code behind the Form
0
 
nobusAuthor Commented:
ok here the result i got :
y
i wanted only the grid to be visible, over the jpg
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Did you click the button and select an image?

"i wanted only the grid to be visible, over the jpg "

You also wanted:

    "select # of vertical & horizontal lines to display"

We can definitely modify this to show a just the image with gridlines.  One way would to display it in another popup form that is borderless.
0
 
nobusAuthor Commented:
my apologies, i opened the jpg first
and yes it does what i want
there is only one thing i would like also change the grid color white & black would do, but if i can select others , that would be a bonus
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Yeah, we could another button in there to select the color to be used for the grids.

I'll post modified code in a bit...
0
 
nobusAuthor Commented:
ok - some feedback :
i ran the original exe file on a win 7 - 64 bit fine
on an XP - 32 bit it says that this file is no valid windows 32 application
meanwhile  - i'll also test the color version
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
In Project --> Properties on the Compile Tab, make sure the "Platform" option is set to "Active (Any CPU)".
0
 
nobusAuthor Commented:
Idle Mind - the color version works flawlessly - on the 64 bit W7 platform -thanks for that

the Project>Platform>Any cpu is checked, but :
on the XP SP3 32 bit -  i still get the "grid is no valid windows32 application" (grid is the name i gave to the project)
0
 
nobusAuthor Commented:
Idle Mind - i tested it on a fresh install, and on another XP laptop; both give the same error
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Hmmm...apparently VS2012 cannot target anything below Vista.  =\

You can use VS2010 instead:
http://www.microsoft.com/visualstudio/eng/downloads#d-2010-express
http://go.microsoft.com/?linkid=9709929
0
 
nobusAuthor Commented:
ok i made the 2010 cd - it lets me install the following :
Visual C
visual Basic
Visual C++
Visual Web developer

which one do i install? -  i suppose Visual Basic ?
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Right...you only need the VB version, though it won't hurt anything if you install all of them.
0
 
nobusAuthor Commented:
Idle Mind your solution is exactly what i looked for
Many thanks, also for the continued support !
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Not a problem...hope you continue to tinker with VB.Net...
0
 
nobusAuthor Commented:
i did a bit of Vb, and C++, but only smalll things
i am still grateful you directed me to the free downloads - i did not know about them
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.