日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

图片image和byte处理,fileupload上传图片

發布時間:2023/12/31 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 图片image和byte处理,fileupload上传图片 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

--
這是通過瀏覽某圖片,把他存放到數據庫中
string?filename?=?txt_filename.Text;
????????
string?filecomment?=?txt_filecomment.Text;
????????
string?SlaveFileName?=?FileUpload1.PostedFile.FileName;
????????
byte[]?FileContent_img?=?null;
????????DateTime?UploadTime?
=?DateTime.Now.Date;

????????
string?id?=?lbl_id.Text;
????????RemoteRule?remoteRule?
=?(RemoteRule)GetRemoteingObjectByType(typeof(RemoteRule),?"remoterule");
????????DataSet?ds?
=?new?DataSet();
????????
if?(id?==?"")
????????
{
????????????ds?
=?remoteRule.GetRuleByID(-1);
????????????DataRow?dr?
=?ds.Tables[0].NewRow();
????????????
if?(SlaveFileName?!=?"")
????????????
{
????????????????
//讀取所上傳的文件的二進制流
????????????????HttpPostedFile?file1?=?FileUpload1.PostedFile;
????????????????
int?filelength?=?Convert.ToInt32(file1.InputStream.Length);
????????????????FileContent_img?
=?new?byte[filelength];
????????????????file1.InputStream.Read(FileContent_img,?
0,?filelength);//這里所說的二進制流表現為什么樣
????????????}

????????????
else
????????????
{
????????????????SlaveFileName?
=?null;
????????????}


????????????dr[
"FileName_ch"]?=?filename;
????????????dr[
"FileDesc_ch"]?=?filecomment;
????????????dr[
"SlaveFileName_ch"]?=?SlaveFileName;
????????????dr[
"FileContent_img"]?=?FileContent_img;
????????????dr[
"UploadUser_ch"]?=?this.SystemModuleSettings.UserManage.CurrUserInfo["RealName"].ToString();
????????????dr[
"UploadTime_dt"]?=?UploadTime;
????????????ds.Tables[
0].Rows.Add(dr);
????????????
string?result?=?remoteRule.InsRule(ds);
????????????
if?(result?==?"")
????????????
{
????????????????Response.Write(
"?<script>alert('插入不成功')?</script>");
????????????}

????????????
else
????????????
{
????????????????
if?(result?!=?"f")
????????????????
{
????????????????????Response.Write(
"?<script>alert('插入成功')?</script>");
????????????????????ViewState[
"PageState"]?=?"edit";
????????????????????lbl_id.Text?
=?result.Substring(result.IndexOf(",")?+?1);
????????????????????setControlsValue();
????????????????}

????????????????
else
????????????????
{
????????????????????Response.Write(
"?<script>alert('插入不成功')?</script>");
????????????????}

????????????}

????????}
?
--
顯示圖片的

byte[]?Image_img?=?(byte[])ds_image.Tables[0].Rows[0]["Image_im"];
????????????????????????????
if?(Image_img.Length?==?0)
????????????????????????????????
return;
????????????????????????????
int?filelength?=?Image_img.Length;
????????????????????????????
string?imageName?=?ds_image.Tables[0].Rows[0][1].ToString()?+?"1"?+?".jpg";
????????????????????????????
string?myUrl?=?HttpContext.Current.Server.MapPath(this.Request.ApplicationPath)?+?@"\TempDownLoad\"?+?imageName;
????????????????????????????FileStream?fs?
=?new?FileStream(myUrl,?FileMode.OpenOrCreate);
????????????????????????????BinaryWriter?w?
=?new?BinaryWriter(fs);
????????????????????????????w.BaseStream.Write(Image_img,?
0,?filelength);
????????????????????????????w.Flush();
????????????????????????????w.Close();

????????????????????????????Image1.ImageUrl?
=?Context.Request.ApplicationPath?+?"/TempDownLoad/"?+?imageName;
????????????????????????????Bitmap?bitmap?
=?new?Bitmap(myUrl);
????????????????????????????Image1.Width?
=?bitmap.Width;
????????????????????????????Image1.Height?
=?bitmap.Height;?

轉載于:https://www.cnblogs.com/virusswb/archive/2008/05/22/1205030.html

總結

以上是生活随笔為你收集整理的图片image和byte处理,fileupload上传图片的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。