如何使用C#将图像从二进制文件获取到ASP.NET中的图像控件 [英] How to get image from binary to my image control in ASP.NET using C#

查看:60
本文介绍了如何使用C#将图像从二进制文件获取到ASP.NET中的图像控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Byte[] bytes = null;
                string text = this.lblId.Text;
                string str18 = this.FileUploadFrontImageR.FileName;
                if (this.FileUploadFrontImageR.HasFile)
                {
                    string filename = FileUploadFrontImageR.PostedFile.FileName;
                    string str20 = text + str18;
                    string filePath = Path.GetFileName(filename);
                    Stream fs = FileUploadFrontImageR.PostedFile.InputStream;
                    BinaryReader br = new BinaryReader(fs);
                    bytes = br.ReadBytes((Int32)fs.Length);
                    ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
                    connection3 = new SqlConnection(this.strConnectionstring);
                    connection3.Open();
                    SqlCommand cmdddd = new SqlCommand("Update TBL_PRODUCTDETAILS Set Picfront = @Picfront where ID = '" + text + "' ", connection3);
                    cmdddd.Parameters.Add("@Picfront", SqlDbType.Binary).Value = bytes;
                    cmdddd.ExecuteNonQuery();
                }





我的尝试:



i根据我的知识做了所有事情,但没有在我的图像控件中获取图像



What I have tried:

i have doing all things as per my knowledge but not getting the image in my image control

推荐答案

你的代码中没有任何内容处理图像,存储在SQL中的数据只是原始字节数据。您可以通常的方式从SQL读取数据并将其转换为图像:

There is nothing in your code that has anything to do with images, and the data stored in SQL is just raw byte data. You can read the data from SQL in the usual way and convert it to an image:
MemoryStream ms = new MemoryStream(bytes);
Image myImage = Image.FromStream(ms);

你可以以任何你认为必要的方式使用Image。

You can them use the Image in any way you deem necessary.


这篇关于如何使用C#将图像从二进制文件获取到ASP.NET中的图像控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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