新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论SVG, GML, X3D, VRML, VML, XAML, AVALON, Batik等基于XML的图形技术,以及有关GIS的应用。
    [返回] 中文XML论坛 - 专业的XML技术讨论区XML.ORG.CN讨论区 - 高级XML应用『 SVG/GML/VRML/X3D/XAML 』 → 怎样把存在数据库的图片数据<binary>转化成ImageBox可以有的 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 3007 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: 怎样把存在数据库的图片数据<binary>转化成ImageBox可以有的 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     feiniao_21 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:3
      积分:83
      门派:XML.ORG.CN
      注册:2005/3/15

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给feiniao_21发送一个短消息 把feiniao_21加入好友 查看feiniao_21的个人资料 搜索feiniao_21在『 SVG/GML/VRML/X3D/XAML 』的所有贴子 引用回复这个贴子 回复这个贴子 查看feiniao_21的博客楼主
    发贴心情 怎样把存在数据库的图片数据<binary>转化成ImageBox可以有的

    SqlCommand cmd;
       cmd = new SqlCommand("INSERT INTO photodata (ID, data) " +
        "VALUES (@CustomerID, @CompanyName)", cnn);

       cmd.Parameters.Add("@CustomerID", SqlDbType.Int, 5);
       cmd.Parameters.Add("@CompanyName", SqlDbType.Image, 69812);
       cmd.Parameters[0].Value= 1;
       cmd.Parameters[1].Value=b;     

    byte[]    b=(byte[])dr["data"];
    怎样把 b 变成 bt=new Bitmap();bitmap()构造函数可以用的??
    Stream 类型!

    兄弟帮忙啊,小弟感激不尽!!


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/5/14 17:07:00
     
     edison1024 帅哥哟,离线,有人找我吗?
      
      
      等级:大二(研究C++)
      文章:55
      积分:292
      门派:XML.ORG.CN
      注册:2005/1/31

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给edison1024发送一个短消息 把edison1024加入好友 查看edison1024的个人资料 搜索edison1024在『 SVG/GML/VRML/X3D/XAML 』的所有贴子 引用回复这个贴子 回复这个贴子 查看edison1024的博客2
    发贴心情 
    这是MSDN的例子。以后要养成查帮助的习惯哦。

    SqlConnection pubsConn = new SqlConnection("Data Source=localhost;Integrated Security=SSPI;Initial Catalog=pubs;");
    SqlCommand logoCMD = new SqlCommand("SELECT pub_id, logo FROM pub_info", pubsConn);

    FileStream fs;                          // Writes the BLOB to a file (*.bmp).
    BinaryWriter bw;                        // Streams the BLOB to the FileStream object.

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

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

    // Open the connection and read data into the DataReader.
    pubsConn.Open();
    SqlDataReader myReader = logoCMD.ExecuteReader(CommandBehavior.SequentialAccess);

    while (myReader.Read())
    {
      // Get the publisher id, which must occur before getting the logo.
      pub_id = myReader.GetString(0);  

      // Create a file to hold the output.
      fs = new FileStream("logo" + pub_id + ".bmp", FileMode.OpenOrCreate, FileAccess.Write);
      bw = new BinaryWriter(fs);

      // Reset the starting byte for the new BLOB.
      startIndex = 0;

      // Read the bytes into outbyte[] and retain the number of bytes returned.
      retval = myReader.GetBytes(1, startIndex, outbyte, 0, bufferSize);

      // Continue reading and writing while there are bytes beyond the size of the buffer.
      while (retval == bufferSize)
      {
        bw.Write(outbyte);
        bw.Flush();

        // Reposition the start index to the end of the last buffer and fill the buffer.
        startIndex += bufferSize;
        retval = myReader.GetBytes(1, startIndex, outbyte, 0, bufferSize);
      }

      // Write the remaining buffer.
      bw.Write(outbyte, 0, (int)retval - 1);
      bw.Flush();

      // Close the output file.
      bw.Close();
      fs.Close();
    }

    // Close the reader and the connection.
    myReader.Close();
    pubsConn.Close();

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/5/16 9:23:00
     
     feiniao_21 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:3
      积分:83
      门派:XML.ORG.CN
      注册:2005/3/15

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给feiniao_21发送一个短消息 把feiniao_21加入好友 查看feiniao_21的个人资料 搜索feiniao_21在『 SVG/GML/VRML/X3D/XAML 』的所有贴子 引用回复这个贴子 回复这个贴子 查看feiniao_21的博客3
    发贴心情 
    很感谢楼上的回答!

    我想从数据库里查到这些数据,让它直接在控件PictureBoxl里显示

    但,我不想保存那些从数据库中的<binary>数据!。


    PictureBox.Image,需要一个Image类型的数据,而,在数据库中定义的字段本来就为Image的类型!(应该说PictureBox.iImage=(Image)bytes是可以的)
    我不知道什么直接利用数据库的数据可以让PictureBox.Image可以用的!

    public void init(string url)
      {  
       try
       {
                      bmap=new Bitmap(url);
       }
       catch(Exception e)
       {
        MessageBox.Show(e.Message);

       }   
       pictureBox1.Image=(Image) bmap;
      }

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/5/17 15:57:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 SVG/GML/VRML/X3D/XAML 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/5/10 19:54:21

    本主题贴数3,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    78.125ms