public JsonResult SelectImgJson() { String id = Request["id"]; List <ImageModel> list = new List <ImageModel>(); if (!(id == null || id.Equals(""))) { list.Add(ImgService.selectImgById(Convert.ToInt64(id))); } else { DefaultConfig config = setConfig(); if (Request["limit"] != null) { config.limit = Convert.ToInt32(Request["limit"]); } if (config.order == StaticVal.Order.ORDER_BY_RANDOM) { list.AddRange(ImgService.random(config)); } else { list.Add(ImgService.selectImg(config)); } } DataTool.addHis("json", IPAddress(), list); return(Json(list, JsonRequestBehavior.AllowGet)); }
// GET: Main public ActionResult Index() { DefaultConfig con = new DefaultConfig(); con.fileSize = Convert.ToInt64(1.5 * 1024.0 * 1024.0); con.limit = 1; ViewBag.sss = con.fileSize; ViewBag.img = ImgService.random(con)[0].Kid; ViewBag.sum = DataTool.getSum(); ViewBag.count = DataTool.getCount(1); return(View()); }
public void SelectImgPng( ) { DefaultConfig config = new DefaultConfig(); String id = Request["id"]; List <ImageModel> list = new List <ImageModel>(); if (!(id == null || id.Equals(""))) { list.Add(ImgService.selectImgById(Convert.ToInt64(id))); } else { config = setConfig(); if (config.order == StaticVal.Order.ORDER_BY_RANDOM) { list.AddRange(ImgService.random(config)); } else { list.Add(ImgService.selectImg(config)); } } DataTool.addHis("png", IPAddress(), list[0].Kid); string pathh = "C:\\Onedrive\\OneDrive - ITBYCX\\pmcdn\\" + Convert.ToInt32(list[0].Kid) / 1000 + "\\" + list[0].Kid + getExt(list[0].File_url); FileStream fs = new FileStream(pathh, FileMode.Open);//可以是其他重载方法 byte[] byData = new byte[fs.Length]; fs.Read(byData, 0, byData.Length); fs.Close(); if (getExt(list[0].File_url).Equals(".png")) { Response.ContentType = "image/png"; Response.BinaryWrite(byData); } else { Response.ContentType = "image/jpeg"; Response.BinaryWrite(byData); } }