Where do you get the information from, that you display on the status line?
Because, you may not be aware that all that info is probably included as part of the image already - Google for EXIF and you will see what I mean. It may be that you don't actually need to do anything to store the info!
If you do have to store it, then one way various systems use is to keep a small file in each folder that has images, with the extra information held in there for all files in the folder.
"I want the info to be stored at the bottom of the image. Just like a status bar."
Then you have two options, both very similar.
1) Write text at the bottom of your image, overwriting part of the image.
2) Create a new image, slightly larger than the original, and write the text in that.
New image is simple:
Image myPicture = Image.FromFile(@"F:\Temp\BTC.jpg");
int integerTextHeight = 20;
Bitmap b = new Bitmap(myPicture.Width, myPicture.Height + integerTextHeight);
using (Graphics g = Graphics.FromImage(myPicture))
{
g.DrawImage(myPicture, new Point(0,0));
g.DrawString("My additional information at the bottom", myFont, Brushes.Black, new PointF(0, myPicture.Height));
}
Drawing on the original is just as easy - you don't need to create the new or draw the image.
Either way, save it using the Image.Save method - it has an override to specify the file format.
"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"
Image source = Image.FromFile(openFileDialog1.FileName);
Image resized = new Bitmap(source, pictureBox1.Size);
using (Graphics g = Graphics.FromImage(resized))
{
g.DrawString("My additional information at the bottom", myFont, Brushes.White, new PointF(0, resized.Height - 20));
}
pictureBox1.Image = resized;
Try that: text at the bottom (I used white so it showed up against my picture)
"
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.
Reply
OriginalGriff - 4 mins ago
And? What happens?
Reply
Deepurs - 1 min ago
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??"
I just bolted all this together and tried it:
private void button1_Click(object sender, EventArgs e)
{
Font myFont = new Font("Arial", 8.0F);
if (pictureBox1.Image == null)
{
Image myPicture = Image.FromFile(@"F:\Temp\BTC.jpg");
int integerTextHeight = 20;
Bitmap b = new Bitmap(myPicture.Width, myPicture.Height + integerTextHeight);
using (Graphics g = Graphics.FromImage(myPicture))
{
g.DrawImage(myPicture, new Point(0, 0));
g.DrawString("My additional information at the bottom", myFont, Brushes.Black, new PointF(0, myPicture.Height));
}
Image resized = new Bitmap(myPicture, pictureBox1.Size);
using (Graphics g = Graphics.FromImage(resized))
{
g.DrawString("My additional information at the bottom", myFont, Brushes.White, new PointF(0, resized.Height - 20));
}
pictureBox1.Image = resized;
}
else
{
Bitmap orgImg = new Bitmap(pictureBox1.Width, pictureBox1.Height);
pictureBox1.DrawToBitmap(orgImg, pictureBox1.Bounds);
orgImg.Save(@"F:\Temp\crap.bmp");
}
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawLine(Pens.Red, new Point(0, 0), new Point(pictureBox1.Width, pictureBox1.Height));
}
On the first click, I got a stretched image, with text, and a red line.
On the second click of the button it saved a stretched picture, with text and a red line as a BMP file.
What are you doing that is different?