//<summary>
//Generate picture
//</summary>
//<param Name= "collection" ></PARAM>
<returns></returns>
Public Filestreamresult generateimage (formcollection collection)
{
var shopid = Shopcaches.getshopinfo ();
var headimginfo = Getresourcepath (Shopid.shopid, collection["Dayinpersonnelid"], "Headfront");
var imageinfo = Getresourcepath (Shopid.shopid, collection["Inputgonghao"], "Personnobarcode");//turn to Picture type
var FilePath = Server.MapPath (string. Format ("~/ui/images/workcardpicture/{0}", Shopid.shopid));
if (! Directory.Exists (FilePath))
Directory.CreateDirectory (filePath);
Const int WIDTH = HEIGHT = n;
var fon t12b = new Font (Fontfamily.genericserif, 12.0f, fontstyle.regular);
var font20b = new Font (Fontfamily.genericserif, 15.0f, fontstyle.bold);
using (var bitmap = new Bitmap (WIDTH, HEIGHT))
{
using (Graphics garphics = graphics.fromimage (bitmap))
{ br> Garphics. Clear (Color.White);
Garphics. DrawString (Shopid.shopname, font20b, Brushes.black, 126, 10);
if (headimginfo! = null)
{
Garphics. DrawImage (Headimginfo, 38, 57, 100, 110); Photo
}
Garphics. DrawString ("Work number:" + collection["Inputgonghao"], font12b, Brushes.black, 197, 53);
Garphics. DrawString ("Name:" + collection["inputxingming"], font12b, Brushes.black, 197, 78);
Garphics. DrawString ("Position:" + collection["Inputzhiwei"], font12b, Brushes.black, 197, 103);
Garphics. DrawImage (Imageinfo, New Point (197, 151)); Barcode
Bitmap. Save (FilePath + "/" + collection["Inputgonghao"] + ". jpg");
Imageinfo.dispose ();//Release all the resources for the barcode
Garphics. Dispose ();//Release resources
Bitmap. Dispose ();//Release resources
}
}
var path = FilePath + "\ \" + collection["Inputgonghao"] + ". jpg";
Return File (New FileStream (Path, FileMode.Open), "Image/jpeg", Server.URLEncode (collection["Inputgonghao"] + ". jpg") ;
Return Json ("");
}
<summary>
Generate Picture: Get the path to the picture (local only; local no resource server)
</summary>
<param name= "Shopid" > Shop id</param>
<param name= "FileName" > The name of the image to be taken </param>
<param name= "FolderName" > folder name </param>
<returns> Picture Path </returns>
Private Image Getresourcepath (Guid shopid, String fileName, String folderName)
{
Image Headimginfo;
Const string URL = "~/ui/images";
string httpurl = Webconfig.resourceserverinformation;
Determine if there is a local
var path = Server.MapPath (string. Format ("{0}/{1}/{2}/{3}", URL, FolderName, shopid, FileName + ". jpg"));
var Httppath = string. Format ("{0}/{1}/{2}/{3}", Httpurl, FolderName, shopid, FileName + ". jpg");
if (System.IO.File.Exists (path))
{
Headimginfo = image.fromfile (path);
}
Else
{
var FilePath = Server.MapPath (string. Format ("{0}/{1}/{2}", URL, FolderName, shopid));
Local no, first download the picture down in the conversion
if (! Directory.Exists (FilePath))
Directory.CreateDirectory (FilePath);
String Dizhi = Server.MapPath (string. Format ("{0}/{1}/{2}/{3}", URL, FolderName, shopid, FileName + ". jpg"));
var webClient = new WebClient ();
Try
{
Webclient.downloadfile (Httppath, Dizhi);//download pictures on the network, save in Local
Headimginfo = Image.FromFile (Dizhi);
}
Catch
{
Headimginfo = null;
}
}
return headimginfo;
}
MVC generate images, download files (images do not exist locally, download on-line)