/// <summary> /// A thumbnail image is a small version of an image. /// </summary> /// <param name="code"></param> public static void CreateThumbnail(Code code) { var codeBytes = FileHelper.GetCode(code.AccountId, code.CodeId); Image codeImage = ByteArrayToImage(codeBytes); Image thumbnailImage = codeImage.GetThumbnailImage(100, 100, new Image.GetThumbnailImageAbort(ThumbnailCallback) , new IntPtr()); FileHelper.SaveThumbnail(code.AccountId, code.CodeId, ImageToByteArray(thumbnailImage)); }
public static void CreateCode(Code code) { Bitmap bmp; using (var ms = new MemoryStream(code.BackgroundImage)) { bmp = new Bitmap(ms); if (bmp.PixelFormat == PixelFormat.Format8bppIndexed) { Bitmap newBmp = new Bitmap(bmp.Width, bmp.Height, PixelFormat.Format32bppArgb); using (Graphics gfx = Graphics.FromImage(newBmp)) { gfx.DrawImage(bmp, 0, 0); } bmp = newBmp; } } string url = UrlHelper.GetUrl(code.AccountId, code.CodeId); string fileName = UrlHelper.Code62Encode(code.AccountId, code.CodeId); fileName = Path.Combine(fileName, ".png"); Bitmap image = QrCodeHelper.Draw(url, bmp, code.Rectangle); byte[] data = QrCodeHelper.ImageToByteArray(image); FileHelper.SaveCode(code.AccountId, code.CodeId, data); }
public Code UpdateCode(Code newCode) { var result = QueryStoreProcedure("UpdateCode", new Dictionary<string, object> { {"param_accountId", newCode.AccountId}, {"param_codeId", newCode.CodeId}, {"param_codeTypeId", (byte)newCode.Type}, {"param_codeRectangle", JsonConvert.SerializeObject(newCode.Rectangle)}, {"param_backgroundContentType", newCode.BackgroundContentType}, {"param_payload", JsonHelper.Serialize(newCode.Payload)}, }); if (result.Tables[0].Rows.Count > 0) { var code = new Code().FromRow(result.Tables[0].Rows[0]); if (newCode.BackgroundImage != null) { FileHelper.SaveBackground(code.AccountId, code.CodeId, code.BackgroundContentType, newCode.BackgroundImage); code.BackgroundImage = newCode.BackgroundImage; } else { code.BackgroundImage = FileHelper.GetBackground(code.AccountId, code.CodeId, code.BackgroundContentType); } return code; } return null; }
public Code GetCode(int accountId, int codeId) { var result = QueryStoreProcedure("GetCode", new Dictionary<string, object> { {"param_accountId", accountId}, {"param_codeId", codeId}, }); if (result.Tables[0].Rows.Count > 0) { var code = new Code().FromRow(result.Tables[0].Rows[0]); //code.BackgroundImage = FileHelper.GetBackground(code.AccountId, code.CodeId, code.BackgroundContentType); return code; } return null; }
public List<Code> GetCodes(int accountId) { var list = new List<Code>(); var result = QueryStoreProcedure("GetCodes", new Dictionary<string, object> { {"param_accountId", accountId}, }); if (result.Tables[0].Rows.Count > 0) { foreach (DataRow row in result.Tables[0].Rows) { var code = new Code().FromRow(row); //code.BackgroundImage = FileHelper.GetBackground(code.AccountId, code.CodeId, code.BackgroundContentType); code.Thumbnail = FileHelper.GetThumbnail(code.AccountId, code.CodeId); list.Add(code); } } return list; }
public ActionResult Place(Code code) { try { int x = (int)Math.Round(Convert.ToDouble(Request["x"].ToString())); int y = (int)Math.Round(Convert.ToDouble(Request["y"].ToString())); int width = (int)Math.Round(Convert.ToDouble(Request["width"].ToString())); int height = (int)Math.Round(Convert.ToDouble(Request["height"].ToString())); code.Rectangle = new Rectangle(x, y, width, height); code = DataAccessor.CodeRepository.UpdateCode(code); QrCodeHelper.CreateCode(code); QrCodeHelper.CreateThumbnail(code); if (!IsAuthenticated()) { CookieHelper.AddAnonymousCodeId(Request, Response, code.CodeId); } return RedirectToAction("Dashboard", "Generator"); } catch (QRBaException ex) { Danger(ex.Message); return View(code); } }
public ActionResult Select(Code code) { if (Request.Files.Count > 0) { var file = Request.Files[0]; if (file != null && file.ContentLength > 0) { if (file.ContentLength > 300 * 1024) { Danger("图片太大,无法上传。 ╮(╯▽╰)╭"); return View(); } var fileName = Path.GetFileName(file.FileName); MemoryStream target = new MemoryStream(); file.InputStream.CopyTo(target); code.BackgroundImage = target.ToArray(); code.BackgroundContentType = file.ContentType; code = DataAccessor.CodeRepository.UpdateCode(code); return View("Place", code); } else if (Request["sample_id"] != null && Request["sample_id"].ToString() != "0") { var sampleId = Convert.ToInt32(Request["sample_id"].ToString()); var fileName = string.Format("background_sample_{0}.jpg", sampleId); code.BackgroundImage = FileHelper.GetFile(fileName); code.BackgroundContentType = "image/jpeg"; code = DataAccessor.CodeRepository.UpdateCode(code); return View("Place", code); } } return View(); }