protected static void DrawIcon(Graphics graphics, Image imgPanelIcon, int x, int y) { if (graphics == null) { throw new ArgumentException( string.Format( System.Globalization.CultureInfo.CurrentUICulture, StaticResource.IDS_ArgumentException, typeof(Graphics).Name)); } if (imgPanelIcon == null) { throw new ArgumentException( string.Format( System.Globalization.CultureInfo.CurrentUICulture, StaticResource.IDS_ArgumentException, typeof(Image).Name)); } int iconWidth = imgPanelIcon.Width; int iconHeight = imgPanelIcon.Height; Rectangle rectangleIcon = new Rectangle(x, y, iconWidth, iconHeight); using (System.Drawing.Imaging.ImageAttributes imageAttribute = new System.Drawing.Imaging.ImageAttributes()) { imageAttribute.SetColorKey(Color.Magenta, Color.Magenta); //颜色改为透明 System.Drawing.Imaging.ColorMap colorMap = new System.Drawing.Imaging.ColorMap(); colorMap.OldColor = Color.FromArgb(0, 60, 166); //改颜色 colorMap.NewColor = Color.Black; imageAttribute.SetRemapTable(new System.Drawing.Imaging.ColorMap[] { colorMap }); graphics.DrawImage(imgPanelIcon, rectangleIcon, 0, 0, iconWidth, iconHeight, GraphicsUnit.Pixel, imageAttribute); } }
public TestRollUpPanel() { InitializeComponent(); rolluppanel.HiddenMarkerWidth = -100; rolluppanel.SetPinState(true); comboBoxCustom1.Items.AddRange(new string[] { "1Fred", "Jim", "Sheila", "George" }); comboBoxCustom1.DropDownBackgroundColor = Color.Red; comboBoxCustom1.FlatStyle = FlatStyle.Popup; comboBoxCustom1.Repaint(); comboBoxCustom2.Items.AddRange(KeyObjectExtensions.KeyListString(true)); comboBoxCustom2.SelectedItem = Keys.ShiftKey.VKeyToString(); //comboBoxCustom1.FlatStyle = FlatStyle.Popup; System.Drawing.Imaging.ColorMap colormap = new System.Drawing.Imaging.ColorMap(); // any drawn panel with drawn images colormap.OldColor = Color.White; // white is defined as the forecolour colormap.NewColor = Color.Orange; System.Drawing.Imaging.ColorMap colormap2 = new System.Drawing.Imaging.ColorMap(); // any drawn panel with drawn images colormap2.OldColor = Color.FromArgb(222, 222, 222); // white is defined as the forecolour colormap2.NewColor = Color.Orange.Multiply(0.8F); foreach (Control c in rolluppanel.Controls) { if (c is ExtendedControls.CheckBoxCustom) { (c as ExtendedControls.CheckBoxCustom).SetDrawnBitmapRemapTable(new System.Drawing.Imaging.ColorMap[] { colormap, colormap2 }); } else if (c is ExtendedControls.ButtonExt) { (c as ExtendedControls.ButtonExt).SetDrawnBitmapRemapTable(new System.Drawing.Imaging.ColorMap[] { colormap, colormap2 }); } } KeyObjectExtensions.VerifyKeyOE(); }
private Image MergeSignature(Image sigImage, Image docImage) { // Create a new empty bitmap var bitmap = new Bitmap(720, 480); // Set up transparency color mapping var colorMap = new System.Drawing.Imaging.ColorMap[1]; colorMap[0] = new System.Drawing.Imaging.ColorMap(); colorMap[0].OldColor = Color.White; colorMap[0].NewColor = Color.Transparent; var attr = new System.Drawing.Imaging.ImageAttributes(); attr.SetRemapTable(colorMap); // Execute the merge using (Graphics grfx = Graphics.FromImage(bitmap)) { grfx.DrawImage(docImage, 0, 0); grfx.DrawImage(sigImage, new Rectangle(200, 200, sigImage.Width, sigImage.Height), 0, 0, sigImage.Width, sigImage.Height, GraphicsUnit.Pixel, attr); grfx.Save(); } return((Image)bitmap); }
// 添加图片水印 public static string addWaterMark(string filepath, string fileName) { System.Drawing.Image image = System.Drawing.Image.FromFile(filepath + fileName); Bitmap b = new Bitmap(image.Width, image.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(b); g.Clear(Color.White); g.DrawImage(image, 0, 0, image.Width, image.Height); Image watermark = new Bitmap(AppDomain.CurrentDomain.BaseDirectory + @"Content/image/logo.png"); System.Drawing.Imaging.ImageAttributes imageAttributes = new System.Drawing.Imaging.ImageAttributes(); System.Drawing.Imaging.ColorMap colorMap = new System.Drawing.Imaging.ColorMap(); colorMap.OldColor = Color.FromArgb(255, 0, 255, 0); colorMap.NewColor = Color.FromArgb(0, 0, 0, 0); System.Drawing.Imaging.ColorMap[] remapTable = { colorMap }; imageAttributes.SetRemapTable(remapTable, System.Drawing.Imaging.ColorAdjustType.Bitmap); float[][] colorMatrixElements = { new float[] { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f }, new float[] { 0.0f, 1.0f, 0.0f, 0.0f, 0.0f }, new float[] { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f }, new float[] { 0.0f, 0.0f, 0.0f, 0.3f, 0.0f }, new float[] { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f } }; System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(colorMatrixElements); imageAttributes.SetColorMatrix(colorMatrix, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap); int xpos = 0; int ypos = 0; xpos = ((image.Width - watermark.Width) / 2); ypos = (image.Height - watermark.Height) / 2; g.DrawImage(watermark, new Rectangle(xpos, ypos, watermark.Width, watermark.Height), 0, 0, watermark.Width, watermark.Height, GraphicsUnit.Pixel, imageAttributes); watermark.Dispose(); imageAttributes.Dispose(); //保存加水印过后的图片,删除原始图片 fileName = DateTime.Now.ToFileTime() + new Random().Next(100, 999) + System.IO.Path.GetExtension(fileName); b.Save(filepath + fileName); b.Dispose(); image.Dispose(); if (System.IO.File.Exists(filepath)) { System.IO.File.Delete(filepath); } return(fileName); }
void CreateMaterialImage(List <PictureBoxHotspot.ImageElement> pc, Point matpos, Size matsize, string text, string mattag, string mattip, Color matcolour, Color textcolour) { System.Drawing.Imaging.ColorMap colormap = new System.Drawing.Imaging.ColorMap(); colormap.OldColor = Color.White; // this is the marker colour to replace colormap.NewColor = matcolour; Bitmap mat = BitMapHelpers.ReplaceColourInBitmap(EDDiscovery.Properties.Resources.materialmarkerorangefilled, new System.Drawing.Imaging.ColorMap[] { colormap }); BitMapHelpers.DrawTextCentreIntoBitmap(ref mat, text, stdfont, textcolour); PictureBoxHotspot.ImageElement ie = new PictureBoxHotspot.ImageElement( new Rectangle(matpos.X, matpos.Y, matsize.Width, matsize.Height), mat, mattag, mattip); pc.Add(ie); }
void CreateMaterialImage(List <ExtPictureBox.ImageElement> pc, Point matpos, Size matsize, string text, string mattag, string mattip, Color matcolour, Color textcolour) { System.Drawing.Imaging.ColorMap colormap = new System.Drawing.Imaging.ColorMap(); colormap.OldColor = Color.White; // this is the marker colour to replace colormap.NewColor = matcolour; Bitmap mat = BaseUtils.BitMapHelpers.ReplaceColourInBitmap((Bitmap)Icons.Controls.Scan_Bodies_Material, new System.Drawing.Imaging.ColorMap[] { colormap }); BaseUtils.BitMapHelpers.DrawTextCentreIntoBitmap(ref mat, text, stdfont, textcolour); ExtPictureBox.ImageElement ie = new ExtPictureBox.ImageElement( new Rectangle(matpos.X, matpos.Y, matsize.Width, matsize.Height), mat, mattag, mattip); pc.Add(ie); }
/// <summary> /// Draws the Chevron Image at the specified location. /// </summary> /// <param name="graphics">The Graphics to draw on.</param> /// <param name="imgChevron">Chevron Image to draw.</param> /// <param name="chevronBackColor"></param> /// <param name="iPositionX">The left position of the Chevron Image</param> protected static void DrawChevron(Graphics graphics, Image imgChevron, Rectangle imageRectangle, Color chevronBackColor) { if (graphics == null) { throw new ArgumentException( string.Format( System.Globalization.CultureInfo.CurrentUICulture, Resources.IDS_ArgumentException, typeof(Graphics).Name)); } if (imgChevron == null) { throw new ArgumentException( string.Format( System.Globalization.CultureInfo.CurrentUICulture, Resources.IDS_ArgumentException, typeof(Image).Name)); } int chevronPositionX = imageRectangle.Left; int chevronPositionY = ImagePaddingTop; Rectangle rectangleChevron = new Rectangle( chevronPositionX + (imageRectangle.Width / 3) - 2, chevronPositionY + 3, 9, 9); using (System.Drawing.Imaging.ImageAttributes imageAttribute = new System.Drawing.Imaging.ImageAttributes()) { imageAttribute.SetColorKey(Color.White, Color.White); System.Drawing.Imaging.ColorMap colorMap = new System.Drawing.Imaging.ColorMap(); colorMap.OldColor = Color.FromArgb(0, 60, 166); colorMap.NewColor = chevronBackColor; imageAttribute.SetRemapTable(new System.Drawing.Imaging.ColorMap[] { colorMap }); using (LinearGradientBrush brushInnerCircle = new LinearGradientBrush( new Rectangle(chevronPositionX, chevronPositionY, 16, 16), Color.FromArgb(128, Color.White), Color.FromArgb(0, Color.White), LinearGradientMode.Vertical)) { graphics.FillPath(brushInnerCircle, GetPath(new Rectangle(chevronPositionX, chevronPositionY, 15, 15), 5)); } graphics.DrawImage(imgChevron, rectangleChevron, 0, 0, 9, 9, GraphicsUnit.Pixel, imageAttribute); } }
public static Bitmap ReplaceColor(this Image image, Color oldColor, Color newColor) { var bmp = new Bitmap(image.Width, image.Height); using (var gr = Graphics.FromImage(bmp)) { var imageAttrs = new System.Drawing.Imaging.ImageAttributes(); var colorMap = new System.Drawing.Imaging.ColorMap() { OldColor = oldColor, NewColor = newColor }; imageAttrs.SetRemapTable(new[] { colorMap }); gr.DrawImage(image, new Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, imageAttrs); } return(bmp); }
private static void GenerateImageResourcesOfAminoAcid(char aa, string filename, bool pos, Color color) { try { Assembly assembly = Assembly.GetExecutingAssembly(); if (!filename.StartsWith("PeSA")) { filename = "PeSA.Engine.Resources." + filename; } Stream stream = assembly.GetManifestResourceStream(filename); if (stream == null) { return; } Image image = Image.FromStream(stream); System.Drawing.Imaging.ImageAttributes imageAttributes = new System.Drawing.Imaging.ImageAttributes(); int width = image.Width; int height = image.Height; System.Drawing.Imaging.ColorMap colorMap = new System.Drawing.Imaging.ColorMap(); colorMap.OldColor = Color.Black; colorMap.NewColor = color; System.Drawing.Imaging.ColorMap[] remapTable = { colorMap }; imageAttributes.SetRemapTable(remapTable, System.Drawing.Imaging.ColorAdjustType.Bitmap); Bitmap bmp = new Bitmap(width, height); using (var gr = Graphics.FromImage(bmp)) { gr.DrawImage(image, new Rectangle(0, 0, width, height), 0, 0, width, height, GraphicsUnit.Pixel, imageAttributes); if (pos) { SetImage(PositiveImages, aa, bmp); } else { SetImage(NegativeImages, aa, bmp); } } } catch (Exception exc) { } }
public static System.Drawing.Bitmap ChangeImageColor(Bitmap source, System.Drawing.Color OldColor, System.Drawing.Color NewColor) { Bitmap Result = new Bitmap(source.Width, source.Height); Graphics g = Graphics.FromImage(Result); using (Bitmap bmp = new Bitmap(source)) { // Set the image attribute's color mappings System.Drawing.Imaging.ColorMap[] colorMap = new System.Drawing.Imaging.ColorMap[1]; colorMap[0] = new System.Drawing.Imaging.ColorMap(); colorMap[0].OldColor = OldColor; colorMap[0].NewColor = NewColor; System.Drawing.Imaging.ImageAttributes attr = new System.Drawing.Imaging.ImageAttributes(); attr.SetRemapTable(colorMap); // Draw using the color map System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height); g.DrawImage(bmp, rect, 0, 0, rect.Width, rect.Height, GraphicsUnit.Pixel, attr); } return(Result); }
public TestMisc() { InitializeComponent(); theme = new ThemeStandard(); theme.LoadBaseThemes(); theme.SetThemeByName("Elite Verdana"); theme.WindowsFrame = true; for (int i = 0; i < 100; i++) { extComboBox1.Items.Add("Item " + i); } extPanelDropDown1.Items = new List <string>() { "One", "two", "three" }; extTextBoxAutoComplete1.SetAutoCompletor(AutoList); System.Drawing.Imaging.ColorMap colormap = new System.Drawing.Imaging.ColorMap(); // any drawn panel with drawn images colormap.OldColor = Color.White; // white is defined as the forecolour colormap.NewColor = Color.Orange; System.Drawing.Imaging.ColorMap colormap2 = new System.Drawing.Imaging.ColorMap(); // any drawn panel with drawn images colormap2.OldColor = Color.FromArgb(222, 222, 222); // white is defined as the forecolour colormap2.NewColor = Color.Orange.Multiply(0.8F); foreach (Control c in tableLayoutPanel3.Controls) { if (c is ExtendedControls.ExtCheckBox) { (c as ExtendedControls.ExtCheckBox).SetDrawnBitmapRemapTable(new System.Drawing.Imaging.ColorMap[] { colormap, colormap2 }); } else if (c is ExtendedControls.ExtButton) { (c as ExtendedControls.ExtButton).SetDrawnBitmapRemapTable(new System.Drawing.Imaging.ColorMap[] { colormap, colormap2 }); } } }
/// <summary> /// 图片等比缩放 /// </summary> /// <remarks>吴剑 2011-01-21</remarks> /// <param name="fromFile">原图Stream对象</param> /// <param name="savePath">缩略图存放地址</param> /// <param name="targetWidth">指定的最大宽度</param> /// <param name="targetHeight">指定的最大高度</param> /// <param name="watermarkText">水印文字(为""表示不使用水印)</param> /// <param name="watermarkImage">水印图片路径(为""表示不使用水印)</param> public static void ZoomAuto(System.IO.Stream fromFile, string savePath, System.Double targetWidth, System.Double targetHeight, string watermarkText, string watermarkImage) { //创建目录 DME_Files.InitFolder(DME_Path.GetDirectoryName(savePath)); //原始图片(获取原始图片创建对象,并使用流中嵌入的颜色管理信息) System.Drawing.Image initImage = System.Drawing.Image.FromStream(fromFile, true); //原图宽高均小于模版,不作处理,直接保存 if (initImage.Width <= targetWidth && initImage.Height <= targetHeight) { //文字水印 if (watermarkText != "") { using (System.Drawing.Graphics gWater = System.Drawing.Graphics.FromImage(initImage)) { System.Drawing.Font fontWater = new System.Drawing.Font("黑体", 12); System.Drawing.Brush brushWater = new System.Drawing.SolidBrush(System.Drawing.Color.White); gWater.DrawString(watermarkText, fontWater, brushWater, 10, 10); gWater.Dispose(); } } //透明图片水印 if (watermarkImage != "") { if (DME_Files.FileExists(watermarkImage)) { //获取水印图片 using (System.Drawing.Image wrImage = System.Drawing.Image.FromFile(watermarkImage)) { //水印绘制条件:原始图片宽高均大于或等于水印图片 if (initImage.Width >= wrImage.Width && initImage.Height >= wrImage.Height) { System.Drawing.Graphics gWater = System.Drawing.Graphics.FromImage(initImage); //透明属性 System.Drawing.Imaging.ImageAttributes imgAttributes = new System.Drawing.Imaging.ImageAttributes(); System.Drawing.Imaging.ColorMap colorMap = new System.Drawing.Imaging.ColorMap(); colorMap.OldColor = System.Drawing.Color.FromArgb(255, 0, 255, 0); colorMap.NewColor = System.Drawing.Color.FromArgb(0, 0, 0, 0); System.Drawing.Imaging.ColorMap[] remapTable = { colorMap }; imgAttributes.SetRemapTable(remapTable, System.Drawing.Imaging.ColorAdjustType.Bitmap); float[][] colorMatrixElements = { new float[] {1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, new float[] {0.0f, 1.0f, 0.0f, 0.0f, 0.0f}, new float[] {0.0f, 0.0f, 1.0f, 0.0f, 0.0f}, new float[] {0.0f, 0.0f, 0.0f, 0.5f, 0.0f},//透明度:0.5 new float[] {0.0f, 0.0f, 0.0f, 0.0f, 1.0f} }; System.Drawing.Imaging.ColorMatrix wmColorMatrix = new System.Drawing.Imaging.ColorMatrix(colorMatrixElements); imgAttributes.SetColorMatrix(wmColorMatrix, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap); gWater.DrawImage(wrImage, new System.Drawing.Rectangle(initImage.Width - wrImage.Width, initImage.Height - wrImage.Height, wrImage.Width, wrImage.Height), 0, 0, wrImage.Width, wrImage.Height, System.Drawing.GraphicsUnit.Pixel, imgAttributes); gWater.Dispose(); } wrImage.Dispose(); } } } //保存 initImage.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg); } else { //缩略图宽、高计算 double newWidth = initImage.Width; double newHeight = initImage.Height; //宽大于高或宽等于高(横图或正方) if (initImage.Width > initImage.Height || initImage.Width == initImage.Height) { //如果宽大于模版 if (initImage.Width > targetWidth) { //宽按模版,高按比例缩放 newWidth = targetWidth; newHeight = initImage.Height * (targetWidth / initImage.Width); } } //高大于宽(竖图) else { //如果高大于模版 if (initImage.Height > targetHeight) { //高按模版,宽按比例缩放 newHeight = targetHeight; newWidth = initImage.Width * (targetHeight / initImage.Height); } } //生成新图 //新建一个bmp图片 System.Drawing.Image newImage = new System.Drawing.Bitmap((int)newWidth, (int)newHeight); //新建一个画板 System.Drawing.Graphics newG = System.Drawing.Graphics.FromImage(newImage); //设置质量 newG.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; newG.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //置背景色 newG.Clear(System.Drawing.Color.White); //画图 newG.DrawImage(initImage, new System.Drawing.Rectangle(0, 0, newImage.Width, newImage.Height), new System.Drawing.Rectangle(0, 0, initImage.Width, initImage.Height), System.Drawing.GraphicsUnit.Pixel); //文字水印 if (watermarkText != "") { using (System.Drawing.Graphics gWater = System.Drawing.Graphics.FromImage(newImage)) { System.Drawing.Font fontWater = new System.Drawing.Font("宋体", 10); System.Drawing.Brush brushWater = new System.Drawing.SolidBrush(System.Drawing.Color.White); gWater.DrawString(watermarkText, fontWater, brushWater, 10, 10); gWater.Dispose(); } } //透明图片水印 if (watermarkImage != "") { if (DME_Files.FileExists(watermarkImage)) { //获取水印图片 using (System.Drawing.Image wrImage = System.Drawing.Image.FromFile(watermarkImage)) { //水印绘制条件:原始图片宽高均大于或等于水印图片 if (newImage.Width >= wrImage.Width && newImage.Height >= wrImage.Height) { System.Drawing.Graphics gWater = System.Drawing.Graphics.FromImage(newImage); //透明属性 System.Drawing.Imaging.ImageAttributes imgAttributes = new System.Drawing.Imaging.ImageAttributes(); System.Drawing.Imaging.ColorMap colorMap = new System.Drawing.Imaging.ColorMap(); colorMap.OldColor = System.Drawing.Color.FromArgb(255, 0, 255, 0); colorMap.NewColor = System.Drawing.Color.FromArgb(0, 0, 0, 0); System.Drawing.Imaging.ColorMap[] remapTable = { colorMap }; imgAttributes.SetRemapTable(remapTable, System.Drawing.Imaging.ColorAdjustType.Bitmap); float[][] colorMatrixElements = { new float[] {1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, new float[] {0.0f, 1.0f, 0.0f, 0.0f, 0.0f}, new float[] {0.0f, 0.0f, 1.0f, 0.0f, 0.0f}, new float[] {0.0f, 0.0f, 0.0f, 0.5f, 0.0f},//透明度:0.5 new float[] {0.0f, 0.0f, 0.0f, 0.0f, 1.0f} }; System.Drawing.Imaging.ColorMatrix wmColorMatrix = new System.Drawing.Imaging.ColorMatrix(colorMatrixElements); imgAttributes.SetColorMatrix(wmColorMatrix, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap); gWater.DrawImage(wrImage, new System.Drawing.Rectangle(newImage.Width - wrImage.Width, newImage.Height - wrImage.Height, wrImage.Width, wrImage.Height), 0, 0, wrImage.Width, wrImage.Height, System.Drawing.GraphicsUnit.Pixel, imgAttributes); gWater.Dispose(); } wrImage.Dispose(); } } } //保存缩略图 newImage.Save(savePath, System.Drawing.Imaging.ImageFormat.Jpeg); //释放资源 newG.Dispose(); newImage.Dispose(); initImage.Dispose(); } }
/// <summary> /// 文字和Logo图片水印 /// </summary> /// <param name="ImgFile">原图文件地址</param> /// <param name="WaterImg">水印图片地址</param> /// <param name="TextFont">水印文字信息</param> /// <param name="sImgPath">生存水印图片后的保存地址</param> /// <param name="ImgAlpha">水印图片的透明度</param> /// <param name="imgiScale">水印图片在原图上的显示比例</param> /// <param name="intimgDistance">水印图片在原图上的边距确定,以图片的右边和下边为准,当设定的边距超过一定大小后参数会自动失效</param> /// <param name="texthScale">水印文字高度位置,从图片底部开始计算,0-1</param> /// <param name="textwidthFont">文字块在图片中所占宽度比例 0-1</param> /// <param name="textAlpha">文字透明度 其数值的范围在0到255</param> public void zzsImgTextWater( string ImgFile , string WaterImg , string TextFont , string sImgPath , float ImgAlpha , float imgiScale , int intimgDistance , float texthScale , float textwidthFont , int textAlpha ) { try { FileStream fs = new FileStream(ImgFile, FileMode.Open); BinaryReader br = new BinaryReader(fs); byte[] bytes = br.ReadBytes((int)fs.Length); br.Close(); fs.Close(); MemoryStream ms = new MemoryStream(bytes); System.Drawing.Image imgPhoto = System.Drawing.Image.FromStream(ms); //System.Drawing.Image imgPhoto = System.Drawing.Image.FromFile(ImgFile); int imgPhotoWidth = imgPhoto.Width; int imgPhotoHeight = imgPhoto.Height; Bitmap bmPhoto = new Bitmap(imgPhotoWidth, imgPhotoHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb); bmPhoto.SetResolution(72, 72); Graphics gbmPhoto = Graphics.FromImage(bmPhoto); gbmPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; gbmPhoto.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; gbmPhoto.DrawImage( imgPhoto , new Rectangle(0, 0, imgPhotoWidth, imgPhotoHeight) , 0 , 0 , imgPhotoWidth , imgPhotoHeight , GraphicsUnit.Pixel ); //建立字体大小的数组,循环找出适合图片的水印字体 int[] sizes = new int[] { 1000, 800, 700, 650, 600, 560, 540, 500, 450, 400, 380, 360, 340, 320, 300, 280, 260, 240, 220, 200, 180, 160, 140, 120, 100, 80, 72, 64, 48, 32, 28, 26, 24, 20, 28, 16, 14, 12, 10, 8, 6, 4, 2 }; System.Drawing.Font crFont = null; System.Drawing.SizeF crSize = new SizeF(); for (int i = 0; i < 43; i++) { crFont = new Font("arial", sizes[i], FontStyle.Bold); crSize = gbmPhoto.MeasureString(TextFont, crFont); if ((ushort)crSize.Width < (ushort)imgPhotoWidth * textwidthFont) { break; } } //设置水印字体的位置 int yPixlesFromBottom = (int)(imgPhotoHeight * texthScale); float yPosFromBottom = ((imgPhotoHeight - yPixlesFromBottom) - (crSize.Height / 2)); float xCenterOfImg = (imgPhotoWidth * 1 / 2); System.Drawing.StringFormat StrFormat = new System.Drawing.StringFormat(); StrFormat.Alignment = System.Drawing.StringAlignment.Center; // System.Drawing.SolidBrush semiTransBrush2 = new System.Drawing.SolidBrush(Color.FromArgb(textAlpha, 0, 0, 0)); gbmPhoto.DrawString( TextFont , crFont , semiTransBrush2 , new System.Drawing.PointF(xCenterOfImg + 1, yPosFromBottom + 1) , StrFormat ); System.Drawing.SolidBrush semiTransBrush = new System.Drawing.SolidBrush(Color.FromArgb(textAlpha, 255, 255, 255)); gbmPhoto.DrawString( TextFont , crFont , semiTransBrush , new System.Drawing.PointF(xCenterOfImg, yPosFromBottom) , StrFormat ); System.Drawing.Image imgWatermark = new Bitmap(WaterImg); int imgWatermarkWidth = imgWatermark.Width; int imgWatermarkHeight = imgWatermark.Height; //计算水印图片尺寸 decimal aScale = Convert.ToDecimal(imgiScale); decimal pScale = 0.05M; decimal MinScale = aScale - pScale; decimal MaxScale = aScale + pScale; int imgWatermarkWidthNew = imgWatermarkWidth; int imgWatermarkHeightNew = imgWatermarkHeight; if (imgPhotoWidth >= imgWatermarkWidth && imgPhotoHeight >= imgWatermarkHeight && imgPhotoWidth >= imgPhotoHeight) { if (imgWatermarkWidth > imgWatermarkHeight) { if ((MinScale <= Math.Round((Convert.ToDecimal(imgWatermarkWidth) / Convert.ToDecimal(imgPhotoWidth)), 7)) && (Math.Round((Convert.ToDecimal(imgWatermarkWidth) / Convert.ToDecimal(imgPhotoWidth)), 7) <= MaxScale)) { } else { imgWatermarkWidthNew = Convert.ToInt32(imgPhotoWidth * aScale); imgWatermarkHeightNew = Convert.ToInt32((imgPhotoWidth * aScale / imgWatermarkWidth) * imgWatermarkHeight); } } else if ((MinScale <= Math.Round((Convert.ToDecimal(imgWatermarkHeight) / Convert.ToDecimal(imgPhotoHeight)), 7)) && (Math.Round((Convert.ToDecimal(imgWatermarkHeight) / Convert.ToDecimal(imgPhotoHeight)), 7) <= MaxScale)) { } else { imgWatermarkHeightNew = Convert.ToInt32(imgPhotoHeight * aScale); imgWatermarkWidthNew = Convert.ToInt32((imgPhotoHeight * aScale / imgWatermarkHeight) * imgWatermarkWidth); } } if (imgWatermarkWidth >= imgPhotoWidth && imgWatermarkHeight >= imgPhotoHeight && imgWatermarkWidth >= imgWatermarkHeight) { imgWatermarkWidthNew = Convert.ToInt32(imgPhotoWidth * aScale); imgWatermarkHeightNew = Convert.ToInt32(((imgPhotoWidth * aScale) / imgWatermarkWidth) * imgWatermarkHeight); } if (imgWatermarkWidth >= imgPhotoWidth && imgWatermarkHeight <= imgPhotoHeight && imgPhotoWidth >= imgPhotoHeight) { imgWatermarkWidthNew = Convert.ToInt32(imgPhotoWidth * aScale); imgWatermarkHeightNew = Convert.ToInt32(((imgPhotoWidth * aScale) / imgWatermarkWidth) * imgWatermarkHeight); } if (imgWatermarkWidth <= imgPhotoWidth && imgWatermarkHeight >= imgPhotoHeight && imgPhotoWidth >= imgPhotoHeight) { imgWatermarkHeightNew = Convert.ToInt32(imgPhotoHeight * aScale); imgWatermarkWidthNew = Convert.ToInt32(((imgPhotoHeight * aScale) / imgWatermarkHeight) * imgWatermarkWidth); } if (imgPhotoWidth >= imgWatermarkWidth && imgPhotoHeight >= imgWatermarkHeight && imgPhotoWidth <= imgPhotoHeight) { if (imgWatermarkWidth > imgWatermarkHeight) { if ((MinScale <= Math.Round((Convert.ToDecimal(imgWatermarkWidth) / Convert.ToDecimal(imgPhotoWidth)), 7)) && (Math.Round((Convert.ToDecimal(imgWatermarkWidth) / Convert.ToDecimal(imgPhotoWidth)), 7) <= MaxScale)) { } else { imgWatermarkWidthNew = Convert.ToInt32(imgPhotoWidth * aScale); imgWatermarkHeightNew = Convert.ToInt32(((imgPhotoWidth * aScale) / imgWatermarkWidth) * imgWatermarkHeight); } } else if ((MinScale <= Math.Round((Convert.ToDecimal(imgWatermarkHeight) / Convert.ToDecimal(imgPhotoHeight)), 7)) && (Math.Round((Convert.ToDecimal(imgWatermarkHeight) / Convert.ToDecimal(imgPhotoHeight)), 7) <= MaxScale)) { } else { imgWatermarkHeightNew = Convert.ToInt32(imgPhotoHeight * aScale); imgWatermarkWidthNew = Convert.ToInt32(((imgPhotoHeight * aScale) / imgWatermarkHeight) * imgWatermarkWidth); } } if (imgWatermarkWidth >= imgPhotoWidth && imgWatermarkHeight >= imgPhotoHeight && imgWatermarkWidth <= imgWatermarkHeight) { imgWatermarkHeightNew = Convert.ToInt32(imgPhotoHeight * aScale); imgWatermarkWidthNew = Convert.ToInt32(((imgPhotoHeight * aScale) / imgWatermarkHeight) * imgWatermarkWidth); } if (imgWatermarkWidth >= imgPhotoWidth && imgWatermarkHeight <= imgPhotoHeight && imgPhotoWidth <= imgPhotoHeight) { imgWatermarkWidthNew = Convert.ToInt32(imgPhotoWidth * aScale); imgWatermarkHeightNew = Convert.ToInt32(((imgPhotoWidth * aScale) / imgWatermarkWidth) * imgWatermarkHeight); } if (imgWatermarkWidth <= imgPhotoWidth && imgWatermarkHeight >= imgPhotoHeight && imgPhotoWidth <= imgPhotoHeight) { imgWatermarkHeightNew = Convert.ToInt32(imgPhotoHeight * aScale); imgWatermarkWidthNew = Convert.ToInt32(((imgPhotoHeight * aScale) / imgWatermarkHeight) * imgWatermarkWidth); } //将原图画出来 Bitmap bmWatermark = new Bitmap(bmPhoto); bmWatermark.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution); Graphics gWatermark = Graphics.FromImage(bmWatermark); //指定高质量显示水印图片质量 gWatermark.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; gWatermark.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; System.Drawing.Imaging.ImageAttributes imageAttributes = new System.Drawing.Imaging.ImageAttributes(); //设置两种颜色,达到合成效果 System.Drawing.Imaging.ColorMap colorMap = new System.Drawing.Imaging.ColorMap(); colorMap.OldColor = Color.FromArgb(255, 0, 255, 0); colorMap.NewColor = Color.FromArgb(0, 0, 0, 0); System.Drawing.Imaging.ColorMap[] remapTable = { colorMap }; imageAttributes.SetRemapTable(remapTable, System.Drawing.Imaging.ColorAdjustType.Bitmap); //用矩阵设置水印图片透明度 float[][] colorMatrixElements = { new float[] { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f }, new float[] { 0.0f, 1.0f, 0.0f, 0.0f, 0.0f }, new float[] { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f }, new float[] { 0.0f, 0.0f, 0.0f, ImgAlpha, 0.0f }, new float[] { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f } }; System.Drawing.Imaging.ColorMatrix wmColorMatrix = new System.Drawing.Imaging.ColorMatrix(colorMatrixElements); imageAttributes.SetColorMatrix(wmColorMatrix, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap); //确定水印边距 int xPos = imgPhotoWidth - imgWatermarkWidthNew; int yPos = imgPhotoHeight - imgWatermarkHeightNew; int xPosOfWm = 0; int yPosOfWm = 0; if (xPos > intimgDistance) { xPosOfWm = xPos - intimgDistance; } else { xPosOfWm = xPos; } if (yPos > intimgDistance) { yPosOfWm = yPos - intimgDistance; } else { yPosOfWm = yPos; } gWatermark.DrawImage( imgWatermark , new Rectangle(xPosOfWm, yPosOfWm, imgWatermarkWidthNew, imgWatermarkHeightNew) , 0 , 0 , imgWatermarkWidth , imgWatermarkHeight , GraphicsUnit.Pixel , imageAttributes ); imgPhoto = bmWatermark; //以jpg格式保存图片 imgPhoto.Save(sImgPath, System.Drawing.Imaging.ImageFormat.Jpeg); //销毁对象 gbmPhoto.Dispose(); gWatermark.Dispose(); bmPhoto.Dispose(); imgPhoto.Dispose(); imgWatermark.Dispose(); } catch (Exception ex) { } }
/// <summary> /// 图片水印 /// </summary> /// <param name="ImgFile">原图文件地址</param> /// <param name="WaterImg">水印图片地址</param> /// <param name="sImgPath">水印图片保存地址</param> /// <param name="Alpha">水印透明度设置</param> /// <param name="iScale">水印图片在原图上的显示比例</param> /// <param name="intDistance">水印图片在原图上的边距确定,以图片的右边和下边为准,当设定的边距超过一定大小后参数会自动失效</param> public void zzsImgWater( string ImgFile , string WaterImg , string sImgPath , float Alpha , float iScale , int intDistance ) { try { //装载图片 FileStream fs = new FileStream(ImgFile, FileMode.Open); BinaryReader br = new BinaryReader(fs); byte[] bytes = br.ReadBytes((int)fs.Length); br.Close(); fs.Close(); MemoryStream ms = new MemoryStream(bytes); System.Drawing.Image imgPhoto = System.Drawing.Image.FromStream(ms); //System.Drawing.Image imgPhoto = System.Drawing.Image.FromFile(ImgFile); int imgPhotoWidth = imgPhoto.Width; int imgPhotoHeight = imgPhoto.Height; System.Drawing.Image imgWatermark = new Bitmap(WaterImg); int imgWatermarkWidth = imgWatermark.Width; int imgWatermarkHeight = imgWatermark.Height; //计算水印图片尺寸 decimal aScale = Convert.ToDecimal(iScale); decimal pScale = 0.05M; decimal MinScale = aScale - pScale; decimal MaxScale = aScale + pScale; int imgWatermarkWidthNew = imgWatermarkWidth; int imgWatermarkHeightNew = imgWatermarkHeight; if (imgPhotoWidth >= imgWatermarkWidth && imgPhotoHeight >= imgWatermarkHeight && imgPhotoWidth >= imgPhotoHeight) { if (imgWatermarkWidth > imgWatermarkHeight) { if ((MinScale <= Math.Round((Convert.ToDecimal(imgWatermarkWidth) / Convert.ToDecimal(imgPhotoWidth)), 7)) && (Math.Round((Convert.ToDecimal(imgWatermarkWidth) / Convert.ToDecimal(imgPhotoWidth)), 7) <= MaxScale)) { } else { imgWatermarkWidthNew = Convert.ToInt32(imgPhotoWidth * aScale); imgWatermarkHeightNew = Convert.ToInt32((imgPhotoWidth * aScale / imgWatermarkWidth) * imgWatermarkHeight); } } else if ((MinScale <= Math.Round((Convert.ToDecimal(imgWatermarkHeight) / Convert.ToDecimal(imgPhotoHeight)), 7)) && (Math.Round((Convert.ToDecimal(imgWatermarkHeight) / Convert.ToDecimal(imgPhotoHeight)), 7) <= MaxScale)) { } else { imgWatermarkHeightNew = Convert.ToInt32(imgPhotoHeight * aScale); imgWatermarkWidthNew = Convert.ToInt32((imgPhotoHeight * aScale / imgWatermarkHeight) * imgWatermarkWidth); } } if (imgWatermarkWidth >= imgPhotoWidth && imgWatermarkHeight >= imgPhotoHeight && imgWatermarkWidth >= imgWatermarkHeight) { imgWatermarkWidthNew = Convert.ToInt32(imgPhotoWidth * aScale); imgWatermarkHeightNew = Convert.ToInt32(((imgPhotoWidth * aScale) / imgWatermarkWidth) * imgWatermarkHeight); } if (imgWatermarkWidth >= imgPhotoWidth && imgWatermarkHeight <= imgPhotoHeight && imgPhotoWidth >= imgPhotoHeight) { imgWatermarkWidthNew = Convert.ToInt32(imgPhotoWidth * aScale); imgWatermarkHeightNew = Convert.ToInt32(((imgPhotoWidth * aScale) / imgWatermarkWidth) * imgWatermarkHeight); } if (imgWatermarkWidth <= imgPhotoWidth && imgWatermarkHeight >= imgPhotoHeight && imgPhotoWidth >= imgPhotoHeight) { imgWatermarkHeightNew = Convert.ToInt32(imgPhotoHeight * aScale); imgWatermarkWidthNew = Convert.ToInt32(((imgPhotoHeight * aScale) / imgWatermarkHeight) * imgWatermarkWidth); } if (imgPhotoWidth >= imgWatermarkWidth && imgPhotoHeight >= imgWatermarkHeight && imgPhotoWidth <= imgPhotoHeight) { if (imgWatermarkWidth > imgWatermarkHeight) { if ((MinScale <= Math.Round((Convert.ToDecimal(imgWatermarkWidth) / Convert.ToDecimal(imgPhotoWidth)), 7)) && (Math.Round((Convert.ToDecimal(imgWatermarkWidth) / Convert.ToDecimal(imgPhotoWidth)), 7) <= MaxScale)) { } else { imgWatermarkWidthNew = Convert.ToInt32(imgPhotoWidth * aScale); imgWatermarkHeightNew = Convert.ToInt32(((imgPhotoWidth * aScale) / imgWatermarkWidth) * imgWatermarkHeight); } } else if ((MinScale <= Math.Round((Convert.ToDecimal(imgWatermarkHeight) / Convert.ToDecimal(imgPhotoHeight)), 7)) && (Math.Round((Convert.ToDecimal(imgWatermarkHeight) / Convert.ToDecimal(imgPhotoHeight)), 7) <= MaxScale)) { } else { imgWatermarkHeightNew = Convert.ToInt32(imgPhotoHeight * aScale); imgWatermarkWidthNew = Convert.ToInt32(((imgPhotoHeight * aScale) / imgWatermarkHeight) * imgWatermarkWidth); } } if (imgWatermarkWidth >= imgPhotoWidth && imgWatermarkHeight >= imgPhotoHeight && imgWatermarkWidth <= imgWatermarkHeight) { imgWatermarkHeightNew = Convert.ToInt32(imgPhotoHeight * aScale); imgWatermarkWidthNew = Convert.ToInt32(((imgPhotoHeight * aScale) / imgWatermarkHeight) * imgWatermarkWidth); } if (imgWatermarkWidth >= imgPhotoWidth && imgWatermarkHeight <= imgPhotoHeight && imgPhotoWidth <= imgPhotoHeight) { imgWatermarkWidthNew = Convert.ToInt32(imgPhotoWidth * aScale); imgWatermarkHeightNew = Convert.ToInt32(((imgPhotoWidth * aScale) / imgWatermarkWidth) * imgWatermarkHeight); } if (imgWatermarkWidth <= imgPhotoWidth && imgWatermarkHeight >= imgPhotoHeight && imgPhotoWidth <= imgPhotoHeight) { imgWatermarkHeightNew = Convert.ToInt32(imgPhotoHeight * aScale); imgWatermarkWidthNew = Convert.ToInt32(((imgPhotoHeight * aScale) / imgWatermarkHeight) * imgWatermarkWidth); } //将原图画出来 Bitmap bmPhoto = new Bitmap(imgPhotoWidth, imgPhotoHeight, System.Drawing.Imaging.PixelFormat.Format24bppRgb); bmPhoto.SetResolution(72, 72); Graphics gbmPhoto = Graphics.FromImage(bmPhoto); gbmPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; gbmPhoto.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; gbmPhoto.Clear(Color.White); gbmPhoto.DrawImage( imgPhoto , new Rectangle(0, 0, imgPhotoWidth, imgPhotoHeight) , 0 , 0 , imgPhotoWidth , imgPhotoHeight , GraphicsUnit.Pixel ); Bitmap bmWatermark = new Bitmap(bmPhoto); bmWatermark.SetResolution(imgPhoto.HorizontalResolution, imgPhoto.VerticalResolution); Graphics gWatermark = Graphics.FromImage(bmWatermark); //指定高质量显示水印图片质量 gWatermark.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; gWatermark.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; System.Drawing.Imaging.ImageAttributes imageAttributes = new System.Drawing.Imaging.ImageAttributes(); //设置两种颜色,达到合成效果 System.Drawing.Imaging.ColorMap colorMap = new System.Drawing.Imaging.ColorMap(); colorMap.OldColor = Color.FromArgb(255, 0, 255, 0); colorMap.NewColor = Color.FromArgb(0, 0, 0, 0); System.Drawing.Imaging.ColorMap[] remapTable = { colorMap }; imageAttributes.SetRemapTable(remapTable, System.Drawing.Imaging.ColorAdjustType.Bitmap); //用矩阵设置水印图片透明度 float[][] colorMatrixElements = { new float[] { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f }, new float[] { 0.0f, 1.0f, 0.0f, 0.0f, 0.0f }, new float[] { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f }, new float[] { 0.0f, 0.0f, 0.0f, Alpha, 0.0f }, new float[] { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f } }; System.Drawing.Imaging.ColorMatrix wmColorMatrix = new System.Drawing.Imaging.ColorMatrix(colorMatrixElements); imageAttributes.SetColorMatrix(wmColorMatrix, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap); //确定水印边距 int xPos = imgPhotoWidth - imgWatermarkWidthNew; int yPos = imgPhotoHeight - imgWatermarkHeightNew; int xPosOfWm = 0; int yPosOfWm = 0; if (xPos > intDistance) { xPosOfWm = xPos - intDistance; } else { xPosOfWm = xPos; } if (yPos > intDistance) { yPosOfWm = yPos - intDistance; } else { yPosOfWm = yPos; } gWatermark.DrawImage( imgWatermark , new Rectangle(xPosOfWm, yPosOfWm, imgWatermarkWidthNew, imgWatermarkHeightNew) , 0 , 0 , imgWatermarkWidth , imgWatermarkHeight , GraphicsUnit.Pixel , imageAttributes ); imgPhoto = bmWatermark; //以jpg格式保存图片 imgPhoto.Save(sImgPath, System.Drawing.Imaging.ImageFormat.Jpeg); //销毁对象 gbmPhoto.Dispose(); gWatermark.Dispose(); imgPhoto.Dispose(); imgWatermark.Dispose(); } catch (Exception ex) { } }
/// <summary>Initializes a new instance of the <see cref="T:Common.Drawing.Imaging.ColorMap" /> class.</summary> public ColorMap() { WrappedColorMap = new System.Drawing.Imaging.ColorMap(); }
private void UpdateColorControls(Control parent , Control myControl, Font fnt, int level) { #if DEBUG //string pad = " ".Substring(0, level); //System.Diagnostics.Debug.WriteLine(pad + level + ":" + parent.Name.ToString() + ":" + myControl.Name.ToString() + " " + myControl.ToString()); #endif float mouseoverscaling = 1.3F; float mouseselectedscaling = 1.5F; Type controltype = myControl.GetType(); Type parentcontroltype = parent.GetType(); if (!parentcontroltype.Namespace.Equals("ExtendedControls") && (controltype.Name.Equals("Button") || controltype.Name.Equals("RadioButton") || controltype.Name.Equals("GroupBox") || controltype.Name.Equals("CheckBox") || controltype.Name.Equals("TextBox") || controltype.Name.Equals("ComboBox") || (controltype.Name.Equals("RichTextBox") ) ) ) { Debug.Assert(false, myControl.Name + " of " + controltype.Name + " from " + parent.Name + " !!! Use the new controls in Controls folder - not the non visual themed ones!"); } else if (myControl is MenuStrip || myControl is ToolStrip) { myControl.BackColor = currentsettings.colors[Settings.CI.menu_back]; myControl.ForeColor = currentsettings.colors[Settings.CI.menu_fore]; myControl.Font = fnt; } else if (myControl is RichTextBoxScroll) { RichTextBoxScroll MyDgv = (RichTextBoxScroll)myControl; MyDgv.BorderColor = Color.Transparent; MyDgv.BorderStyle = BorderStyle.None; MyDgv.TextBox.ForeColor = currentsettings.colors[Settings.CI.textbox_fore]; MyDgv.TextBox.BackColor = currentsettings.colors[Settings.CI.textbox_back]; MyDgv.ScrollBar.FlatStyle = FlatStyle.System; if (currentsettings.textboxborderstyle.Equals(TextboxBorderStyles[1])) MyDgv.BorderStyle = BorderStyle.FixedSingle; else if (currentsettings.textboxborderstyle.Equals(TextboxBorderStyles[2])) MyDgv.BorderStyle = BorderStyle.Fixed3D; else if (currentsettings.textboxborderstyle.Equals(TextboxBorderStyles[3])) { Color c1 = currentsettings.colors[Settings.CI.textbox_scrollbutton]; MyDgv.BorderColor = currentsettings.colors[Settings.CI.textbox_border]; MyDgv.ScrollBar.BackColor = currentsettings.colors[Settings.CI.textbox_back]; MyDgv.ScrollBar.SliderColor = currentsettings.colors[Settings.CI.textbox_sliderback]; MyDgv.ScrollBar.BorderColor = MyDgv.ScrollBar.ThumbBorderColor = MyDgv.ScrollBar.ArrowBorderColor = currentsettings.colors[Settings.CI.textbox_border]; MyDgv.ScrollBar.ArrowButtonColor = MyDgv.ScrollBar.ThumbButtonColor = c1; MyDgv.ScrollBar.MouseOverButtonColor = ButtonExt.Multiply(c1, mouseoverscaling); MyDgv.ScrollBar.MousePressedButtonColor = ButtonExt.Multiply(c1, mouseselectedscaling); MyDgv.ScrollBar.ForeColor = currentsettings.colors[Settings.CI.textbox_scrollarrow]; MyDgv.ScrollBar.FlatStyle = FlatStyle.Popup; } if (myControl.Font.Name.Contains("Courier")) // okay if we ordered a fixed font, don't override { Font fntf = new Font(myControl.Font.Name, currentsettings.fontsize); // make one of the selected size myControl.Font = fntf; } else myControl.Font = fnt; MyDgv.Invalidate(); MyDgv.PerformLayout(); } else if (myControl is TextBoxBorder) { TextBoxBorder MyDgv = (TextBoxBorder)myControl; myControl.ForeColor = currentsettings.colors[Settings.CI.textbox_fore]; myControl.BackColor = currentsettings.colors[Settings.CI.textbox_back]; MyDgv.BorderColor = Color.Transparent; MyDgv.BorderStyle = BorderStyle.None; MyDgv.AutoSize = true; if (currentsettings.textboxborderstyle.Equals(TextboxBorderStyles[0])) MyDgv.AutoSize = false; // with no border, the autosize clips the bottom of chars.. else if (currentsettings.textboxborderstyle.Equals(TextboxBorderStyles[1])) MyDgv.BorderStyle = BorderStyle.FixedSingle; else if (currentsettings.textboxborderstyle.Equals(TextboxBorderStyles[2])) MyDgv.BorderStyle = BorderStyle.Fixed3D; else if (currentsettings.textboxborderstyle.Equals(TextboxBorderStyles[3])) MyDgv.BorderColor = currentsettings.colors[Settings.CI.textbox_border]; myControl.Font = fnt; if (myControl is AutoCompleteTextBox) // derived from text box { AutoCompleteTextBox actb = myControl as AutoCompleteTextBox; actb.DropDownBackgroundColor = currentsettings.colors[Settings.CI.button_back]; actb.DropDownBorderColor = currentsettings.colors[Settings.CI.textbox_border]; actb.DropDownScrollBarButtonColor = currentsettings.colors[Settings.CI.textbox_scrollbutton]; actb.DropDownScrollBarColor = currentsettings.colors[Settings.CI.textbox_sliderback]; actb.DropDownMouseOverBackgroundColor = ButtonExt.Multiply(currentsettings.colors[Settings.CI.button_back], mouseoverscaling); if (currentsettings.buttonstyle.Equals(ButtonStyles[0])) actb.FlatStyle = FlatStyle.System; else if (currentsettings.buttonstyle.Equals(ButtonStyles[1])) // flat actb.FlatStyle = FlatStyle.Flat; else actb.FlatStyle = FlatStyle.Popup; } } else if (myControl is ButtonExt) { ButtonExt MyDgv = (ButtonExt)myControl; MyDgv.ForeColor = currentsettings.colors[Settings.CI.button_text]; if (currentsettings.buttonstyle.Equals(ButtonStyles[0])) // system { MyDgv.FlatStyle = FlatStyle.System; MyDgv.UseVisualStyleBackColor = true; // this makes it system.. } else { MyDgv.BackColor = currentsettings.colors[Settings.CI.button_back]; MyDgv.FlatAppearance.BorderColor = currentsettings.colors[Settings.CI.button_border]; MyDgv.FlatAppearance.BorderSize = 1; MyDgv.FlatAppearance.MouseOverBackColor = ButtonExt.Multiply(currentsettings.colors[Settings.CI.button_back], mouseoverscaling); MyDgv.FlatAppearance.MouseDownBackColor = ButtonExt.Multiply(currentsettings.colors[Settings.CI.button_back], mouseselectedscaling); if (currentsettings.buttonstyle.Equals(ButtonStyles[1])) // flat MyDgv.FlatStyle = FlatStyle.Flat; else MyDgv.FlatStyle = FlatStyle.Popup; } myControl.Font = fnt; } else if (myControl is TabControlCustom) { TabControlCustom MyDgv = (TabControlCustom)myControl; if (!currentsettings.buttonstyle.Equals(ButtonStyles[0])) // not system { MyDgv.FlatStyle = (currentsettings.buttonstyle.Equals(ButtonStyles[1])) ? FlatStyle.Flat : FlatStyle.Popup; MyDgv.TabControlBorderColor = ButtonExt.Multiply(currentsettings.colors[Settings.CI.tabcontrol_borderlines], 0.6F); MyDgv.TabControlBorderBrightColor = currentsettings.colors[Settings.CI.tabcontrol_borderlines]; MyDgv.TabNotSelectedBorderColor = ButtonExt.Multiply(currentsettings.colors[Settings.CI.tabcontrol_borderlines], 0.4F); MyDgv.TabNotSelectedColor = currentsettings.colors[Settings.CI.button_back]; MyDgv.TabSelectedColor = ButtonExt.Multiply(currentsettings.colors[Settings.CI.button_back], mouseselectedscaling); MyDgv.TabMouseOverColor = ButtonExt.Multiply(currentsettings.colors[Settings.CI.button_back], mouseoverscaling); MyDgv.TextSelectedColor = currentsettings.colors[Settings.CI.button_text]; MyDgv.TextNotSelectedColor = ButtonExt.Multiply(currentsettings.colors[Settings.CI.button_text], 0.8F); MyDgv.TabStyle = new ExtendedControls.TabStyleAngled(); } else MyDgv.FlatStyle = FlatStyle.System; MyDgv.Font = fnt; } else if (myControl is ListControlCustom) { ListControlCustom MyDgv = (ListControlCustom)myControl; MyDgv.ForeColor = currentsettings.colors[Settings.CI.button_text]; if (currentsettings.buttonstyle.Equals(ButtonStyles[0])) { MyDgv.FlatStyle = FlatStyle.System; } else { MyDgv.BackColor = currentsettings.colors[Settings.CI.button_back]; MyDgv.BorderColor = currentsettings.colors[Settings.CI.button_border]; MyDgv.ScrollBarButtonColor = currentsettings.colors[Settings.CI.textbox_scrollbutton]; MyDgv.ScrollBarColor = currentsettings.colors[Settings.CI.textbox_sliderback]; if (currentsettings.buttonstyle.Equals(ButtonStyles[1])) // flat MyDgv.FlatStyle = FlatStyle.Flat; else MyDgv.FlatStyle = FlatStyle.Popup; } myControl.Font = fnt; MyDgv.Repaint(); // force a repaint as the individual settings do not by design. } else if (myControl is ComboBoxCustom) { ComboBoxCustom MyDgv = (ComboBoxCustom)myControl; MyDgv.ForeColor = currentsettings.colors[Settings.CI.button_text]; if (currentsettings.buttonstyle.Equals(ButtonStyles[0])) // system { MyDgv.FlatStyle = FlatStyle.System; } else { MyDgv.BackColor = MyDgv.DropDownBackgroundColor = currentsettings.colors[Settings.CI.button_back]; MyDgv.BorderColor = currentsettings.colors[Settings.CI.button_border]; MyDgv.MouseOverBackgroundColor = ButtonExt.Multiply(currentsettings.colors[Settings.CI.button_back], mouseoverscaling); MyDgv.ScrollBarButtonColor = currentsettings.colors[Settings.CI.textbox_scrollbutton]; MyDgv.ScrollBarColor = currentsettings.colors[Settings.CI.textbox_sliderback]; if (currentsettings.buttonstyle.Equals(ButtonStyles[1])) // flat MyDgv.FlatStyle = FlatStyle.Flat; else MyDgv.FlatStyle = FlatStyle.Popup; } myControl.Font = fnt; MyDgv.Repaint(); // force a repaint as the individual settings do not by design. } else if (myControl is NumericUpDown) { // BACK colour does not work.. myControl.ForeColor = currentsettings.colors[Settings.CI.textbox_fore]; myControl.Font = fnt; } else if (myControl is DrawnPanelNoTheme) // ignore these.. { } else if (myControl is DrawnPanel) { DrawnPanel MyDgv = (DrawnPanel)myControl; MyDgv.BackColor = currentsettings.colors[Settings.CI.form]; MyDgv.ForeColor = currentsettings.colors[Settings.CI.label]; MyDgv.MouseOverColor = ButtonExt.Multiply(currentsettings.colors[Settings.CI.label], mouseoverscaling); MyDgv.MouseSelectedColor = ButtonExt.Multiply(currentsettings.colors[Settings.CI.label], mouseselectedscaling); System.Drawing.Imaging.ColorMap colormap = new System.Drawing.Imaging.ColorMap(); // any drawn panel with drawn images colormap.OldColor = Color.White; // white is defined as the forecolour colormap.NewColor = MyDgv.ForeColor; MyDgv.SetDrawnBitmapRemapTable(new System.Drawing.Imaging.ColorMap[] { colormap }); } else if (myControl is Panel) { if (!(myControl.Name.Contains("defaultmapcolor"))) // theme panels show settings color - don't overwrite { myControl.BackColor = currentsettings.colors[Settings.CI.form]; myControl.ForeColor = currentsettings.colors[Settings.CI.label]; } } else if (myControl is Label) { myControl.ForeColor = currentsettings.colors[Settings.CI.label]; myControl.Font = fnt; } else if (myControl is GroupBoxCustom) { GroupBoxCustom MyDgv = (GroupBoxCustom)myControl; MyDgv.ForeColor = currentsettings.colors[Settings.CI.group_text]; MyDgv.BackColor = currentsettings.colors[Settings.CI.group_back]; MyDgv.BorderColor = currentsettings.colors[Settings.CI.group_borderlines]; MyDgv.FlatStyle = FlatStyle.Flat; // always in Flat, always apply our border. MyDgv.Font = fnt; } else if (myControl is CheckBoxCustom) { CheckBoxCustom MyDgv = (CheckBoxCustom)myControl; if (MyDgv.Appearance != Appearance.Button) // Buttons are always left in the appearance selected by the code as the { // Standard type for buttons covers what we need. if (currentsettings.buttonstyle.Equals(ButtonStyles[0])) // system MyDgv.FlatStyle = FlatStyle.System; else if (currentsettings.buttonstyle.Equals(ButtonStyles[1])) // flat MyDgv.FlatStyle = FlatStyle.Flat; else MyDgv.FlatStyle = FlatStyle.Popup; MyDgv.BackColor = GroupBoxOverride(parent, currentsettings.colors[Settings.CI.form]); MyDgv.ForeColor = currentsettings.colors[Settings.CI.checkbox]; MyDgv.CheckBoxColor = currentsettings.colors[Settings.CI.checkbox]; MyDgv.CheckBoxInnerColor = ButtonExt.Multiply(currentsettings.colors[Settings.CI.checkbox], 1.5F); MyDgv.CheckColor = currentsettings.colors[Settings.CI.checkbox_tick]; MyDgv.MouseOverColor = ButtonExt.Multiply(currentsettings.colors[Settings.CI.checkbox], 1.4F); MyDgv.TickBoxReductionSize = (fnt.SizeInPoints > 10) ? 10 : 6; MyDgv.Font = fnt; } } else if (myControl is RadioButtonCustom) { RadioButtonCustom MyDgv = (RadioButtonCustom)myControl; MyDgv.FlatStyle = FlatStyle.System; MyDgv.Font = fnt; if (currentsettings.buttonstyle.Equals(ButtonStyles[0])) // system MyDgv.FlatStyle = FlatStyle.System; else if (currentsettings.buttonstyle.Equals(ButtonStyles[1])) // flat MyDgv.FlatStyle = FlatStyle.Flat; else MyDgv.FlatStyle = FlatStyle.Popup; //Console.WriteLine("RB:" + myControl.Name + " Apply style " + currentsettings.buttonstyle); MyDgv.BackColor = GroupBoxOverride(parent, currentsettings.colors[Settings.CI.form]); MyDgv.ForeColor = currentsettings.colors[Settings.CI.checkbox]; MyDgv.RadioButtonColor = currentsettings.colors[Settings.CI.checkbox]; MyDgv.RadioButtonInnerColor = ButtonExt.Multiply(currentsettings.colors[Settings.CI.checkbox], 1.5F); MyDgv.SelectedColor = ButtonExt.Multiply(MyDgv.BackColor, 0.75F); MyDgv.MouseOverColor = ButtonExt.Multiply(currentsettings.colors[Settings.CI.checkbox], 1.4F); } else if (myControl is DataGridView) // we theme this directly { DataGridView MyDgv = (DataGridView)myControl; MyDgv.EnableHeadersVisualStyles = false; // without this, the colours for the grid are not applied. MyDgv.RowHeadersDefaultCellStyle.BackColor = currentsettings.colors[Settings.CI.grid_borderback]; MyDgv.RowHeadersDefaultCellStyle.ForeColor = currentsettings.colors[Settings.CI.grid_bordertext]; MyDgv.ColumnHeadersDefaultCellStyle.BackColor = currentsettings.colors[Settings.CI.grid_borderback]; MyDgv.ColumnHeadersDefaultCellStyle.ForeColor = currentsettings.colors[Settings.CI.grid_bordertext]; MyDgv.BackgroundColor = GroupBoxOverride(parent, currentsettings.colors[Settings.CI.form]); MyDgv.DefaultCellStyle.BackColor = GroupBoxOverride(parent, currentsettings.colors[Settings.CI.grid_cellbackground]); MyDgv.DefaultCellStyle.ForeColor = currentsettings.colors[Settings.CI.grid_celltext]; MyDgv.DefaultCellStyle.SelectionBackColor = MyDgv.DefaultCellStyle.ForeColor; MyDgv.DefaultCellStyle.SelectionForeColor = MyDgv.DefaultCellStyle.BackColor; MyDgv.GridColor = currentsettings.colors[Settings.CI.grid_borderlines]; MyDgv.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single; MyDgv.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single; MyDgv.Font = fnt; Font fnt2; if (myControl.Name.Contains("dataGridViewTravel") && fnt.Size > 10F) fnt2 = new Font(currentsettings.fontname, 10F); else fnt2 = fnt; MyDgv.ColumnHeadersDefaultCellStyle.Font = fnt2; MyDgv.RowHeadersDefaultCellStyle.Font = fnt2; MyDgv.Columns[0].DefaultCellStyle.Font = fnt2; using (Graphics g = MyDgv.CreateGraphics()) { SizeF sz = g.MeasureString("99999", fnt2); MyDgv.RowHeadersWidth = (int)(sz.Width + 6); // size it to the text, need a little more for rounding } } else if (myControl is VScrollBarCustom && !(parent is ListControlCustom || parent is RichTextBoxScroll)) { // selected items need VScroll controlled here. Others control it themselves VScrollBarCustom MyDgv = (VScrollBarCustom)myControl; //System.Diagnostics.Debug.WriteLine("VScrollBarCustom Theme " + level + ":" + parent.Name.ToString() + ":" + myControl.Name.ToString() + " " + myControl.ToString() + " " + parentcontroltype.Name); if (currentsettings.textboxborderstyle.Equals(TextboxBorderStyles[3])) { Color c1 = currentsettings.colors[Settings.CI.grid_scrollbutton]; MyDgv.BorderColor = currentsettings.colors[Settings.CI.grid_borderlines]; MyDgv.BackColor = currentsettings.colors[Settings.CI.form]; MyDgv.SliderColor = currentsettings.colors[Settings.CI.grid_sliderback]; MyDgv.BorderColor = MyDgv.ThumbBorderColor = MyDgv.ArrowBorderColor = currentsettings.colors[Settings.CI.grid_borderlines]; MyDgv.ArrowButtonColor = MyDgv.ThumbButtonColor = c1; MyDgv.MouseOverButtonColor = ButtonExt.Multiply(c1, mouseoverscaling); MyDgv.MousePressedButtonColor = ButtonExt.Multiply(c1, mouseselectedscaling); MyDgv.ForeColor = currentsettings.colors[Settings.CI.grid_scrollarrow]; MyDgv.FlatStyle = FlatStyle.Popup; } else MyDgv.FlatStyle = FlatStyle.System; } else if (myControl is NumericUpDownCustom) { NumericUpDownCustom MyDgv = (NumericUpDownCustom)myControl; MyDgv.TextBoxForeColor = currentsettings.colors[Settings.CI.textbox_fore]; MyDgv.TextBoxBackColor = currentsettings.colors[Settings.CI.textbox_back]; MyDgv.BorderColor = currentsettings.colors[Settings.CI.textbox_border]; Color c1 = currentsettings.colors[Settings.CI.textbox_scrollbutton]; MyDgv.updown.BackColor = c1; MyDgv.updown.ForeColor = currentsettings.colors[Settings.CI.textbox_scrollarrow]; MyDgv.updown.MouseOverColor = ButtonExt.Multiply(c1, mouseoverscaling); MyDgv.updown.MouseSelectedColor = ButtonExt.Multiply(c1, mouseselectedscaling); MyDgv.Invalidate(); } else if (myControl is Chart) { Chart ctrl = (Chart)myControl; ctrl.BackColor = Color.Transparent; } else { if (!parentcontroltype.Namespace.Equals("ExtendedControls")) { //Console.WriteLine("THEME: Unhandled control " + controltype.Name + ":" + myControl.Name + " from " + parent.Name); } } foreach (Control subC in myControl.Controls) { UpdateColorControls(myControl,subC,fnt,level+1); } }
/// <summary> /// 加图片水印 /// </summary> /// <param name="filename">文件名</param> /// <param name="watermarkFilename">水印文件名</param> /// <param name="watermarkStatus">图片水印位置:0=不使用 1=左上 2=中上 3=右上 4=左中 ... 9=右下</param> /// <param name="quality">是否是高质量图片 取值范围0--100</param> /// <param name="watermarkTransparency">图片水印透明度 取值范围1--10 (10为不透明)</param> public static void AddImageSignPic(string Path, string filename, string watermarkFilename, int watermarkStatus, int quality, int watermarkTransparency) { System.Drawing.Image img = System.Drawing.Image.FromFile(Path); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(img); //设置高质量插值法 //g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; //设置高质量,低速度呈现平滑程度 //g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; System.Drawing.Image watermark = new System.Drawing.Bitmap(watermarkFilename); if (watermark.Height >= img.Height || watermark.Width >= img.Width) { return; } System.Drawing.Imaging.ImageAttributes imageAttributes = new System.Drawing.Imaging.ImageAttributes(); System.Drawing.Imaging.ColorMap colorMap = new System.Drawing.Imaging.ColorMap(); colorMap.OldColor = System.Drawing.Color.FromArgb(255, 0, 255, 0); colorMap.NewColor = System.Drawing.Color.FromArgb(0, 0, 0, 0); System.Drawing.Imaging.ColorMap[] remapTable = { colorMap }; imageAttributes.SetRemapTable(remapTable, System.Drawing.Imaging.ColorAdjustType.Bitmap); float transparency = 0.5F; if (watermarkTransparency >= 1 && watermarkTransparency <= 10) { transparency = (watermarkTransparency / 10.0F); } float[][] colorMatrixElements = { new float[] { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f }, new float[] { 0.0f, 1.0f, 0.0f, 0.0f, 0.0f }, new float[] { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f }, new float[] { 0.0f, 0.0f, 0.0f, transparency, 0.0f }, new float[] { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f } }; System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(colorMatrixElements); imageAttributes.SetColorMatrix(colorMatrix, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap); int xpos = 0; int ypos = 0; switch (watermarkStatus) { case 1: xpos = (int)(img.Width * (float).01); ypos = (int)(img.Height * (float).01); break; case 2: xpos = (int)((img.Width * (float).50) - (watermark.Width / 2)); ypos = (int)(img.Height * (float).01); break; case 3: xpos = (int)((img.Width * (float).99) - (watermark.Width)); ypos = (int)(img.Height * (float).01); break; case 4: xpos = (int)(img.Width * (float).01); ypos = (int)((img.Height * (float).50) - (watermark.Height / 2)); break; case 5: xpos = (int)((img.Width * (float).50) - (watermark.Width / 2)); ypos = (int)((img.Height * (float).50) - (watermark.Height / 2)); break; case 6: xpos = (int)((img.Width * (float).99) - (watermark.Width)); ypos = (int)((img.Height * (float).50) - (watermark.Height / 2)); break; case 7: xpos = (int)(img.Width * (float).01); ypos = (int)((img.Height * (float).99) - watermark.Height); break; case 8: xpos = (int)((img.Width * (float).50) - (watermark.Width / 2)); ypos = (int)((img.Height * (float).99) - watermark.Height); break; case 9: xpos = (int)((img.Width * (float).99) - (watermark.Width)); ypos = (int)((img.Height * (float).99) - watermark.Height); break; } g.DrawImage(watermark, new System.Drawing.Rectangle(xpos, ypos, watermark.Width, watermark.Height), 0, 0, watermark.Width, watermark.Height, System.Drawing.GraphicsUnit.Pixel, imageAttributes); System.Drawing.Imaging.ImageCodecInfo[] codecs = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders(); System.Drawing.Imaging.ImageCodecInfo ici = null; foreach (System.Drawing.Imaging.ImageCodecInfo codec in codecs) { //if (codec.MimeType.IndexOf("jpeg") > -1) if (codec.MimeType.Contains("jpeg")) { ici = codec; } } System.Drawing.Imaging.EncoderParameters encoderParams = new System.Drawing.Imaging.EncoderParameters(); long[] qualityParam = new long[1]; if (quality < 0 || quality > 100) { quality = 80; } qualityParam[0] = quality; System.Drawing.Imaging.EncoderParameter encoderParam = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qualityParam); encoderParams.Param[0] = encoderParam; if (ici != null) { img.Save(filename, ici, encoderParams); } else { img.Save(filename); } g.Dispose(); img.Dispose(); watermark.Dispose(); imageAttributes.Dispose(); }
/// <summary> /// 加图片水印 /// </summary> /// <param name="filename">文件名</param> /// <param name="watermarkFilename">水印文件名</param> /// <param name="watermarkStatus">图片水印位置:0=不使用 1=左上 2=中上 3=右上 4=左中 ... 9=右下</param> /// <param name="quality">是否是高质量图片 取值范围0--100</param> /// <param name="watermarkTransparency">图片水印透明度 取值范围1--10 (10为不透明)</param> public static void AddImageSignPic(string Path, string filename, string watermarkFilename, int watermarkStatus, int quality, int watermarkTransparency) { System.Drawing.Image img = System.Drawing.Image.FromFile(Path); System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(img); //设置高质量插值法 //g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; //设置高质量,低速度呈现平滑程度 //g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; System.Drawing.Image watermark = new System.Drawing.Bitmap(watermarkFilename); if (watermark.Height >= img.Height || watermark.Width >= img.Width) { return; } System.Drawing.Imaging.ImageAttributes imageAttributes = new System.Drawing.Imaging.ImageAttributes(); System.Drawing.Imaging.ColorMap colorMap = new System.Drawing.Imaging.ColorMap(); colorMap.OldColor = System.Drawing.Color.FromArgb(255, 0, 255, 0); colorMap.NewColor = System.Drawing.Color.FromArgb(0, 0, 0, 0); System.Drawing.Imaging.ColorMap[] remapTable = { colorMap }; imageAttributes.SetRemapTable(remapTable, System.Drawing.Imaging.ColorAdjustType.Bitmap); float transparency = 0.5F; if (watermarkTransparency >= 1 && watermarkTransparency <= 10) { transparency = (watermarkTransparency / 10.0F); } float[][] colorMatrixElements = { new float[] {1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, new float[] {0.0f, 1.0f, 0.0f, 0.0f, 0.0f}, new float[] {0.0f, 0.0f, 1.0f, 0.0f, 0.0f}, new float[] {0.0f, 0.0f, 0.0f, transparency, 0.0f}, new float[] {0.0f, 0.0f, 0.0f, 0.0f, 1.0f} }; System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(colorMatrixElements); imageAttributes.SetColorMatrix(colorMatrix, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap); int xpos = 0; int ypos = 0; switch (watermarkStatus) { case 1: xpos = (int)(img.Width * (float).01); ypos = (int)(img.Height * (float).01); break; case 2: xpos = (int)((img.Width * (float).50) - (watermark.Width / 2)); ypos = (int)(img.Height * (float).01); break; case 3: xpos = (int)((img.Width * (float).99) - (watermark.Width)); ypos = (int)(img.Height * (float).01); break; case 4: xpos = (int)(img.Width * (float).01); ypos = (int)((img.Height * (float).50) - (watermark.Height / 2)); break; case 5: xpos = (int)((img.Width * (float).50) - (watermark.Width / 2)); ypos = (int)((img.Height * (float).50) - (watermark.Height / 2)); break; case 6: xpos = (int)((img.Width * (float).99) - (watermark.Width)); ypos = (int)((img.Height * (float).50) - (watermark.Height / 2)); break; case 7: xpos = (int)(img.Width * (float).01); ypos = (int)((img.Height * (float).99) - watermark.Height); break; case 8: xpos = (int)((img.Width * (float).50) - (watermark.Width / 2)); ypos = (int)((img.Height * (float).99) - watermark.Height); break; case 9: xpos = (int)((img.Width * (float).99) - (watermark.Width)); ypos = (int)((img.Height * (float).99) - watermark.Height); break; } g.DrawImage(watermark, new System.Drawing.Rectangle(xpos, ypos, watermark.Width, watermark.Height), 0, 0, watermark.Width, watermark.Height, System.Drawing.GraphicsUnit.Pixel, imageAttributes); System.Drawing.Imaging.ImageCodecInfo[] codecs = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders(); System.Drawing.Imaging.ImageCodecInfo ici = null; foreach (System.Drawing.Imaging.ImageCodecInfo codec in codecs) { //if (codec.MimeType.IndexOf("jpeg") > -1) if (codec.MimeType.Contains("jpeg")) { ici = codec; } } System.Drawing.Imaging.EncoderParameters encoderParams = new System.Drawing.Imaging.EncoderParameters(); long[] qualityParam = new long[1]; if (quality < 0 || quality > 100) { quality = 80; } qualityParam[0] = quality; System.Drawing.Imaging.EncoderParameter encoderParam = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qualityParam); encoderParams.Param[0] = encoderParam; if (ici != null) { img.Save(filename, ici, encoderParams); } else { img.Save(filename); } g.Dispose(); img.Dispose(); watermark.Dispose(); imageAttributes.Dispose(); }
/// <summary> /// Draws the icon image at the specified location. /// </summary> /// <param name="graphics">The Graphics to draw on.</param> /// <param name="imgPanelIcon">icon image to draw.</param> /// <param name="imageRectangle">A rectangle structure that specifies the bounds of the linear gradient.</param> /// <param name="foreColorImage">The foreground color of this image</param> /// <param name="iconPositionY">The vertical position for the icon image</param> protected static void DrawIcon(Graphics graphics, Image imgPanelIcon, Rectangle imageRectangle, Color foreColorImage, int iconPositionY) { if (graphics == null) { throw new ArgumentException( string.Format( System.Globalization.CultureInfo.CurrentUICulture, Resources.IDS_ArgumentException, typeof(Graphics).Name)); } if (imgPanelIcon == null) { throw new ArgumentException( string.Format( System.Globalization.CultureInfo.CurrentUICulture, Resources.IDS_ArgumentException, typeof(Image).Name)); } int iconPositionX = imageRectangle.Left; int iconWidth = imgPanelIcon.Width; int iconHeight = imgPanelIcon.Height; Rectangle rectangleIcon = new Rectangle( iconPositionX + (iconWidth / 2) - 1, iconPositionY + (iconHeight / 2) - 1, imgPanelIcon.Width, imgPanelIcon.Height - 1); using (System.Drawing.Imaging.ImageAttributes imageAttribute = new System.Drawing.Imaging.ImageAttributes()) { imageAttribute.SetColorKey(Color.Magenta, Color.Magenta); System.Drawing.Imaging.ColorMap colorMap = new System.Drawing.Imaging.ColorMap(); colorMap.OldColor = Color.FromArgb(0, 60, 166); colorMap.NewColor = foreColorImage; imageAttribute.SetRemapTable(new System.Drawing.Imaging.ColorMap[] { colorMap }); graphics.DrawImage(imgPanelIcon, rectangleIcon, 0, 0, iconWidth, iconHeight, GraphicsUnit.Pixel, imageAttribute); } }
private ColorMap(System.Drawing.Imaging.ColorMap colorMap) { WrappedColorMap = colorMap; }
// curmats may be null Point CreateMaterialNodes(List <ExtPictureBox.ImageElement> pc, JournalScan sn, List <MaterialCommodityMicroResource> historicmats, List <MaterialCommodityMicroResource> curmats, Point matpos, Size matsize) { Point startpos = matpos; Point maximum = matpos; int noperline = 0; string matclicktext = sn.DisplayMaterials(2, historicmats, curmats); foreach (KeyValuePair <string, double> sd in sn.Materials) { string tooltip = sn.DisplayMaterial(sd.Key, sd.Value, historicmats, curmats); Color fillc = Color.Yellow; string abv = sd.Key.Substring(0, 1); MaterialCommodityMicroResourceType mc = MaterialCommodityMicroResourceType.GetByFDName(sd.Key); if (mc != null) { abv = mc.Shortname; fillc = mc.Colour; //System.Diagnostics.Debug.WriteLine("Colour {0} {1}", fillc.ToString(), fillc.GetBrightness()); if (HideFullMaterials) // check full { int?limit = mc.MaterialLimit(); MaterialCommodityMicroResource matnow = curmats?.Find(x => x.Details == mc); // allow curmats = null // debug if (matnow != null && mc.shortname == "Fe") matnow.count = 10000; if (matnow != null && limit != null && matnow.Count >= limit) // and limit { continue; } } if (ShowOnlyMaterialsRare && mc.IsCommonMaterial) { continue; } } System.Drawing.Imaging.ColorMap colormap = new System.Drawing.Imaging.ColorMap(); colormap.OldColor = Color.White; // this is the marker colour to replace colormap.NewColor = fillc; Bitmap mat = BaseUtils.BitMapHelpers.ReplaceColourInBitmap((Bitmap)BaseUtils.Icons.IconSet.GetIcon("Controls.Scan.Bodies.Material"), new System.Drawing.Imaging.ColorMap[] { colormap }); BaseUtils.BitMapHelpers.DrawTextCentreIntoBitmap(ref mat, abv, Font, fillc.GetBrightness() > 0.4f ? Color.Black : Color.White); ExtPictureBox.ImageElement ie = new ExtPictureBox.ImageElement( new Rectangle(matpos.X, matpos.Y, matsize.Width, matsize.Height), mat, tooltip + "\n\n" + "All " + matclicktext, tooltip); pc.Add(ie); maximum = new Point(Math.Max(maximum.X, matpos.X + matsize.Width), Math.Max(maximum.Y, matpos.Y + matsize.Height)); if (++noperline == 4) { matpos = new Point(startpos.X, matpos.Y + matsize.Height + materiallinespacerxy); noperline = 0; } else { matpos.X += matsize.Width + materiallinespacerxy; } } return(maximum); }
void CreateMaterialImage(List<PictureBoxHotspot.ImageElement> pc, Point matpos, Size matsize, string text, string mattag, string mattip, Color matcolour , Color textcolour) { System.Drawing.Imaging.ColorMap colormap = new System.Drawing.Imaging.ColorMap(); colormap.OldColor = Color.White; // this is the marker colour to replace colormap.NewColor = matcolour; Bitmap mat = ControlHelpers.ReplaceColourInBitmap(EDDiscovery.Properties.Resources.materialmarkerorangefilled, new System.Drawing.Imaging.ColorMap[] { colormap }); ControlHelpers.DrawTextCentreIntoBitmap(ref mat, text, stdfont, textcolour); PictureBoxHotspot.ImageElement ie = new PictureBoxHotspot.ImageElement( new Rectangle(matpos.X, matpos.Y, matsize.Width, matsize.Height), mat, mattag, mattip); pc.Add(ie); }
/// <summary> /// 在图片上生成图片水印 /// </summary> /// <param name="sourcePath">原图片路径</param> /// <param name="targetPath">另存为路径</param> /// <param name="waterMarkFilePath">水印图片路径</param> /// <param name="positionType">图片水印位置:UL,UM , UR , ML , MM , MR , BL , BM , BR ,CUSTORM 为自定义.</param> /// <param name="quality">是否是高质量图片 取值范围0--100</param> /// <param name="watermarkTransparency">图片水印透明度 取值范围1--10 (10为不透明)</param> /// <returns></returns> public static bool PictureWatermark(string sourcePath, string targetPath, string waterMarkFilePath, PicWaterMarkPosition positionType, int quality, int watermarkTransparency) { System.Drawing.Image img = System.Drawing.Image.FromFile(sourcePath); System.Drawing.Bitmap outPut = new System.Drawing.Bitmap(img); try { #region using using (Graphics g = Graphics.FromImage(outPut)) { //设置高质量插值法 //g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; //设置高质量,低速度呈现平滑程度 //g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; System.Drawing.Image markImg = new System.Drawing.Bitmap(waterMarkFilePath); if (markImg.Height >= img.Height || markImg.Width >= img.Width) { return false; } System.Drawing.Imaging.ImageAttributes imageAttributes = new System.Drawing.Imaging.ImageAttributes(); System.Drawing.Imaging.ColorMap colorMap = new System.Drawing.Imaging.ColorMap(); colorMap.OldColor = System.Drawing.Color.FromArgb(255, 0, 255, 0); colorMap.NewColor = System.Drawing.Color.FromArgb(0, 0, 0, 0); System.Drawing.Imaging.ColorMap[] remapTable = { colorMap }; imageAttributes.SetRemapTable(remapTable, System.Drawing.Imaging.ColorAdjustType.Bitmap); float transparency = 0.5F; if (watermarkTransparency >= 1 && watermarkTransparency <= 10) { transparency = (watermarkTransparency / 10.0F); } float[][] colorMatrixElements = { new float[] {1.0f, 0.0f, 0.0f, 0.0f, 0.0f}, new float[] {0.0f, 1.0f, 0.0f, 0.0f, 0.0f}, new float[] {0.0f, 0.0f, 1.0f, 0.0f, 0.0f}, new float[] {0.0f, 0.0f, 0.0f, transparency, 0.0f}, new float[] {0.0f, 0.0f, 0.0f, 0.0f, 1.0f} }; System.Drawing.Imaging.ColorMatrix colorMatrix = new System.Drawing.Imaging.ColorMatrix(colorMatrixElements); imageAttributes.SetColorMatrix(colorMatrix, System.Drawing.Imaging.ColorMatrixFlag.Default, System.Drawing.Imaging.ColorAdjustType.Bitmap); int xpos = 0; int ypos = 0; #region position switch (positionType) { case PicWaterMarkPosition.UL: xpos = (int)(img.Width * (float).01); ypos = (int)(img.Height * (float).01); break; case PicWaterMarkPosition.UM: xpos = (int)((img.Width * (float).50) - (markImg.Width / 2)); ypos = (int)(img.Height * (float).01); break; case PicWaterMarkPosition.UR: xpos = (int)((img.Width * (float).99) - (markImg.Width)); ypos = (int)(img.Height * (float).01); break; case PicWaterMarkPosition.ML: xpos = (int)(img.Width * (float).01); ypos = (int)((img.Height * (float).50) - (markImg.Height / 2)); break; case PicWaterMarkPosition.MM: xpos = (int)((img.Width * (float).50) - (markImg.Width / 2)); ypos = (int)((img.Height * (float).50) - (markImg.Height / 2)); break; case PicWaterMarkPosition.MR: xpos = (int)((img.Width * (float).99) - (markImg.Width)); ypos = (int)((img.Height * (float).50) - (markImg.Height / 2)); break; case PicWaterMarkPosition.BL: xpos = (int)(img.Width * (float).01); ypos = (int)((img.Height * (float).99) - markImg.Height); break; case PicWaterMarkPosition.BM: xpos = (int)((img.Width * (float).50) - (markImg.Width / 2)); ypos = (int)((img.Height * (float).99) - markImg.Height); break; case PicWaterMarkPosition.BR: xpos = (int)((img.Width * (float).99) - (markImg.Width)); ypos = (int)((img.Height * (float).99) - markImg.Height); break; } #endregion position g.DrawImage(markImg, new System.Drawing.Rectangle(xpos, ypos, markImg.Width, markImg.Height), 0, 0, markImg.Width, markImg.Height, System.Drawing.GraphicsUnit.Pixel, imageAttributes); System.Drawing.Imaging.ImageCodecInfo[] codecs = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders(); System.Drawing.Imaging.ImageCodecInfo ici = null; foreach (System.Drawing.Imaging.ImageCodecInfo codec in codecs) { if (codec.MimeType.IndexOf("jpeg") > -1) { ici = codec; } } System.Drawing.Imaging.EncoderParameters encoderParams = new System.Drawing.Imaging.EncoderParameters(); long[] qualityParam = new long[1]; if (quality < 0 || quality > 100) { quality = 80; } qualityParam[0] = quality; System.Drawing.Imaging.EncoderParameter encoderParam = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qualityParam); encoderParams.Param[0] = encoderParam; if (ici != null) { outPut.Save(targetPath, ici, encoderParams); } else { outPut.Save(targetPath); } g.Dispose(); markImg.Dispose(); imageAttributes.Dispose(); } #endregion using } catch (Exception) { return false; } finally { if (outPut != null) { outPut.Dispose(); } if (img != null) { img.Dispose(); } } return true; }
// curmats may be null Point CreateMaterialNodes(List <ExtPictureBox.ImageElement> pc, JournalScan sn, MaterialCommoditiesList curmats, HistoryList hl, Point matpos, Size matsize) { Point startpos = matpos; Point maximum = matpos; int noperline = 0; string matclicktext = sn.DisplayMaterials(2, curmats, hl.GetLast?.MaterialCommodity); foreach (KeyValuePair <string, double> sd in sn.Materials) { string tooltip = sn.DisplayMaterial(sd.Key, sd.Value, curmats, hl.GetLast?.MaterialCommodity); Color fillc = Color.Yellow; string abv = sd.Key.Substring(0, 1); MaterialCommodityData mc = MaterialCommodityData.GetByFDName(sd.Key); if (mc != null) { abv = mc.Shortname; fillc = mc.Colour; if (HideFullMaterials) // check full { int?limit = mc.MaterialLimit(); MaterialCommodities matnow = curmats?.Find(mc); // allow curmats = null // debug if (matnow != null && mc.shortname == "Fe") matnow.count = 10000; if (matnow != null && limit != null && matnow.Count >= limit) // and limit { continue; } } if (ShowOnlyMaterialsRare && mc.IsCommonMaterial) { continue; } } System.Drawing.Imaging.ColorMap colormap = new System.Drawing.Imaging.ColorMap(); colormap.OldColor = Color.White; // this is the marker colour to replace colormap.NewColor = fillc; Bitmap mat = BaseUtils.BitMapHelpers.ReplaceColourInBitmap((Bitmap)Icons.Controls.Scan_Bodies_Material, new System.Drawing.Imaging.ColorMap[] { colormap }); BaseUtils.BitMapHelpers.DrawTextCentreIntoBitmap(ref mat, abv, stdfont, Color.Black); ExtPictureBox.ImageElement ie = new ExtPictureBox.ImageElement( new Rectangle(matpos.X, matpos.Y, matsize.Width, matsize.Height), mat, tooltip + "\n\n" + "All " + matclicktext, tooltip); pc.Add(ie); maximum = new Point(Math.Max(maximum.X, matpos.X + matsize.Width), Math.Max(maximum.Y, matpos.Y + matsize.Height)); if (++noperline == 4) { matpos = new Point(startpos.X, matpos.Y + matsize.Height + materiallinespacerxy); noperline = 0; } else { matpos.X += matsize.Width + materiallinespacerxy; } } return(maximum); }
/// <summary> /// 指定された色を塗る /// </summary> private void btn_paint_Click(object sender, EventArgs e) { try { if (btn_selectcolor1.BackColor == btn_selectcolor2.BackColor) { DialogResult result = MessageBox.Show( "1色で塗り潰されます。" + Environment.NewLine + "2色で塗り分ける場合は、画像選択からテンプレートを選び直してください。", "お知らせ", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation); if (result == DialogResult.Cancel) { return; } } //描画先とするImageオブジェクトを作成する Bitmap canvas = new Bitmap(pictureBox1.Image.Width, pictureBox1.Image.Height); //Bitmap canvas = new Bitmap(global::VI_mark.Properties.Settings.Default.Width, // global::VI_mark.Properties.Settings.Default.Height); //ImageオブジェクトのGraphicsオブジェクトを作成する Graphics g = Graphics.FromImage(canvas); //ColorMapオブジェクトの配列(カラーリマップテーブル)を作成 System.Drawing.Imaging.ColorMap[] cms = new System.Drawing.Imaging.ColorMap[] { new System.Drawing.Imaging.ColorMap(), new System.Drawing.Imaging.ColorMap() }; //SkyBlueを色1に変換する cms[0].OldColor = cmr[0].OldColor; cms[0].NewColor = btn_selectcolor1.BackColor; //PowderBlueを色2に変換する cms[1].OldColor = cmr[1].OldColor; cms[1].NewColor = btn_selectcolor2.BackColor; //色情報を保存 cmr[0].OldColor = btn_selectcolor1.BackColor; cmr[1].OldColor = btn_selectcolor2.BackColor; //ImageAttributesオブジェクトの作成 System.Drawing.Imaging.ImageAttributes ia = new System.Drawing.Imaging.ImageAttributes(); //ColorMapを設定 ia.SetRemapTable(cms); //色を変換して画像を描画 g.DrawImage(pictureBox1.Image, new Rectangle(0, 0, pictureBox1.Image.Width, pictureBox1.Image.Height), 0, 0, pictureBox1.Image.Width, pictureBox1.Image.Height, GraphicsUnit.Pixel, ia); //Graphicsオブジェクトのリソースを解放する g.Dispose(); // pictureBox1に表示する pictureBox1.SizeMode = PictureBoxSizeMode.Zoom; pictureBox1.Image = canvas; } catch (Exception ex) { MessageBox.Show(ex.Message, "エラー"); } finally { string s = @" ( ・∀・) | | ガッ と ) | | Y /ノ 人 / ) < >__Λ∩ _/し' //. V`Д´)/ (_フ彡 /"; MessageBox.Show(s, "ぬるぽ"); } }
/// <summary> /// Draws the Chevron Image at the specified location. /// </summary> /// <param name="graphics">The Graphics to draw on.</param> /// <param name="imgChevron">Chevron image to draw.</param> /// <param name="imageRectangle">A Rectangle structure that specifies the bounds of the linear gradient.</param> /// <param name="foreColorImage">the foreground color of this image</param> /// <param name="bDrawBackground">Gets or sets a value indicating whether the background of the close and expand images is drawn</param> protected static void DrawChevron(Graphics graphics, Image imgChevron, Rectangle imageRectangle, Color foreColorImage, bool bDrawBackground, int chevronPositionY) { if (graphics == null) { throw new ArgumentException( string.Format( System.Globalization.CultureInfo.CurrentUICulture, Resources.IDS_ArgumentException, typeof(Graphics).Name)); } if (imgChevron == null) { throw new ArgumentException( string.Format( System.Globalization.CultureInfo.CurrentUICulture, Resources.IDS_ArgumentException, typeof(Image).Name)); } int chevronPositionX = imageRectangle.Left; Rectangle rectangleChevron = new Rectangle( chevronPositionX + (imageRectangle.Width / 3) - 2, chevronPositionY + 3, 9, 9); using (System.Drawing.Imaging.ImageAttributes imageAttribute = new System.Drawing.Imaging.ImageAttributes()) { imageAttribute.SetColorKey(Color.Magenta, Color.Magenta); System.Drawing.Imaging.ColorMap colorMap = new System.Drawing.Imaging.ColorMap(); colorMap.OldColor = Color.FromArgb(0, 60, 166); colorMap.NewColor = foreColorImage; imageAttribute.SetRemapTable(new System.Drawing.Imaging.ColorMap[] { colorMap }); if (bDrawBackground == true) { using (LinearGradientBrush brushInnerCircle = new LinearGradientBrush( new Rectangle(chevronPositionX, chevronPositionY, 16, 16), Color.FromArgb(128, Color.White), Color.FromArgb(0, Color.White), LinearGradientMode.Vertical)) { graphics.FillPath(brushInnerCircle, GetPath(new Rectangle(chevronPositionX, chevronPositionY, 15, 15), 5)); } } graphics.DrawImage(imgChevron, rectangleChevron, 0, 0, 9, 9, GraphicsUnit.Pixel, imageAttribute); } }
protected override void WndProc( ref Message m ) { base.WndProc( ref m ); switch( m.Msg ) { case win32.WM_PAINT : //this.BorderStyle= BorderStyle.None ; Bitmap bmpCaptured = new Bitmap( this.ClientRectangle.Width, this.ClientRectangle.Height ); Bitmap bmpResult = new Bitmap( this.ClientRectangle.Width,this.ClientRectangle.Height ); Rectangle r = new Rectangle( 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height ); CaptureWindow( this, ref bmpCaptured ); //this.SetStyle( ControlStyles.SupportsTransparentBackColor, true ); //this.BackColor = Color.Transparent; System.Drawing.Imaging.ImageAttributes imgAttrib = new System.Drawing.Imaging.ImageAttributes(); System.Drawing.Imaging.ColorMap[] colorMap = new System.Drawing.Imaging.ColorMap[1]; colorMap[0] = new System.Drawing.Imaging.ColorMap(); colorMap[0].OldColor = Color.White; colorMap[0].NewColor = Color.Transparent; imgAttrib.SetRemapTable( colorMap ); Graphics g = Graphics.FromImage( bmpResult ); g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; //Rectangle rect = new Rectangle(0, 0, this.Width, this.Height); System.Drawing.Drawing2D.LinearGradientBrush lgBrush = new System.Drawing.Drawing2D.LinearGradientBrush( r, this._colorTop , this._colorDown , this._orientacion ); g.FillRectangle(lgBrush,r); g.DrawImage( bmpCaptured, r, 1 , 1, this.ClientRectangle.Width, this.ClientRectangle.Height, GraphicsUnit.Pixel, imgAttrib ); g.Dispose(); _pictureBox.Image = ( Image )bmpResult.Clone(); break; case win32.WM_HSCROLL: case win32.WM_VSCROLL: this.Invalidate(); // repaint // if you use scrolling then add these two case statements break; } }