Solved

display grid over jpg picture

Posted on 2013-06-01
35
415 Views
Last Modified: 2013-06-16
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!
0
Comment
Question by:nobus
  • 17
  • 17
35 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
Comment Utility
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
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
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
 
LVL 91

Author Comment

by:nobus
Comment Utility
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
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
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
 
LVL 91

Author Comment

by:nobus
Comment Utility
can somebody provide a script ? or tool ?
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
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
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
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
 
LVL 91

Author Comment

by:nobus
Comment Utility
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
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
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
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
Wit the code I gave you above, you can literally create your own tool.  Visual Studio Express is free...
0
 
LVL 91

Author Comment

by:nobus
Comment Utility
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
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
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
 
LVL 91

Author Comment

by:nobus
Comment Utility
ok - i'll test it out. and post back
0
 
LVL 91

Author Comment

by:nobus
Comment Utility
ok i installed VSE - when i select new project, what to choose ?vse
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
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
 
LVL 91

Author Comment

by:nobus
Comment Utility
yes, that is what i used to do in Visual basic, some time ago (make buttons for it)
0
 
LVL 91

Author Comment

by:nobus
Comment Utility
OK I TRIED TO COPY HTE CODE? BUT I DON4T GET THE PASTE OPTION
sorry for caps
here is what i got :
vse
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
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
 
LVL 91

Author Comment

by:nobus
Comment Utility
that's what i did : hit F7 - and thats what i got
i'll try the view code option too - can be different
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
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
 
LVL 91

Author Comment

by:nobus
Comment Utility
ok here the result i got :
y
i wanted only the grid to be visible, over the jpg
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
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
 
LVL 91

Author Comment

by:nobus
Comment Utility
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
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
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
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
Comment Utility
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
 
LVL 91

Author Comment

by:nobus
Comment Utility
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
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
In Project --> Properties on the Compile Tab, make sure the "Platform" option is set to "Active (Any CPU)".
0
 
LVL 91

Author Comment

by:nobus
Comment Utility
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
 
LVL 91

Author Comment

by:nobus
Comment Utility
Idle Mind - i tested it on a fresh install, and on another XP laptop; both give the same error
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
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
 
LVL 91

Author Comment

by:nobus
Comment Utility
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
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
Right...you only need the VB version, though it won't hurt anything if you install all of them.
0
 
LVL 91

Author Closing Comment

by:nobus
Comment Utility
Idle Mind your solution is exactly what i looked for
Many thanks, also for the continued support !
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
Not a problem...hope you continue to tinker with VB.Net...
0
 
LVL 91

Author Comment

by:nobus
Comment Utility
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now