16,016,501 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View .NET questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Deepurs (Top 44 by date)
Deepurs
25-May-11 2:27am
View
Windows Forms
Deepurs
16-May-11 5:21am
View
i need to draw rectangle on image.
Deepurs
16-May-11 4:28am
View
i can draw rectangle on a mouse click. But not able to delete...
Deepurs
16-May-11 1:50am
View
someone plz help me...
Deepurs
13-May-11 7:42am
View
Thank u
Deepurs
13-May-11 7:10am
View
its saving both text and lines now, but a small part image is getting cropped at the bottom when i open the saved image. Why??
Deepurs
13-May-11 6:14am
View
I can save only image with lines if i use my method and image with text at the bottom of the image if i use your method. How do i save both lines and text??
Deepurs
13-May-11 6:03am
View
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "JPEG Files(*.jpg)|*.jpg";
Bitmap orgImg = new Bitmap(resized.Width, resized.Height);
pictureBox1.DrawToBitmap(orgImg, pictureBox1.Bounds);
if (sfd.ShowDialog() == DialogResult.OK)
orgImg.Save(sfd.FileName);
Am saving this way, as am drawing lines on the image using pictureBox_paint.
Deepurs
13-May-11 5:43am
View
am not able to save those contents :(
Deepurs
13-May-11 5:12am
View
Thank you :) working!!
Deepurs
13-May-11 4:59am
View
am stretching the image like this..
Image source = Image.FromFile(openFileDialog1.FileName);
Image resized = new Bitmap(source, pictureBox1.Size);
pictureBox1.Image = resized;
then also its not working
Deepurs
13-May-11 4:39am
View
I need to stretch the image to fit the pictureBox size while loading. I tired with your code, not able add text at the bottom of the image :(
Deepurs
13-May-11 4:38am
View
Deleted
I need to stretch the image to fit the pictureBox size while loading. I tired with your code, not able add text at the bottom of the image :(
Deepurs
13-May-11 4:03am
View
I want the info to be stored at the bottom of the image. Just like a status bar.
Deepurs
13-May-11 3:47am
View
Am getting information from first form and display those info in the second form where i load the image. So there is no way to save image along with statusstrip contents??
Deepurs
13-May-11 1:30am
View
how do i update the range in foreach loop??
Deepurs
12-May-11 5:15am
View
Thanks... its working fine now :)
Deepurs
12-May-11 4:38am
View
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
Deepurs
12-May-11 4:30am
View
Am stretching the image to the pictureBox size.
Deepurs
12-May-11 4:17am
View
still not working... :( someone plz guide me
Deepurs
12-May-11 0:56am
View
yes am streching the imageto fit the pictureBox size...
Deepurs
11-May-11 7:14am
View
still my circles are drawn much away from the clicked point :(
Deepurs
11-May-11 6:55am
View
I have already tried with the character. But could get the exact output. Please guide me in the other way i.e., draw circle and 2 lines with swapped co ordinates.
Deepurs
11-May-11 6:31am
View
Sometimes I need to draw Cross i.e., X also. So in general, i change the 'str' value according to the requirement.
Deepurs
11-May-11 0:50am
View
Am trying to draw a small circle on the image with a mouse click. But the circle is drawn away from the mouse clicked point. here is my code.
private void pictureBox1_MouseClick(object sender, MouseEventArgs e1)
{
string str = "O";
if ((e1.Button & MouseButtons.Left) == MouseButtons.Left)
{
Bitmap b = (Bitmap)pictureBox1.Image;
pictureBox1.Image = b;
Graphics g = Graphics.FromImage(b);
p = new Point(e1.X, e1.Y);
Pen p3 = new Pen(Color.Red, 1);
this.Text = p.ToString();
SizeF sizef = g.MeasureString(str, Font);
f = new Font(new FontFamily("Times New Roman"), 10);
g.DrawString(str, f, Brushes.Red, ((p.X)), ((p.Y)));
}
pictureBox1.Invalidate();
}
Deepurs
10-May-11 8:05am
View
its working perfectly... thanks :)
Deepurs
10-May-11 6:58am
View
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace TestLine
{
public partial class Form1 : Form
{
bool imageOpened = false;
int imght, imgwd, xmid, ymid;
int[] xLines;
int[] yLines;
int selectedLineIndex;
bool xline = false;
bool yline = false;
int xdist, ydist;
int x,y;
public Form1()
{
InitializeComponent();
imght = pictureBox1.Height;
imgwd = pictureBox1.Width;
xmid = (imgwd) / 2;
ymid = (imght) / 2;
xLines = new int[] { xmid, xmid / 2 };
yLines = new int[] { ymid, ymid / 2 };
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
if (openFileDialog1.ShowDialog() != DialogResult.Cancel)
{
// Display the image in the PictureBox.
pictureBox1.Image = Image.FromFile(openFileDialog1.FileName);
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
// Display the Resolution of a loaded image in a status bar
//imgSizeStatusLabel.Text = "" + pictureBox1.Width + "x" + pictureBox1.Height + "";
}
imageOpened = true;
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
if (imageOpened == true)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "JPEG Files(*.jpg)|*.jpg";
Bitmap orgImg = new Bitmap(pictureBox1.Width, pictureBox1.Height);
pictureBox1.DrawToBitmap(orgImg, pictureBox1.Bounds);
if (sfd.ShowDialog() == DialogResult.OK)
orgImg.Save(sfd.FileName);
}
else
MessageBox.Show("No image to save");
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
//find the closest line from the current mouse position
int xminDistance = int.MaxValue;
int yminDistance = int.MaxValue;
selectedLineIndex = 0;
for (x = 0; x < xLines.Length; x++)
{
xdist = Math.Abs(e.X - xLines[x]);
if (xdist < xminDistance)
{
xminDistance = xdist;
//selectedLineIndex = x;
}
}
for (y = 0; y < yLines.Length; y++)
{
ydist = Math.Abs(e.Y - xLines[y]);
if (ydist < yminDistance)
{
yminDistance = ydist;
//selectedLineIndex = y;
}
}
if (xminDistance < yminDistance)
{
xline = true;
}
else if (yminDistance < xminDistance)
{
yline = true;
}
if (xline)
{
selectedLineIndex = x;
}
else if (yline)
{
selectedLineIndex = y;
}
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
foreach (int x in xLines)
{
//draw the line
e.Graphics.DrawLine(Pens.Red, x, 0, x, pictureBox1.Height);
}
foreach (int y in yLines)
{
//draw the line
e.Graphics.DrawLine(Pens.Red, 0, y, pictureBox1.Width, y);
}
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if ((MouseB
Deepurs
10-May-11 6:58am
View
am getting array out of bounds expection at lines
xLines[selectedLineIndex] = e.X;
yLines[selectedLineIndex] = e.Y;
Deepurs
10-May-11 6:57am
View
Deleted
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace TestLine
{
public partial class Form1 : Form
{
bool imageOpened = false;
int imght, imgwd, xmid, ymid;
int[] xLines;
int[] yLines;
int selectedLineIndex;
bool xline = false;
bool yline = false;
int xdist, ydist;
int x,y;
public Form1()
{
InitializeComponent();
imght = pictureBox1.Height;
imgwd = pictureBox1.Width;
xmid = (imgwd) / 2;
ymid = (imght) / 2;
xLines = new int[] { xmid, xmid / 2 };
yLines = new int[] { ymid, ymid / 2 };
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
if (openFileDialog1.ShowDialog() != DialogResult.Cancel)
{
// Display the image in the PictureBox.
pictureBox1.Image = Image.FromFile(openFileDialog1.FileName);
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
// Display the Resolution of a loaded image in a status bar
//imgSizeStatusLabel.Text = "" + pictureBox1.Width + "x" + pictureBox1.Height + "";
}
imageOpened = true;
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
if (imageOpened == true)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "JPEG Files(*.jpg)|*.jpg";
Bitmap orgImg = new Bitmap(pictureBox1.Width, pictureBox1.Height);
pictureBox1.DrawToBitmap(orgImg, pictureBox1.Bounds);
if (sfd.ShowDialog() == DialogResult.OK)
orgImg.Save(sfd.FileName);
}
else
MessageBox.Show("No image to save");
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
//find the closest line from the current mouse position
int xminDistance = int.MaxValue;
int yminDistance = int.MaxValue;
selectedLineIndex = 0;
for (x = 0; x < xLines.Length; x++)
{
xdist = Math.Abs(e.X - xLines[x]);
if (xdist < xminDistance)
{
xminDistance = xdist;
//selectedLineIndex = x;
}
}
for (y = 0; y < yLines.Length; y++)
{
ydist = Math.Abs(e.Y - xLines[y]);
if (ydist < yminDistance)
{
yminDistance = ydist;
//selectedLineIndex = y;
}
}
if (xminDistance < yminDistance)
{
xline = true;
}
else if (yminDistance < xminDistance)
{
yline = true;
}
if (xline)
{
selectedLineIndex = x;
}
else if (yline)
{
selectedLineIndex = y;
}
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
foreach (int x in xLines)
{
//draw the line
e.Graphics.DrawLine(Pens.Red, x, 0, x, pictureBox1.Height);
}
foreach (int y in yLines)
{
//draw the line
e.Graphics.DrawLine(Pens.Red, 0, y, pictureBox1.Width, y);
}
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if ((MouseB
Deepurs
10-May-11 6:29am
View
Its working fine if i have only vertical lines. I included horizontal lines also in the same manner. But when i drag any line, both horizontal and vertical lines are moved.
Deepurs
10-May-11 5:33am
View
Thanks a ton :)
Deepurs
10-May-11 5:25am
View
One last question, When i do pictureBox1.Image = null; for clearing the pictureBox...only image is getting cleared, Not the lines :(
Deepurs
10-May-11 5:22am
View
Thank you so much. It works perfectly :) Sorry for my mistakes. Thanks again
Deepurs
10-May-11 5:03am
View
How to use the extended pictureBox in my code? Sorry am new to C#
Deepurs
10-May-11 5:01am
View
Attaching my code...am Still not able to drag.
Deepurs
10-May-11 5:01am
View
Deleted
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace TestLine
{
public partial class Form1 : Form
{
bool imageOpened = false;
int imght, imgwd, xmid, ymid;
int[] xLines;
public Form1()
{
InitializeComponent();
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
if (openFileDialog1.ShowDialog() != DialogResult.Cancel)
{
// Display the image in the PictureBox.
pictureBox1.Image = Image.FromFile(openFileDialog1.FileName);
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
// Display the Resolution of a loaded image in a status bar
//imgSizeStatusLabel.Text = "" + pictureBox1.Width + "x" + pictureBox1.Height + "";
}
imageOpened = true;
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
if (imageOpened == true)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "JPEG Files(*.jpg)|*.jpg";
Bitmap orgImg = new Bitmap(pictureBox1.Width, pictureBox1.Height);
pictureBox1.DrawToBitmap(orgImg, pictureBox1.Bounds);
if (sfd.ShowDialog() == DialogResult.OK)
orgImg.Save(sfd.FileName);
}
else
MessageBox.Show("No image to save");
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
//find the closest line from the current mouse position
int minDistance = int.MaxValue;
int selectedLineIndex = 0;
for (int k = 0; k < xLines.Length; k++)
{
int dist = Math.Abs(e.X - xLines[k]);
if (dist < minDistance)
{
minDistance = dist;
selectedLineIndex = k;
}
}
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
imght = pictureBox1.Height;
imgwd = pictureBox1.Width;
xmid = (imgwd) / 2;
ymid = (imght) / 2;
xLines = new int[] { xmid, xmid / 2 };
foreach (int x in xLines)
{
//draw the line
e.Graphics.DrawLine(Pens.Red, x, 0, x, pictureBox1.Height);
}
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if ((MouseButtons & MouseButtons.Left) != MouseButtons.Left)
return;
//find the closest line from the current mouse position
int minDistance = int.MaxValue;
int closestLineIndex = 0;
for (int k = 0; k < xLines.Length; k++)
{
int dist = Math.Abs(e.X - xLines[k]);
if (dist < minDistance)
{
minDistance = dist;
closestLineIndex = k;
}
}
//update the line position
xLines[closestLineIndex] = e.X;
//redraw the picture box
pictureBox1.Invalidate();
}
}
}
Deepurs
10-May-11 4:45am
View
am not able to drag lines :(
Deepurs
10-May-11 4:20am
View
To be more specific user should be able to drag lines on the image and save.
Deepurs
10-May-11 4:19am
View
Yes. I need manual selection of lines. User should be able to select lines just by a mouse click on that particular line. Please help. And thank you so much
Deepurs
10-May-11 4:13am
View
Deleted
And one more thing, how do i select line before dragging them?
Deepurs
10-May-11 4:13am
View
Deleted
AN done more thing, how do i select line before dragging them?
Deepurs
10-May-11 4:09am
View
Am getting error at this line --> int dist = Math.Abs(e.X - xLines[k].X);
Error 1 'int' does not contain a definition for 'X' and no extension method 'X' accepting a first argument of type 'int' could be found (are you missing a using directive or an assembly reference?)
Deepurs
4-May-11 1:50am
View
yes am trying to save the image with grids and these grids are dragable. To be more specific, its like a horizontal and vertical ruler on the image.
Deepurs
4-May-11 1:49am
View
am able to save only the image, not the grids. I feel it is refreshing every time i move the grid. I have attached the code. U can hav a look at it.
Show More