如何保存图片框和状态条 [英] how to save pictureBox along with statusstripbar

查看:64
本文介绍了如何保存图片框和状态条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在将图像加载到pictureBox中,并在statusStripBar中加载该图像的一些细节;例如图像分辨率,日期和时间等,
现在,我想同时保存图像和statustripbar的内容,以便下次用户打开图像时,他/她应同时查看图像及其详细信息.

Hi
I am loading an image into a pictureBox and few details of that image in a statusStripBar; for example,image resolution,date and time etc.,
Now i want to save both image and contents of statustripbar such that next time when the user opens the image,he/she should view both image and its details.
kindly guide me.

推荐答案

您从哪里获得信息,并显示在状态行上?
因为,您可能不知道所有这些信息可能已包含在图像中-Google for EXIF,您将明白我的意思.可能您实际上不需要执行任何操作即可存储信息!

如果必须存储它,那么各种系统使用的一种方法是在每个包含图像的文件夹中保留一个小文件,并在其中保留该文件夹中所有文件的额外信息.


我希望信息存储在图像的底部.就像状态栏一样."

然后您有两个选择,两者都非常相似.
1)在图片底部写上文字,覆盖图片的一部分.
2)创建一个比原始图片稍大的新图片,并在其中写上文字.

新图像很简单:
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));
    }

在原件上绘制同样容易-无需创建新图或绘制图像.
无论哪种方式,都可以使用Image.Save方法保存它-它具有重写以指定文件格式.

像这样拉伸图像.

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);


节省了这种方式,就像使用pictureBox_paint在图像上绘制线条一样.

回复
OriginalGriff-4分钟前
和?会发生什么?

回复
Deepurs-1分钟前
如果使用我的方法,我只能保存带线的图像,如果使用您的方法,则只能在图像的底部保存带文本的图像.如何保存行和文本?"


我只是将所有这些螺栓固定在一起并进行了尝试:


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));
    }


第一次单击时,我得到了一张拉伸的图像,上面有文字和一条红线.
在第二次单击按钮时,它保存了一张拉伸的图片,其中带有文本和红线的内容作为BMP文件.
你在做什么不同?


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?


这篇关于如何保存图片框和状态条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆