成人午夜激情影院,小视频免费在线观看,国产精品夜夜嗨,欧美日韩精品一区二区在线播放

上傳圖片并顯示縮略圖的最簡單方法(C#)

2010-08-28 10:50:27來源:西部e網(wǎng)作者:

private void fileUpload_Click(object sender, System.EventArgs e)
       
{
            
// 模擬數(shù)據(jù)庫里取出byte[]再顯示縮略,
            
// 模擬方法:先上傳,把stream轉(zhuǎn)成byte[],再把byte[]放在stream里,再輸出

            
// 上傳
            System.IO.Stream fs = jpgUpload.PostedFile.InputStream;
            
int nBytes          = jpgUpload.PostedFile.ContentLength;
            
byte[] ByteArray    = new byte[nBytes];
            
int nBytesRead      = fs.Read(ByteArray, 0, nBytes);
            MemoryStream mBytes  
= new MemoryStream(ByteArray,0,nBytes);
            
            
// 轉(zhuǎn)為stream,處理縮略
            System.Drawing.Image _img;
            _img 
= System.Drawing.Image.FromStream(mBytes);
            System.Drawing.Image _thumbImg 
= _img.GetThumbnailImage(Convert.ToInt32(_img.Width* 0.3),Convert.ToInt32( _img.Height * 0.3),null, IntPtr.Zero);

            
// 顯示到客戶端
            Response.ContentType    = this.jpgUpload.PostedFile.ContentType;
            MemoryStream MemStream  
= new MemoryStream(); 
            _thumbImg.Save(MemStream, System.Drawing.Imaging.ImageFormat.Jpeg); 
            MemStream.WriteTo(Response.OutputStream); 
            Response.Flush();
       }
關(guān)鍵詞:C#
主站蜘蛛池模板: 桦甸市| 崇仁县| 宣威市| 枣庄市| 独山县| 丰顺县| 巢湖市| 玉门市| 开化县| 祥云县| 蕲春县| 泰州市| 错那县| 山阴县| 南宁市| 宜兰市| 信丰县| 马尔康县| 泰州市| 利津县| 桂东县| 洛隆县| 德兴市| 无棣县| 武汉市| 铜陵市| 鸡西市| 保亭| 孝感市| 翼城县| 沅陵县| 烟台市| 靖远县| 渭南市| 昭平县| 和田市| 洛隆县| 万年县| 宁都县| 黄浦区| 张家川|