c# - Problems rendering image from database byte field using WebImage -
c# - Problems rendering image from database byte field using WebImage -
i have asp.net mvc 5 app database stores photos. i'm trying read photo , resize display in staff profile.
i'm new both asp.net mvc , c#
i setup next controller not getting image display when utilize link controller in img tag.
any help appreciated.
public actionresult index(int id) { staff staff = db.stafflist.find(id); if (staff.photo != null) { var img = new webimage(staff.photo); img.resize(100, 100, true, true); var imgbytes = img.getbytes(); homecoming file(imgbytes, "image/" + img.imageformat); } else { homecoming null; } }
looking around seems there's lot of dissatisfaction webimage class , has few prominent bugs. settled on using nuget bundle called imageprocessor rather trying write own. seems inefficient me don't have improve reply right , isn't heavily used i'm going , moving on.
posting here in case else struggling similar.
public actionresult index(int id, int? height, int? width) { int h = (height ?? 325); int w = (width ?? 325); staff staff = db.stafflist.find(id); if (staff == null) { homecoming new httpnotfoundresult(); } if (staff.photo != null) { size size = new size(w, h); byte[] rawimg; using (memorystream instream = new memorystream(staff.photo)) { using (memorystream outstream = new memorystream()) { using (imagefactory imagefactory = new imagefactory()) { imagefactory.load(instream) .constrain(size) .format(format) .save(outstream); } rawimg = outstream.toarray(); } } homecoming new filecontentresult(rawimg, "image/jpeg"); } else { homecoming null; } }
c# asp.net asp.net-mvc
Comments
Post a Comment