乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      圖片轉(zhuǎn)化為二進(jìn)制數(shù)據(jù),并顯示出來(lái)

       orion360doc 2011-06-26

      圖片轉(zhuǎn)化為二進(jìn)制數(shù)據(jù),并顯示出來(lái)

      2009-12-04 17:32:29|  分類: 默認(rèn)分類 |  標(biāo)簽:圖片轉(zhuǎn)化為二進(jìn)制數(shù)據(jù)     字號(hào): 訂閱

      1.將Image圖像文件存入到數(shù)據(jù)庫(kù)中

             我們知道數(shù)據(jù)庫(kù)里的Image類型的數(shù)據(jù)是"二進(jìn)制數(shù)據(jù)",因此必須將圖像文件轉(zhuǎn)換成字節(jié)數(shù)組才能存入數(shù)據(jù)庫(kù)中.

      要這里有關(guān)數(shù)據(jù)的操作略寫,我將一些代碼段寫成方法,方便直接調(diào)用.

      //根據(jù)文件名(完全路徑)
      public byte[] SetImageToByteArray(string fileName)
          {
              FileStream fs = new FileStream(fileName, FileMode.Open);
              int streamLength = (int)fs.Length;
              byte[] image = new byte[streamLength];
              fs.Read(image, 0, streamLength);
              fs.Close();
              return image;
          }

      //另外,在ASP.NET中通過FileUpload控件得到的圖像文件可以通過以下方法
      public byte[] SetImageToByteArray(FileUpload FileUpload1)
          {
              Stream stream = FileUpload1.PostedFile.InputStream;
              byte[] photo = new byte[FileUpload1.PostedFile.ContentLength];
              stream.Read(photo, 0, FileUpload1.PostedFile.ContentLength);
              stream.Close();
              return photo;
          }


      2.從SQL Server數(shù)據(jù)庫(kù)讀取Image類型的數(shù)據(jù),并轉(zhuǎn)換成bytes[]或Image圖像文件



      //要使用SqlDataReader要加載using System.Data.SqlClient命名空間
      //將數(shù)據(jù)庫(kù)中的Image類型轉(zhuǎn)換成byte[]
              public byte[] SetImage(SqlDataReader reader)
              {
                  return (byte[])reader["Image"];//Image為數(shù)據(jù)庫(kù)中存放Image類型字段
              }

      //將byte[]轉(zhuǎn)換成Image圖像類型
      //加載以下命名空間using System.Drawing;/using System.IO;
      using System.Data.SqlClient;*/
              public Image SetByteToImage(byte[] mybyte)
              {
                 Image image;
                   MemoryStream mymemorystream = new MemoryStream(mybyte,0, mybyte.Length);
                 image = Image.FromStream(mymemorystream);
                 return image;
              } 

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多