public static void GenerateProcessedImage() { ImageProcessingJob jobNormal = new ImageProcessingJob(); jobNormal.Filters.Add(new FixedResizeConstraint(200, 200));//限制图片的大小,避免生成大图。如果想原图大小处理,就不用加这个Filter jobNormal.SaveProcessedImageToFileSystem(@"C:\Program Files\longCode\LongRoom\Long.Test\img\dalong.png", @"C:\Program Files\longCode\LongRoom\Long.Test\img\dalong2.png"); }
/// <summary> /// 生成缩略图 /// </summary> /// <param name="fileName"></param> public static void BuildThumbnail(string sourceFileName, string targetFileName) { ImageProcessingJob jobThumb = new ImageProcessingJob(); jobThumb.Filters.Add(new FixedResizeConstraint(20, 20)); //缩略图尺寸 jobThumb.SaveProcessedImageToFileSystem(sourceFileName, targetFileName, new BmpFormatEncoderParams()); //第一个参数可以是string文件名,也可以是流 }
private string SaveImg(byte[] imgBytes, string ext) { string md5 = CommonHelper.GetMD5(imgBytes); string path = "/upload/" + DateTime.Now.ToString("yyyy/MM/dd") + "/" + md5 + ext; //string thumbPath = "/upload/" + DateTime.Now.ToString("yyyy/MM/dd") + "/" + md5 + "_thumb" + ext; string fullPath = HttpContext.Server.MapPath("" + path); //string thumbFullPath = HttpContext.Server.MapPath("~" + thumbPath); new FileInfo(fullPath).Directory.Create(); //file.SaveAs(fullPath); //缩略图 //file.InputStream.Position = 0; //ImageProcessingJob jobThumb = new ImageProcessingJob(); //jobThumb.Filters.Add(new FixedResizeConstraint(200, 200));//缩略图尺寸 200*200 //jobThumb.SaveProcessedImageToFileSystem(file.InputStream, thumbFullPath); //水印 //file.InputStream.Position = 0; //ImageWatermark imgWatermark = new ImageWatermark(HttpContext.Server.MapPath("~/images/fb.png")); //imgWatermark.ContentAlignment = System.Drawing.ContentAlignment.BottomRight;//水印位置 //imgWatermark.Alpha = 50;//透明度,需要水印图片是背景透明的 png 图片 ImageProcessingJob jobNormal = new ImageProcessingJob(); //jobNormal.Filters.Add(imgWatermark);//添加水印 jobNormal.Filters.Add(new FixedResizeConstraint(517, 216));//限制图片的大小,避免生成 //jobNormal.SaveProcessedImageToFileSystem(file.InputStream, fullPath); jobNormal.SaveProcessedImageToFileSystem(imgBytes, fullPath); return(path); }
/// <summary> /// 生成缩略图 /// install- Package CodeCarvings.Piczard /// </summary> /// <param name="path">原图路径</param> /// <param name="path2">保存路径</param> /// <param name="newName">缩略图名称</param> public static void GetImagePro(string path, string path2, string newName) { ImageProcessingJob job = new ImageProcessingJob(); job.Filters.Add(new FixedResizeConstraint(200, 200)); job.SaveProcessedImageToFileSystem(path, path2 + @"\" + newName + ".png"); }
protected void LoadImageIntoPictureTrimmer(bool resetSelection) { // Pre-process the image ImageProcessingJob job = this.GetImagePreProcessingJob(); using (System.Drawing.Bitmap preProcessedImage = job.GetProcessedImage(SourceImageFileName)) { // Backup the previous userState PictureTrimmerUserState previousUserState = null; if (this.InlinePictureTrimmer1.ImageLoaded) { previousUserState = this.InlinePictureTrimmer1.UserState; } // Load the pre-processed image into the PictureTrimmer control this.InlinePictureTrimmer1.LoadImage(preProcessedImage, new FreeCropConstraint(null, 600, null, 600)); if (previousUserState != null) { if (resetSelection) { // Re-calculate the cropping rectangle previousUserState.Value.ImageSelection.Crop.Rectangle = null; // Re-center the image previousUserState.UIParams.PictureScrollH = null; previousUserState.UIParams.PictureScrollV = null; } // Restore the previous user state this.InlinePictureTrimmer1.UserState = previousUserState; } } }
public ActionResult PicUpload(long urlId, HttpPostedFileBase file) { string md5 = CommonHelper.GetMD5(file.InputStream); string ext = Path.GetExtension(file.FileName); string path = "/upload/" + DateTime.Now.ToString("yyyy/MM/dd") + "/" + md5 + ext; //string thumbPath = "/upload/" + DateTime.Now.ToString("yyyy/MM/dd") + "/" + md5 + "_thumb" + ext; string fullPath = HttpContext.Server.MapPath("" + path); //string thumbFullPath = HttpContext.Server.MapPath("~" + thumbPath); new FileInfo(fullPath).Directory.Create(); //file.SaveAs(fullPath); //缩略图 //file.InputStream.Position = 0; //ImageProcessingJob jobThumb = new ImageProcessingJob(); //jobThumb.Filters.Add(new FixedResizeConstraint(200, 200));//缩略图尺寸 200*200 //jobThumb.SaveProcessedImageToFileSystem(file.InputStream, thumbFullPath); //水印 //file.InputStream.Position = 0; //ImageWatermark imgWatermark = new ImageWatermark(HttpContext.Server.MapPath("~/images/fb.png")); //imgWatermark.ContentAlignment = System.Drawing.ContentAlignment.BottomRight;//水印位置 //imgWatermark.Alpha = 50;//透明度,需要水印图片是背景透明的 png 图片 ImageProcessingJob jobNormal = new ImageProcessingJob(); //jobNormal.Filters.Add(imgWatermark);//添加水印 jobNormal.Filters.Add(new FixedResizeConstraint(600, 600));//限制图片的大小,避免生成 jobNormal.SaveProcessedImageToFileSystem(file.InputStream, fullPath); return(Json(new AjaxResult { Status = "success", Data = path })); }
private ImageProcessingJob CreateJob(int imgX, int imgY) { ImageProcessingJob job = new ImageProcessingJob(); job.Filters.Add(new FixedResizeConstraint(imgX, imgY)); return(job); }
/// <summary> /// 生成带水印的图片 /// install- Package CodeCarvings.Piczard /// </summary> /// <param name="watermarkPath">水印图片路径</param> /// <param name="alpha">透明度</param> /// <param name="path">原图路径</param> /// <param name="path2">保存路径</param> /// <param name="newName">缩略图名称</param> public static void GetWatermarkImage(string watermarkPath, int alpha, string path, string path2, string newName) { ImageWatermark imgWatermark = new ImageWatermark(watermarkPath); imgWatermark.ContentAlignment = System.Drawing.ContentAlignment.BottomRight; ImageProcessingJob job = new ImageProcessingJob(); job.Filters.Add(imgWatermark); job.SaveProcessedImageToFileSystem(path, path2 + @"\" + newName + ".png"); }
//缩略图一 static void Thumbnail() { ImageProcessingJob job = new ImageProcessingJob(); job.Filters.Add(new FixedResizeConstraint(200, 200)); job.SaveProcessedImageToFileSystem(@"E:\Program\NET高级培训\NET掌上租\TEST\Image\1.jpg", @"E:\Program\NET高级培训\NET掌上租\TEST\Image\2.jpg", new JpegFormatEncoderParams()); //job.SaveProcessedImageToStream(); }
public void WaterMark() { ImageWatermark imgWatermark = new ImageWatermark(@"D:\a\sauce.png"); imgWatermark.ContentAlignment = System.Drawing.ContentAlignment.BottomRight; //水印位置 imgWatermark.Alpha = 100; //透明度,需要水印图片是背景透明的png图片 ImageProcessingJob jobNormal = new ImageProcessingJob(); jobNormal.Filters.Add(imgWatermark); //添加水印 jobNormal.Filters.Add(new FixedResizeConstraint(300, 300)); //限制图片的大小,避免生成大图。如果想原图大小处理,就不用加这个Filter jobNormal.SaveProcessedImageToFileSystem(@"D:\a\Tulips.jpg", @"D:\a\2.png"); }
public static void GenerateWatermark() { ImageWatermark imgWatermark = new ImageWatermark(@"C:\Program Files\longCode\LongRoom\Long.Test\img\star.ico"); imgWatermark.ContentAlignment = System.Drawing.ContentAlignment.BottomRight; //水印位置 imgWatermark.Alpha = 50; //透明度,需要水印图片是背景透明的png图片 ImageProcessingJob jobNormal = new ImageProcessingJob(); jobNormal.Filters.Add(imgWatermark); //添加水印 jobNormal.Filters.Add(new FixedResizeConstraint(600, 600)); //限制图片的大小,避免生成大图。如果想原图大小处理,就不用加这个Filter jobNormal.SaveProcessedImageToFileSystem(@"C:\Program Files\longCode\LongRoom\Long.Test\img\test.png", @"C:\Program Files\longCode\LongRoom\Long.Test\img\cool.png"); }
//水印 //CodeCarvings.Piczard static void ImgWaterMark() { ImageWatermark imgWatermark = new ImageWatermark(@"E:\Program\NET高级培训\NET掌上租\TEST\Image\bg.jpg"); imgWatermark.ContentAlignment = System.Drawing.ContentAlignment.BottomRight; //水印位置 imgWatermark.Alpha = 50; //透明度,需要水印图片是背景透明的png图片 ImageProcessingJob jobNormal = new ImageProcessingJob(); jobNormal.Filters.Add(imgWatermark); //添加水印 jobNormal.Filters.Add(new FixedResizeConstraint(300, 300)); //限制图片的大小,避免生成大图。如果想原图大小处理,就不用加这个Filter jobNormal.SaveProcessedImageToFileSystem(@"E:\Program\NET高级培训\NET掌上租\TEST\Image\1.jpg", @"E:\Program\NET高级培训\NET掌上租\TEST\Image\3.jpg"); }
private string SaveImg(byte[] imgBytes, string ext) { string md5 = CommonHelper.GetMD5(imgBytes); string path = "/upload/" + DateTime.Now.ToString("yyyy/MM/dd") + "/" + md5 + ext; string fullPath = HttpContext.Server.MapPath("" + path); new FileInfo(fullPath).Directory.Create(); ImageProcessingJob jobNormal = new ImageProcessingJob(); jobNormal.Filters.Add(new FixedResizeConstraint(640, 308));//限制图片的大小,避免生成 jobNormal.SaveProcessedImageToFileSystem(imgBytes, fullPath); return(path); }
public ActionResult UploadPic(int houseId, HttpPostedFileBase file) { /* * if (houseId < 5) * { * return Json(new AjaxResult { Status = "error", ErrorMsg = "id必须大于5" }); * }*/ //month月,minute string md5 = CommonHelper.CalcMD5(file.InputStream); string ext = Path.GetExtension(file.FileName); string path = "/upload/" + DateTime.Now.ToString("yyyy/MM/dd") + "/" + md5 + ext; // /upload/2017/07/07/afadsfa.jpg string thumbPath = "/upload/" + DateTime.Now.ToString("yyyy/MM/dd") + "/" + md5 + "_thumb" + ext; string fullPath = HttpContext.Server.MapPath("~" + path); //d://22/upload/2017/07/07/afadsfa.jpg string thumbFullPath = HttpContext.Server.MapPath("~" + thumbPath); new FileInfo(fullPath).Directory.Create(); //尝试创建可能不存在的文件夹 file.InputStream.Position = 0; //指针复位 //file.SaveAs(fullPath);//SaveAs("d:/1.jpg"); //缩略图 ImageProcessingJob jobThumb = new ImageProcessingJob(); jobThumb.Filters.Add(new FixedResizeConstraint(200, 200));//缩略图尺寸200*200 jobThumb.SaveProcessedImageToFileSystem(file.InputStream, thumbFullPath); file.InputStream.Position = 0;//指针复位 //水印 ImageWatermark imgWatermark = new ImageWatermark(HttpContext.Server.MapPath("~/images/watermark.jpg")); imgWatermark.ContentAlignment = System.Drawing.ContentAlignment.BottomRight; //水印位置 imgWatermark.Alpha = 50; //透明度,需要水印图片是背景透明的png图片 ImageProcessingJob jobNormal = new ImageProcessingJob(); jobNormal.Filters.Add(imgWatermark);//添加水印 jobNormal.Filters.Add(new FixedResizeConstraint(600, 600)); jobNormal.SaveProcessedImageToFileSystem(file.InputStream, fullPath); houseService.AddNewHousePic(new HousePicDTO { HouseId = houseId, Url = path, ThumbUrl = thumbPath }); CreateStaticPage(houseId);//上传了新图片或者删除图片都要重新生成html页面 return(Json(new AjaxResult { Status = "ok" })); }
/// <summary> /// 生成水印 /// </summary> /// <param name="waterFileName"></param> /// <param name="sourceFileName"></param> /// <param name="targetFileName"></param> public static void BuiildWaterMark(string waterFileName, string sourceFileName, string targetFileName) { ImageProcessingJob jobThumb = new ImageProcessingJob(); ImageWatermark imgWater = new ImageWatermark(waterFileName); imgWater.ContentAlignment = System.Drawing.ContentAlignment.BottomRight; //水印位置 imgWater.Alpha = 50; //透明度,需要水印图片是背景透明的png图片 jobThumb.Filters.Add(imgWater); //添加水印 jobThumb.Filters.Add(new FixedResizeConstraint(200, 200)); //缩略图尺寸 jobThumb.SaveProcessedImageToFileSystem(sourceFileName, targetFileName, new BmpFormatEncoderParams()); //第一个参数可以是string文件名,也可以是流 }
private async Task WorkImage(ImageProcessingJob job) { var fileHandler = new MongoDbFileHandler(_imageDbConnectionString); var sourcefile = await fileHandler.GetMessageObject <DtoImage>(job.Id); var outputfile = AddOverlay(sourcefile, job.Overlay, job.Resolution); var id = await fileHandler.SaveMessageObject(outputfile); foreach (var successor in job.Successors) { successor.Id = id; await _bus.PublishAsync(successor.GetType(), successor); } }
public static string SaveByte(Stream stream) { byte[] files = StreamToBytes(stream); string md5 = CommonHelper.GetMD5(files); string path = "/upload/" + DateTime.Now.ToString("yyyy") + "/" + md5 + ".jpeg"; string fullPath = HttpContext.Current.Server.MapPath("~" + path); new FileInfo(fullPath).Directory.Create(); //file.SaveAs(fullPath); //缩略图 ImageProcessingJob jobNormal = new ImageProcessingJob(); jobNormal.SaveProcessedImageToFileSystem(files, fullPath); return(path); }
public static string SaveImage(HttpPostedFileBase file) { string md5 = CommonHelper.GetMD5(file.InputStream); string ext = Path.GetExtension(file.FileName); string path = "/upload/" + DateTime.Now.ToString("yyyy") + "/" + md5 + ext; string fullPath = HttpContext.Current.Server.MapPath("~" + path); new FileInfo(fullPath).Directory.Create(); //file.SaveAs(fullPath); //缩略图 file.InputStream.Position = 0; ImageProcessingJob jobNormal = new ImageProcessingJob(); jobNormal.SaveProcessedImageToFileSystem(file.InputStream, fullPath); return(path); }
protected void btnProcessImage_Click(object sender, EventArgs e) { // Process the image // Get the image processing job ImageProcessingJob job = this.InlinePictureTrimmer1.GetImageProcessingJob(); // Add the filters job.Filters.Add(DefaultColorFilters.Grayscale); // Grayscale job.Filters.Add(new ImageWatermark(WatermarkImageFileName, System.Drawing.ContentAlignment.BottomRight)); // Watermark // Save the image job.SaveProcessedImageToFileSystem(SourceImageFileName, OutputImageFileName); // Display the output image this.InlinePictureTrimmer1.OnClientControlLoadFunction = "displayOutputImage"; }
public static bool SaveBase64(string file, out string res) { if (!file.Contains(";base64")) { res = "不是base64图片文件"; return(false); } string[] strs = file.Split(','); string[] formats = strs[0].Replace(";base64", "").Split(':'); string img = strs[1]; string format = formats[1]; string[] imgFormats = { "image/png", "image/jpg", "image/jpeg", "image/bmp", "IMAGE/PNG", "IMAGE/JPG", "IMAGE/JPEG", "IMAGE/BMP" }; if (!imgFormats.Contains(format)) { res = "请选择正确的图片格式,支持png、jpg、jpeg、png格式"; return(false); } string ext = "." + format.Split('/')[1]; byte[] imgBytes = null; try { imgBytes = Convert.FromBase64String(img); } catch (Exception ex) { res = "base64图片文件解码错误"; return(false); } string md5 = CommonHelper.GetMD5(imgBytes); string path = "/upload/" + DateTime.Now.ToString("yyyy") + "/" + md5 + ext; string fullPath = HttpContext.Current.Server.MapPath("~" + path); new FileInfo(fullPath).Directory.Create(); //Install-Package CodeCarvings.Piczard ImageProcessingJob jobNormal = new ImageProcessingJob(); jobNormal.SaveProcessedImageToFileSystem(imgBytes, fullPath); res = path; return(true); }
public string PicSave(HttpPostedFileBase file) { string md5 = CommonHelper.GetMD5(file.InputStream); string ext = Path.GetExtension(file.FileName); string path = "/upload/" + DateTime.Now.ToString("yyyy/MM/dd") + "/" + md5 + ext; string fullPath = HttpContext.Server.MapPath("~" + path); new FileInfo(fullPath).Directory.Create(); ImageProcessingJob jobNormal = new ImageProcessingJob(); //FixedAspectRatioCropConstraint constraint = new FixedAspectRatioCropConstraint(1.0f);//宽高比 //constraint.LimitedDimension = SizeDimension.Height;//是限制宽度还是限制高度(Height为限制高度,Width为限制宽度) //constraint.Min = 50;//最小50像素(根据LimitedDimension确定是限定宽度还是高度) //constraint.Max = 200;//最大200像素(根据LimitedDimension确定是限定宽度还是高度) jobNormal.Filters.Add(new FixedResizeConstraint(512, 512));//限制图片的大小,避免生成 jobNormal.SaveProcessedImageToFileSystem(file.InputStream, fullPath); return(path); }
public ActionResult UpImg(HttpPostedFileBase file) { string md5 = CommonHelper.GetMD5(file.InputStream); string ext = Path.GetExtension(file.FileName); string path = "/upload/" + DateTime.Now.ToString("yyyy/MM/dd") + "/" + md5 + ext; string fullPath = HttpContext.Server.MapPath("~" + path); new FileInfo(fullPath).Directory.Create(); file.InputStream.Position = 0; ImageProcessingJob jobNormal = new ImageProcessingJob(); //jobNormal.Filters.Add(new FixedResizeConstraint(750, 1334));//限制图片的大小,避免生成 jobNormal.SaveProcessedImageToFileSystem(file.InputStream, fullPath); string[] paths = { path }; return(Json(new { errno = "0", Data = paths })); }
private static void Main(string[] args) { //Console.WriteLine("123".CalcMd5()); //Console.WriteLine(CommonHelper.GenerateCaptchaCode(5)); #region 邮件发送 //using (MailMessage mailMessage = new MailMessage()) //using (SmtpClient smtpClient = new SmtpClient("smtp.163.com")) //{ // mailMessage.To.Add("*****@*****.**"); // mailMessage.To.Add("*****@*****.**"); // mailMessage.Body = "邮件正文"; // mailMessage.From = new MailAddress("*****@*****.**"); // mailMessage.Subject = "邮件标题"; // smtpClient.Credentials = new System.Net.NetworkCredential("*****@*****.**", "123qweasdzxc");//如果启用了“客户端授权码”,要用授权码代替密码 // smtpClient.Send(mailMessage); //} #endregion 邮件发送 #region 生成缩略图 ImageProcessingJob job = new ImageProcessingJob(); job.Filters.Add(new FixedResizeConstraint(200, 200)); job.SaveProcessedImageToFileSystem(@"G:\私活项目\07微信公众号\优而思校长在线\src\Tests\Yers.AllTests\images\fengjin.jpg", @"G:\私活项目\07微信公众号\优而思校长在线\src\Tests\Yers.AllTests\images\fengjin-new.jpg"); #endregion 生成缩略图 #region 测试数据库 /* * using (YersDbContext db = new YersDbContext()) * { * db.Database.Delete(); * db.Database.Create(); * }*/ #endregion 测试数据库 Console.WriteLine("OK"); Console.ReadKey(); }
protected void ProcessImage() { // Setup the source file name and the output file name string sourceImageFileName = this.imgSource.ImageUrl; string outputImageFileName = "~/repository/output/Ex_A_106.jpg"; // Get the image processing job for the specified resolution ImageProcessingJob job = new ImageProcessingJob(float.Parse(this.ddlOutputResolution.SelectedValue, System.Globalization.CultureInfo.InvariantCulture)); // Setup a crop constraint switch (this.ddlCropSize.SelectedIndex) { case 0: // 200 x 300 px job.Filters.Add(new FixedCropConstraint(200, 300)); break; case 1: // 50 x 75 points job.Filters.Add(new FixedCropConstraint(GfxUnit.Point, 50, 75)); break; case 2: // 20 x 30 mm job.Filters.Add(new FixedCropConstraint(GfxUnit.Mm, 20, 30)); break; case 3: // 0.6 x 0.9 inch job.Filters.Add(new FixedCropConstraint(GfxUnit.Inch, 0.6F, 0.9F)); break; } // Proces the image job.SaveProcessedImageToFileSystem(sourceImageFileName, outputImageFileName); // Update the displayed image (add a timestamp parameter to the query URL to ensure that the image is reloaded by the browser) this.imgOutput.ImageUrl = outputImageFileName + "?timestamp=" + DateTime.UtcNow.Ticks.ToString(); // Display the generated image this.phOutputContainer.Visible = true; }
/// <summary> /// <inheritdoc /> /// </summary> public MagickImage Process(ImageProcessingJob job) { try { // Check if both sizes are valid. Guard.Against.PositiveCondition(job.ThumbnailParams.Width == null && job.ThumbnailParams.Height == null); // Clone a source image var image = (MagickImage)job.Image.Clone(); // If any parameter of Resize function == 0 then another size will be used in respect with aspect ratio var imageSize = new MagickGeometry(job.ThumbnailParams.Width ?? 0, job.ThumbnailParams.Height ?? 0) { IgnoreAspectRatio = job.ThumbnailParams.IsFixedSize }; image.Interpolate = PixelInterpolateMethod.Bilinear; // Resize the image image.Resize(imageSize); // Check if any effect was requested and apply it if so if (job.ThumbnailParams.Effect.HasValue) { ApplyEffect(image, job.ThumbnailParams.Effect.Value); } // Remove image metadata if such setting is set if (!job.Settings.KeepMetadata ?? true) { image.Strip(); } return(image); } catch (Exception ex) { this.logger.LogError(ex, ex.Message); throw new AppFlowException(AppFlowExceptionType.GenericError); } }
public string BackImgSave(HttpPostedFileBase file) { string md5 = CommonHelper.GetMD5(file.InputStream); string ext = Path.GetExtension(file.FileName); string path = "/upload/" + DateTime.Now.ToString("yyyy/MM/dd") + "/" + md5 + ext; string fullPath = HttpContext.Server.MapPath("~" + path); new FileInfo(fullPath).Directory.Create(); ImageProcessingJob jobNormal = new ImageProcessingJob(); FixedAspectRatioCropConstraint constraint = new FixedAspectRatioCropConstraint(750 / 1334f); //宽高比 constraint.LimitedDimension = SizeDimension.Width; //是限制宽度还是限制高度(Height为限制高度,Width为限制宽度) constraint.Min = 600; //最小50像素(根据LimitedDimension确定是限定宽度还是高度) constraint.Max = 900; //最大200像素(根据LimitedDimension确定是限定宽度还是高度) //constraint.DefaultImageSelectionStrategy = CropConstraintImageSelectionStrategy.WholeImage;// 来保证显示原图全部内容,不裁剪。 jobNormal.Filters.Add(constraint);//限制图片的大小,避免生成 jobNormal.SaveProcessedImageToFileSystem(file.InputStream, fullPath); return(path); }
public string[] UploadFiles(HttpPostedFileBase file, string url) { if (!file.FileName.Equals("")) { Random r = new Random(); var newName = DateTime.Now.ToString("yyyyMMddHHmmss") + r.Next(1000, 10000) + file.FileName.Substring(file.FileName.LastIndexOf('.')); var path = Server.MapPath(url + newName); file.SaveAs(path); // 保存的正常大小的图片 ImageProcessingJob job = new ImageProcessingJob(); // 实例化第三方缩略图插件 job.Filters.Add(new FixedResizeConstraint(24, 24)); var smName = newName.Substring(0, newName.LastIndexOf('.')) + "_sm" + newName.Substring(newName.LastIndexOf('.')); var smPath = Server.MapPath(url + smName); job.SaveProcessedImageToFileSystem(path, smPath); return(new string[] { newName, smName }); } return(new string[] { "default.jpeg", "default.png" }); }
public ActionResult UploadPic(long houseId, HttpPostedFileBase file) { //一般是用文件的md5值来命名 string fileMd5 = CommonHelper.CalcMd5(file.InputStream); string fileExt = Path.GetExtension(file.FileName); string path = "/upload/" + DateTime.Now.ToString("yyyy/MM/dd") + "/" + fileMd5 + fileExt; string trumbPath = "/upload/" + DateTime.Now.ToString("yyyy/MM/dd") + "/" + fileMd5 + "_trumb" + fileExt; string trumbFullPath = Server.MapPath("~" + trumbPath); string fullPath = Server.MapPath("~" + path); new FileInfo(trumbFullPath).Directory.Create(); file.InputStream.Position = 0; //指针复位 //缩略图 ImageProcessingJob jobThumb = new ImageProcessingJob(); jobThumb.Filters.Add(new FixedResizeConstraint(200, 200));//缩略图尺寸 200*200 jobThumb.SaveProcessedImageToFileSystem(file.InputStream, trumbFullPath, new JpegFormatEncoderParams()); file.InputStream.Position = 0; //指针复位 ImageWatermark imgWatermark = new ImageWatermark(@"F:\86.jpg"); imgWatermark.ContentAlignment = System.Drawing.ContentAlignment.BottomRight; //水印位置 imgWatermark.Alpha = 80; //透明度,需要水印图片是背景透明的 png 图片 ImageProcessingJob jobNormal = new ImageProcessingJob(); jobNormal.Filters.Add(imgWatermark);//添加水印 //jobNormal.Filters.Add(new FixedResizeConstraint(600, 600));//限制图片的大小,避免生成大图。如果想原图大小处理,就不用加这个 Filter然后调用 SaveProcessedImageToFileSystem 或者 SaveProcessedImageToStream 来保存文件 imgWatermark.SaveProcessedImageToFileSystem(file.InputStream, fullPath, new JpegFormatEncoderParams()); HouseService.AddNewHousePic(new HousePicDTO() { HouseId = houseId, Url = path, ThumbUrl = trumbPath }); CreateStaticPages(houseId);//页面内容有变化,重新生成静态页 return(Json(new AjaxResult() { Status = "ok" })); }
public ActionResult UploadPic(long houseId, HttpPostedFileBase file) { string md5 = CommonHelper.CalcMD5(file.InputStream); string ext = Path.GetExtension(file.FileName); string path = "/PicUpload/" + DateTime.Now.ToString("yyyy/MM/dd") + "/" + md5 + ext; string thumbPath = "/PicUpload/" + DateTime.Now.ToString("yyyy/MM/dd") + "/" + md5 + "_thumb" + ext; string fullPath = Server.MapPath("~" + path); string fullThumbPath = Server.MapPath("~" + thumbPath); new FileInfo(fullPath).Directory.Create();//防止文件夹未创建 file.InputStream.Position = 0; //这里有可能出现指针未复位的情况 //file.SaveAs(fullPath); //添加缩略图 ImageProcessingJob jobThumb = new ImageProcessingJob(); jobThumb.Filters.Add(new FixedResizeConstraint(200, 200)); jobThumb.SaveProcessedImageToFileSystem(file.InputStream, fullThumbPath); //指针复位 //添加水印 file.InputStream.Position = 0; ImageWatermark imgWatermark = new ImageWatermark(Server.MapPath("~/images/watermark.png")); imgWatermark.ContentAlignment = System.Drawing.ContentAlignment.BottomRight; imgWatermark.Alpha = 50; ImageProcessingJob jobWatermark = new ImageProcessingJob(); jobWatermark.Filters.Add(imgWatermark); jobWatermark.Filters.Add(new FixedResizeConstraint(600, 600)); jobWatermark.SaveProcessedImageToFileSystem(file.InputStream, fullPath); HouseService.AddNewHousePic(new HousePicDTO() { HouseId = houseId, Url = path, ThumbUrl = thumbPath }); return(Json(new AjaxResult() { Status = "ok" })); }
//处理图片的上传请求 public ActionResult UpLoadPic(int houseId, HttpPostedFileBase file) { //HttpContext.Server.MapPath()表示保存到网站的根目录 //保存的文件名:houseId.扩展名;Path.GetExtension:获取文件的扩展名 //file.SaveAs(HttpContext.Server.MapPath("~/"+houseId+Path.GetExtension(file.FileName))); string mds = CommonHelper.CalMD5(file.InputStream); string ext = Path.GetExtension(file.FileName);//得到文件的后缀名 string path = "/upload/" + DateTime.Now.ToString("yyyy/MM/dd") + "/" + mds + ext; string fullPath = HttpContext.Server.MapPath("~" + path); string thumbPath = "/upload/" + DateTime.Now.ToString("yyyy/MM/dd") + "/" + mds + "_thumb" + ext; string thumbFullPath = HttpContext.Server.MapPath("~" + thumbPath); //判断文件夹upload是否存在 new FileInfo(fullPath).Directory.Create(); //尝试创建可能不存在的文件夹 file.InputStream.Position = 0; //指针复位,如果Md5生成的文件夹名为0的情况 //file.SaveAs(fullPath); //缩列图 ImageProcessingJob jobThumb = new ImageProcessingJob(); jobThumb.Filters.Add(new FixedResizeConstraint(200, 200));//缩略图尺寸 200*200 调用 ImageProcessingJob 的 jobThumb.SaveProcessedImageToFileSystem(file.InputStream, thumbFullPath); file.InputStream.Position = 0; //水印 ImageWatermark imgWatermark = new ImageWatermark("~/images/watermark.jpg"); imgWatermark.ContentAlignment = System.Drawing.ContentAlignment.BottomRight;//水印位置 imgWatermark.Alpha = 50;//透明度,需要水印图片是背景透明的 png 图片 ImageProcessingJob jobNormal = new ImageProcessingJob(); jobNormal.Filters.Add(imgWatermark); //添加水印 jobNormal.Filters.Add(new FixedResizeConstraint(600, 600)); //限制图片的大小,避免生成大图。如果想原图大小处理,就不用加这个 Filter jobNormal.SaveProcessedImageToFileSystem(file.InputStream, fullPath); //上传成功后把文件加入到数据库中 houseService.AddNewHousePic(new HousePicDTO { HouseId = houseId, Url = path, ThumbUrl = thumbPath }); return(Json(new AjaxResult { Status = "ok" })); }
protected ImageProcessingJob GetImagePreProcessingJob() { ImageProcessingJob job = new ImageProcessingJob(); // Set the back color job.ImageBackColor.Value = this.InlinePictureTrimmer1.ImageBackColor.Clone(); // Add the color filter switch (this.ddlDefaultColorFilters.SelectedIndex) { case 0: // No color filter break; case 1: // Grayscale job.Filters.Add(DefaultColorFilters.Grayscale); break; case 2: // Sepia job.Filters.Add(DefaultColorFilters.Sepia); break; case 3: // Invert job.Filters.Add(DefaultColorFilters.Invert); break; } // Add the rotation filter float rotationAngle = float.Parse(this.ddlRotationAngle.SelectedValue, System.Globalization.CultureInfo.InvariantCulture); job.Filters.Add(new MyRotationFilter(rotationAngle)); return job; }
protected void processImages() { // Delete the previously generated files string[] oldOutputImages = System.IO.Directory.GetFiles(Server.MapPath(OutputImagesFolder)); foreach (string oldOutputImage in oldOutputImages) { System.IO.File.Delete(oldOutputImage); } // Create a new image processing job ImageProcessingJob job = new ImageProcessingJob(); if (this.cbFilterCrop.Checked) { // Add the crop filter job.Filters.Add(new FixedCropConstraint(380, 320)); } if (this.cbFilterColor.Checked) { job.Filters.Add(DefaultColorFilters.Sepia); } if (this.cbFilterWatermark.Checked) { // Add the watermark TextWatermark textWatermark = new TextWatermark(); textWatermark.ContentAlignment = ContentAlignment.BottomRight; textWatermark.ForeColor = Color.FromArgb(230, Color.Black); textWatermark.Text = "Image processed by Piczard"; textWatermark.Font.Size = 12; job.Filters.Add(textWatermark); } // Get the files to process string[] sourceImages = System.IO.Directory.GetFiles(Server.MapPath(SourceImagesFolder)); for (int i = 0; i < sourceImages.Length; i++) { string sourceFilePath = sourceImages[i]; string sourceFileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(sourceFilePath); // Get the output image format FormatEncoderParams outputFormat; if (this.rbFormatCustom.Checked) { // Custom format outputFormat = ImageArchiver.GetFormatEncoderParamsFromFileExtension(this.ddlImageFormat.SelectedValue); } else { // Same format as the source image outputFormat = ImageArchiver.GetFormatEncoderParamsFromFilePath(sourceFilePath); } string outputFileName = sourceFileNameWithoutExtension + outputFormat.FileExtension; string outputFilePath = System.IO.Path.Combine(OutputImagesFolder, outputFileName); // Process the image job.SaveProcessedImageToFileSystem(sourceFilePath, outputFilePath); } }