Try this
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 LineOnImage
{
public partial class Form1 : Form
{
Bitmap bmOriginal;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
drawImage();
}
public void drawImage()
{
Image img = Image.FromFile("kpk.bmp");
bmOriginal = new Bitmap(img.Width,img.Height);
Graphics g = Graphics.FromImage(bmOriginal);
g.DrawImage(img, 0, 0);
pictureBox1.Image = bmOriginal;
img.Dispose();
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
int w = pictureBox1.Width / 2;
int h = pictureBox1.Height ;
e.Graphics.DrawLine(Pens.Red, w, 0, w, h);// this will draw a line on picturebox only - not bmOriginal
}
}
}
To draw on bmOriginal, you need to create graphics as above
Graphics g = Graphics.FromImage(bmOriginal);
g.DrawLine(As above);
and if you want to you can save the bitmap
bmOriginal.Save("whatever.bmp", System.Drawing.Imaging.ImageFormat.Bmp);