如何显示来自Oracle Blob数据的图像 [英] how to display image from oracle blob data

查看:283
本文介绍了如何显示来自Oracle Blob数据的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hii,
我试图在.net Windows应用程序中显示来自oracle10g的Blob数据类型的图像.
我正在使用文件流获取图像,但是当我为显示图像设置蒸汽对象时,它显示错误(无法访问关闭的文件).

我的代码如下.

Hii,
i am trying to display image from Blob datatype of oracle10g in .net windows application.
i am using filestream to get the image but the when i set the steam object for display image it show the error (Cannot access a closed file).

My code is below.

OracleConnection con = new OracleConnection("Data Source=localhost;uid=test;pwd=test;");
            con.Open();
            try
            {
                OracleCommand cmd = new OracleCommand("Select Token_no,Photo from party_photo where token_no=8629", con);
                // Writes the BLOB to a file (*.bmp).
                FileStream stream;
                // Streams the BLOB to the FileStream object.
                BinaryWriter writer;

                // Size of the BLOB buffer.
                int bufferSize = 100;
                // The BLOB byte[] buffer to be filled by GetBytes.
                byte[] outByte = new byte[bufferSize];
                // The bytes returned from GetBytes.
                long retval;
                // The starting position in the BLOB output.
                long startIndex = 0;

                // The publisher id to use in the file name.
                string token_no = "";

                OracleDataReader reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess);
                while (reader.Read())
                {
                    //token_no = reader.GetString(0);
                    token_no = Convert.ToString(reader[0]);
                    stream = new FileStream("Photo" + token_no + ".bmp", FileMode.OpenOrCreate, FileAccess.Write);
                    writer = new BinaryWriter(stream);
                    startIndex = 0;
                    retval = reader.GetBytes(1, startIndex, outByte, 0, bufferSize);
                    while (retval == bufferSize)
                    {
                        writer.Write(outByte);
                        writer.Flush();

                        startIndex += bufferSize;
                        retval = reader.GetBytes(1, startIndex, outByte, 0, bufferSize);

                    }
                    writer.Write(outByte, 0, (int)retval - 1);
                    writer.Flush();

                    //stream.Write(outByte, 0, (int)retval = 1);
                    writer.Close();
                    pictureBox1.Image  = Image.FromStream(stream);
                    stream.Close();
                    
                }
                reader.Close();
                



            }
            catch (Exception error)
            {
                MessageBox.Show(error.Message, "", MessageBoxButtons.OK);
            }
            finally
            {
                con.Close();
            }



请帮助我解决这个问题.


谢谢



Please help me to short out this problem.


Thanks

推荐答案

您在这里

修复链接
无法访问已关闭的文件 [ ObjectDisposedException-无法访问关闭的文件 [ ^ ]
ObjectDisposedException-无法访问关闭的文件[已解决] [ ^ ]
无法访问已关闭的文件– ASP.NET中的FileUpload [ ^ ]

从Oracle读取BLOB或向Oracle写入BLOB
使用C#.NET DataSet和DataReader
[ ^ ]
使用C#.Net将图像插入Oracle数据库的Blob字段中/从Blob字段中检索图像 [ ^ ]
Oracle BLOB数据类型和C# [ ^ ]
Here you go

Fix links
Cannot access a closed file[^]
ObjectDisposedException - Cannot Access a Closed File[^]
ObjectDisposedException - Cannot access a closed file[Solved][^]
cannot access a closed file – FileUpload in ASP.NET[^]

Read / Write BLOBs from / to Oracle
using C# .NET DataSet and DataReader
[^]
Insert /retrieve an image into/ from a blob field in Oracle database using C#.Net[^]
Oracle BLOB data type and C#[^]


切换到 ODAC [ ^ ]可能一个好主意,因为MS已弃用其oracle ado.net驱动程序.

您还将获得更适合于检索oracle blob类型的功能.

最好的问候
Espen Harlinn
Switching to ODAC[^] is probably a good idea, as MS has deprecated their oracle ado.net driver.

You''ll also get access to functionality that is better suited for retreiving oracle blob types.

Best regards
Espen Harlinn


这篇关于如何显示来自Oracle Blob数据的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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