如何在c#(vs)中查看数据库中的图片文件
具体的……

解决方案 »

  1.   

    读取数据库中的img类型数据到byte[],如果是winform则byte[]到stream再到image对象,否则binaryWrite直接输出到页面
      

  2.   

    WPF中使用Image控件显示数据库中图像文件的方法
    private BitmapFrame xxx(OleDbDataReader dr, string photoColumn) 

        byte[] imageByte = null; 
        int bytesCount = 0; 
        ImageSourceConverter isc = new ImageSourceConverter(); 
        // 图片文件字节流(从数据库字段或文件中获取的byte[])通过ImageSourceConverter转换为BitmapFrame后,即可设置为Image控件的Source进行显示。 
        // 通过BitmapFrame的Decoder.CodeInfo可以获得图片信息 
        BitmapFrame bitmapFrame = null; 
        object imageSource = null; 
        // 从数据库字段中读取一幅照片 
        bytesCount = (int)dr.GetBytes(dr.GetOrdinal(photoColumn), 0, null, 0, 0); 
        if (bytesCount > 0) 
        { 
            imageByte = new byte[bytesCount]; 
            bytesCount = (int)dr.GetBytes(dr.GetOrdinal(photoColumn), 0, imageByte, 0, bytesCount); 
            try 
            { 
                imageSource = isc.ConvertFrom(imageByte); 
            } 
            catch 
            { 
                imageSource = null; 
            } 
            if (imageSource != null) 
            { 
                bitmapFrame = imageSource as BitmapFrame; 
                Console.WriteLine("bitmapFrame Format:", bitmapFrame.Decoder.CodecInfo.MimeTypes); 
            } 
            else 
                bitmapFrame = null;    //转换失败,说明图片数据错误 
        } 
        //// 显示于屏幕上(线程程序需要使用Dispatcher.Invoke执行屏幕刷新) 
        //if (bitmapFrame != null) 
        //{ 
        //    Console.WriteLine("bitmapFrame Format:", bitmapFrame.Decoder.CodecInfo.MimeTypes); 
        //    image1.Dispatcher.Invoke(DispatcherPriority.Render, new ThreadStart(delegate { image1.Source = bitmapFrame; })); 
        //} 
        return bitmapFrame; 

      

  3.   

    msdn上有详细的文章:
    HOW TO:在 Visual C# 中直接将一个图片从数据库复制到 PictureBox 控件
    http://support.microsoft.com/kb/317701/zh-cn
      

  4.   

    首先要确定的是你说的数据库中的图片文件是不是图片文件的存储格式.如果是的话可以读取.不是的话就......
    然后可以查一下msdn,上面有详细的说明,要学会用msdn,很有用的.
      

  5.   

     private void button1_Click(object sender, EventArgs e)
            {
                OracleConnection ocon = new OracleConnection("Password=0000;User ID=jlrel;Data Source=arcgis;Persist Security Info=True");
                OracleDataAdapter oda = new OracleDataAdapter("select image from table", ocon);
                DataTable dt = new DataTable();
                oda.Fill(dt);
                byte[] barray = (byte[])dt.Rows[0][0];
                FileStream fs = new FileStream("E:\\temp.jpg", FileMode.Create, FileAccess.ReadWrite);
                fs.Write(barray, 0, barray.Length);
                fs.Close();
            }