private void OnPngSizeLargeToggleChange(bool isOn) { if (isOn) { imgSize = ImgSize.Large; // Export Image Dimensions exportWidth = 7680; exportHeight = 4320; } }
private void OnPngSizeMediumToggleChange(bool isOn) { if (isOn) { imgSize = ImgSize.Medium; // Export Image Dimensions exportWidth = 3840; exportHeight = 2160; } }
private void OnPngSizeSmallToggleChange(bool isOn) { if (isOn) { imgSize = ImgSize.Small; // Export Image Dimensions exportWidth = 1920; exportHeight = 1080; } }
public static ImgSize GetDimensions(byte[] imgdata) { MemoryStream memstream = null; ImgSize imgsize = new ImgSize(0, 0, "xxx"); try { memstream = new MemoryStream(imgdata); using (BinaryReader binaryReader = new BinaryReader(memstream)) { imgsize = GetDimensions(binaryReader); } } finally { if (memstream != null) memstream.Close(); } return imgsize; }
public static void clr_GetADusersPhotos(SqlString ADpath, SqlString ADfilter) { //System.IO.StreamWriter file = Util.CreateLogFile(); SearchResultCollection results = null; Int32 itemcount = 0; try { DataTable tbl = new DataTable(); tbl.Columns.Add("ObjectGUID", typeof(Guid)); tbl.Columns.Add("Width", typeof(int)); tbl.Columns.Add("Height", typeof(int)); tbl.Columns.Add("Format", typeof(string)); tbl.Columns.Add("Photo", typeof(byte[])); DataRow row; DirectoryEntry entry = new DirectoryEntry((string)ADpath); DirectorySearcher searcher = new DirectorySearcher(entry); searcher.Filter = (string)ADfilter; searcher.PageSize = 500; results = searcher.FindAll(); foreach (SearchResult searchResult in results) { itemcount++; DirectoryEntry item = searchResult.GetDirectoryEntry(); PropertyValueCollection prop = Util.GetADproperty(item, "thumbnailphoto"); if (prop == null) continue; // Get image size ImgSize imgsize = new ImgSize(0, 0, "xxx"); try { imgsize = ImageHeader.GetDimensions((byte[])prop[0]); } catch(Exception ex) { SqlContext.Pipe.Send("Warning: Get image size failed for user (" + Util.GetDistinguishedName(item) + ")" + " Exception: " + ex.Message); } row = tbl.NewRow(); row[0] = item.Guid; if (!imgsize.IsEmpty()) // Image size will be NULL unless size has been read from the image header. { row[1] = imgsize.Width; row[2] = imgsize.Height; row[3] = imgsize.Format; } row[4] = prop[0]; tbl.Rows.Add(row); } // Return dataset to SQL server. ReturnDatasetToSqlServer(tbl); } catch (System.Runtime.InteropServices.COMException) { SqlContext.Pipe.Send("COMException in clr_GetADusersPhotos. ItemCounter = " + itemcount.ToString()); throw; } catch (InvalidOperationException) { SqlContext.Pipe.Send("InvalidOperationException in clr_GetADusersPhotos. ItemCounter = " + itemcount.ToString()); throw; } catch (NotSupportedException) { SqlContext.Pipe.Send("NotSupportedException in clr_GetADusersPhotos. ItemCounter = " + itemcount.ToString()); throw; } catch (Exception) { SqlContext.Pipe.Send("Exception in clr_GetADusersPhotos. ItemCounter = " + itemcount.ToString()); throw; } finally { if (null != results) { results.Dispose(); // To prevent memory leaks, always call results = null; // SearchResultCollection.Dispose() manually. } } //file.Close(); }
public static string PictureSize(string fileName, string newFile, int maxWidth, int maxHeight, int PZ, bool tag) { if (maxWidth == 0 || maxHeight == 0) { return(fileName); } if (System.IO.File.Exists(HttpContext.Current.Server.MapPath("~" + fileName))) { System.Drawing.Image img = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath("~" + fileName)); //if ((img.Width > maxWidth && img.Height > maxHeight) || (tag && (img.Width != maxWidth || img.Height != maxHeight))) if (img.Width != maxWidth || img.Height != maxHeight) { System.Drawing.Imaging.ImageFormat thisFormat = img.RawFormat; string t = "min"; if (tag) { t = "max"; } ImgSize newSize = GetPictureSize(fileName, maxWidth, maxHeight, t); /* * if (newSize.Width == img.Width && newSize.Height == img.Height) * { * if(!tag ||( newSize.Width== maxWidth && newSize.Width == newSize.Height)) * { * * img.Dispose(); * return (fileName); * } * }*/ int CanvasWidth = newSize.Width, CanvasHeight = newSize.Height, CanvasTop = 0, CanvasLeft = 0; if (tag) { CanvasWidth = maxWidth; CanvasHeight = maxHeight; if (newSize.Width > maxWidth) { CanvasLeft = (newSize.Width - maxWidth) / 2; } //if (newSize.Height > maxHeight) CanvasTop = (newSize.Height - maxHeight) / 2; } else { CanvasWidth = maxWidth; CanvasHeight = maxHeight; if (newSize.Width < maxWidth) { CanvasLeft = (newSize.Width - maxWidth) / 2; } if (newSize.Height < maxHeight) { CanvasTop = (newSize.Height - maxHeight) / 2; } } Bitmap outBmp = new Bitmap(CanvasWidth, CanvasHeight); Graphics g = Graphics.FromImage(outBmp); Color color = Color.FromArgb(242, 242, 242); Brush brush = new SolidBrush(color); g.FillRectangle(brush, 0, 0, CanvasWidth, CanvasHeight); // 设置画布的描绘质量 g.CompositingQuality = CompositingQuality.HighQuality; g.SmoothingMode = SmoothingMode.HighQuality; g.InterpolationMode = InterpolationMode.HighQualityBicubic; //throw new NullReferenceException(newSize.Width.ToString() + "," + newSize.Height.ToString() + "," + CanvasLeft.ToString()); g.DrawImage(img, new Rectangle(-CanvasLeft, -CanvasTop, newSize.Width, newSize.Height), 0, 0, img.Width, img.Height, GraphicsUnit.Pixel); g.Dispose(); // 以下代码为保存图片时,设置压缩质量 EncoderParameters encoderParams = new EncoderParameters(); long[] quality = new long[1]; quality[0] = PZ; EncoderParameter encoderParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality); encoderParams.Param[0] = encoderParam; //获得包含有关内置图像编码解码器的信息的ImageCodecInfo 对象。 ImageCodecInfo[] arrayICI = ImageCodecInfo.GetImageEncoders(); ImageCodecInfo jpegICI = null; for (int x = 0; x < arrayICI.Length; x++) { if (arrayICI[x].FormatDescription.Equals("JPEG")) { jpegICI = arrayICI[x];//设置JPEG编码 break; } } img.Dispose(); if (jpegICI != null) { outBmp.Save(HttpContext.Current.Server.MapPath("~" + newFile), jpegICI, encoderParams); } else { outBmp.Save(HttpContext.Current.Server.MapPath("~" + newFile), thisFormat); } outBmp.Dispose(); return(newFile); } return(fileName); } return(""); }