国产99久久精品_欧美日本韩国一区二区_激情小说综合网_欧美一级二级视频_午夜av电影_日本久久精品视频

最新文章專題視頻專題問(wèn)答1問(wèn)答10問(wèn)答100問(wèn)答1000問(wèn)答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
問(wèn)答文章1 問(wèn)答文章501 問(wèn)答文章1001 問(wèn)答文章1501 問(wèn)答文章2001 問(wèn)答文章2501 問(wèn)答文章3001 問(wèn)答文章3501 問(wèn)答文章4001 問(wèn)答文章4501 問(wèn)答文章5001 問(wèn)答文章5501 問(wèn)答文章6001 問(wèn)答文章6501 問(wèn)答文章7001 問(wèn)答文章7501 問(wèn)答文章8001 問(wèn)答文章8501 問(wèn)答文章9001 問(wèn)答文章9501
當(dāng)前位置: 首頁(yè) - 科技 - 知識(shí)百科 - 正文

asp.net mvc 從數(shù)據(jù)庫(kù)中讀取圖片的實(shí)現(xiàn)代碼

來(lái)源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-27 22:43:13
文檔

asp.net mvc 從數(shù)據(jù)庫(kù)中讀取圖片的實(shí)現(xiàn)代碼

asp.net mvc 從數(shù)據(jù)庫(kù)中讀取圖片的實(shí)現(xiàn)代碼:首先是創(chuàng)建一個(gè)類,繼承于ActionResult,記住要引用System.Web.Mvc命名空間,如下: 代碼如下:public class ImageResult : ActionResult { public ImageFormat ContentType { get; set; } public Image image
推薦度:
導(dǎo)讀asp.net mvc 從數(shù)據(jù)庫(kù)中讀取圖片的實(shí)現(xiàn)代碼:首先是創(chuàng)建一個(gè)類,繼承于ActionResult,記住要引用System.Web.Mvc命名空間,如下: 代碼如下:public class ImageResult : ActionResult { public ImageFormat ContentType { get; set; } public Image image

首先是創(chuàng)建一個(gè)類,繼承于ActionResult,記住要引用System.Web.Mvc命名空間,如下:
代碼如下:

public class ImageResult : ActionResult
{
public ImageFormat ContentType { get; set; }
public Image image { get; set; }
public string SourceName { get; set; }
public ImageResult(string _SourceName, ImageFormat _ContentType)
{
this.SourceName = _SourceName;
this.ContentType = _ContentType;
}
public ImageResult(Image _ImageBytes, ImageFormat _ContentType)
{
this.ContentType = _ContentType;
this.image = _ImageBytes;
}
public override void ExecuteResult(ControllerContext context)
{
context.HttpContext.Response.Clear();
context.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
if (ContentType.Equals(ImageFormat.Bmp)) context.HttpContext.Response.ContentType = "image/bmp";
if (ContentType.Equals(ImageFormat.Gif)) context.HttpContext.Response.ContentType = "image/gif";
if (ContentType.Equals(ImageFormat.Icon)) context.HttpContext.Response.ContentType = "image/vnd.microsoft.icon";
if (ContentType.Equals(ImageFormat.Jpeg)) context.HttpContext.Response.ContentType = "image/jpeg";
if (ContentType.Equals(ImageFormat.Png)) context.HttpContext.Response.ContentType = "image/png";
if (ContentType.Equals(ImageFormat.Tiff)) context.HttpContext.Response.ContentType = "image/tiff";
if (ContentType.Equals(ImageFormat.Wmf)) context.HttpContext.Response.ContentType = "image/wmf";
if (image != null)
{
image.Save(context.HttpContext.Response.OutputStream, ContentType);
}
else
{
context.HttpContext.Response.TransmitFile(SourceName);
}
}
}

然后在 Controller類中創(chuàng)建一個(gè)Action.如下:
代碼如下:

public ActionResult GetPicture(int id)
{
ICategory server = new CategoryServer();
byte[] buffer = server.getCategoryPicture(id);
if (buffer != null)
{
MemoryStream stream = new MemoryStream(buffer);
System.Drawing.Image image = System.Drawing.Image.FromStream(stream);
ImageResult result = new ImageResult(image, System.Drawing.Imaging.ImageFormat.Jpeg);
return result;
}
return View();
}

這樣就可以顯示圖片了。
下面幾種方法可以顯示已經(jīng)存在的圖片
方法一:
代碼如下:

using System.IO;
public FileResult Image() {
string path = Server.MapPath("/Content/Images/Decorative/");
string filename = Request.Url.Segments[Request.Url.Segments.Length - 1].ToString();
// Uss Path.Combine from System.IO instead of StringBuilder.
string fullPath = Path.Combine(path, filename);
return(new FileResult(fullPath, "image/jpeg"));
}

方法二:
代碼如下:

public ActionResult Image(string id)
{
var dir = Server.MapPath("/Images");
var path = Path.Combine(dir, id + ".jpg");
return base.File(path, "image/jpg");
}

方法三:
代碼如下:

[AcceptVerbs(HttpVerbs.Get)]
[OutputCache(CacheProfile = "CustomerImages")]
public FileResult Show(int customerId, string imageName)
{
var path = string.Concat(ConfigData.ImagesDirectory, customerId, @"\", imageName);
return new FileStreamResult(new FileStream(path, FileMode.Open), "image/jpeg");
}

這三種都可以顯示已經(jīng)存在的圖片并且我認(rèn)為第三種方法可以修改為從數(shù)據(jù)庫(kù)中讀取圖片顯示。

聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

文檔

asp.net mvc 從數(shù)據(jù)庫(kù)中讀取圖片的實(shí)現(xiàn)代碼

asp.net mvc 從數(shù)據(jù)庫(kù)中讀取圖片的實(shí)現(xiàn)代碼:首先是創(chuàng)建一個(gè)類,繼承于ActionResult,記住要引用System.Web.Mvc命名空間,如下: 代碼如下:public class ImageResult : ActionResult { public ImageFormat ContentType { get; set; } public Image image
推薦度:
標(biāo)簽: 圖片 實(shí)現(xiàn) 代碼
  • 熱門焦點(diǎn)

最新推薦

猜你喜歡

熱門推薦

專題
Top
主站蜘蛛池模板: 精品免费在线 | 国产欧美在线观看一区二区 | 国产欧美精品区一区二区三区 | 国产97视频| 成人看免费一级毛片 | 福利视频欧美一区二区三区 | 亚洲欧美久久精品一区 | 国产99在线观看 | 日韩欧美大陆 | 国产一区二区福利久久 | 国外欧美一区另类中文字幕 | 亚洲伊人天堂 | 久久精品国内一区二区三区 | 国产亚洲综合成人91精品 | 国产精品久久久久久久毛片 | 成人毛片在线观看 | 国产精品久久久久久一区二区三区 | 国产a国产片 | 制服丝袜中文字幕在线 | 欧美精品福利 | 夜色毛片永久免费 | 国内高清久久久久久久久 | 日韩精品第一页 | 在线亚洲精品 | 成人国产精品视频 | 欧美日韩高清在线观看 | 欧美成人精品一区二区三区 | 国产精品久久久久久久久久免费 | 又粗又硬又大又深又爽动态图 | 亚洲精品国产自在久久出水 | 亚洲韩精品欧美一区二区三区 | 亚洲日韩精品欧美一区二区 | 欧美一区二区三区在线播放 | 日韩欧美在线免费观看 | 亚洲欧美视频 | 亚洲欧美日韩国产综合高清 | 午夜欧美视频 | 成人爽a毛片在线视频 | 亚洲 欧美 中文 日韩欧美 | 欧美亚洲国产精品 | 国产一精品一aⅴ一免费 |