在Windows应用程序中上传图像 [英] Upload images in windows application

查看:80
本文介绍了在Windows应用程序中上传图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我必须使用openDialogBox将图像上传到Windows应用程序中.有什么方法可以将图像存储在应用程序内部吗?这怎么可能?请给我有关此的任何想法.

Hi,

I have to upload images into my windows application using openDialogBox. Is there any method to store the images inside the application.? How is this possible? Please give me any idea about this.

推荐答案

上传"是什么意思?只要有许可,您就可以将图像存储在任何您喜欢的位置.我认为Windows应用程序数据区域内的文件夹是一个合理的位置,比将其存储在数据库中要容易得多.
What do you mean by ''upload'' ? You can store images anywhere you like, so long as you have permission. I''d think a folder inside the app data area of windows is a logical place, much easier than storing it in a DB.


1.使用openfiledialog 向用户询问文件.
2.过滤openfiledialog 以仅接受图像.
3.使用File.Copy功能将文件从openfiledialog打开的文件路径复制到您选择的目标路径.
1. use openfiledialog to ask the file from the user.
2. filter the openfiledialog to accept images only.
3. Use File.Copy function to copy file from openfiledialog opened filepath to your chosen destination path.


我认为存储图像的更好选择是将图像转换为byte []然后存储它在数据库中
首先打开文件
I think the better option to storing image is to convert image to byte[] then store it in Database
Open a File First
byte[] big;
private void button7_Click(object sender, EventArgs e)
        {
             OpenFD.Title = "Select Files";
            OpenFD.Filter = "Jpg|*.jpg|Jpge|*.jpge|Gif|*.gif";
            OpenFD.FileName = null;
            string fileName;
            if (OpenFD.ShowDialog() != DialogResult.Cancel)
            {
                querybuilder qu = new querybuilder();
                fileName = OpenFD.FileName;
                Object refmissing = System.Reflection.Missing.Value;
                try
                {
                     // show it to picturebox
                    pictureBox2.Load(fileName);
                     // Here get_image is a function and Big is the byte[] type
                    big = get_image(fileName);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error" + ex.Message.ToString());
                }
            }
        }


get_image函数在下面


get_image function is below

public byte[] get_image(string filePath)
        {
            FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
            BinaryReader reader = new BinaryReader(stream);
            byte[] photo = reader.ReadBytes((int)stream.Length);
            reader.Close();
            stream.Close();

            return photo;
        }


现在进行sql查询


And now make sql query

string sqlquery="insert into Tablename(id,image) values(1,@big)";
SqlParameter param = new SqlParameter("@big", SqlDbType.Binary);
    param.Value = big;


注意:-创建Sqlcommand self我没有将它包含在该解决方案中


Note:- Create Sqlcommand self I didn''t include it in that solution


这篇关于在Windows应用程序中上传图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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