图像处理工具V1.0
图像处理工具V1.0(仿彗星图片处理工具、VS2015安装界面)----个人无聊作品
以下是界面:
部分代码一、(摘自网络----加水印代码):
1 public static void ImageWaterMarkText(Image img, string filename, string watermarkText, int watermarkStatus, int quality, string fontname, int fontsize) 2 { 3 Graphics g = Graphics.FromImage(img); 4 Font drawFont = new Font(fontname, fontsize, FontStyle.Regular, GraphicsUnit.Pixel); 5 SizeF crSize; 6 crSize = g.MeasureString(watermarkText, drawFont); 7 float xpos = 0; 8 float ypos = 0; 9 switch (watermarkStatus) 10 { 11 case 1: 12 xpos = (float)img.Width * (float).01; 13 ypos = (float)img.Height * (float).01; 14 break; 15 case 2: 16 xpos = ((float)img.Width * (float).50) - (crSize.Width / 2); 17 ypos = (float)img.Height * (float).01; 18 break; 19 case 3: 20 xpos = ((float)img.Width * (float).99) - crSize.Width; 21 ypos = (float)img.Height * (float).01; 22 break; 23 case 4: 24 xpos = (float)img.Width * (float).01; 25 ypos = ((float)img.Height * (float).50) - (crSize.Height / 2); 26 break; 27 case 5: 28 xpos = ((float)img.Width * (float).50) - (crSize.Width / 2); 29 ypos = ((float)img.Height * (float).50) - (crSize.Height / 2); 30 break; 31 case 6: 32 xpos = ((float)img.Width * (float).99) - crSize.Width; 33 ypos = ((float)img.Height * (float).50) - (crSize.Height / 2); 34 break; 35 case 7: 36 xpos = (float)img.Width * (float).01; 37 ypos = ((float)img.Height * (float).99) - crSize.Height; 38 break; 39 case 8: 40 xpos = ((float)img.Width * (float).50) - (crSize.Width / 2); 41 ypos = ((float)img.Height * (float).99) - crSize.Height; 42 break; 43 case 9: 44 xpos = ((float)img.Width * (float).99) - crSize.Width; 45 ypos = ((float)img.Height * (float).99) - crSize.Height; 46 break; 47 } 48 //g.DrawString(watermarkText, drawFont, new SolidBrush(Color.White), xpos + 1, ypos + 1);文字阴影 49 g.DrawString(watermarkText, drawFont, new SolidBrush(Color.Black), xpos, ypos); 50 ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders(); 51 ImageCodecInfo ici = null; 52 foreach (ImageCodecInfo codec in codecs) 53 { 54 if (codec.MimeType.IndexOf("jpeg") > -1) 55 ici = codec; 56 } 57 EncoderParameters encoderParams = new EncoderParameters(); 58 long[] qualityParam = new long[1]; 59 if (quality < 0 || quality > 100) 60 quality = 80; 61 qualityParam[0] = quality; 62 EncoderParameter encoderParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qualityParam); 63 encoderParams.Param[0] = encoderParam; 64 if (ici != null) 65 try 66 { 67 img.Save(filename, ici, encoderParams); 68 } 69 catch (Exception) 70 { 71 72 } 73 else 74 img.Save(filename); 75 g.Dispose(); 76 img.Dispose(); 77 }
部分代码二、(摘自网络----图片转格式代码):
1 public string Convert(string fileinpath, string fileoutpath, string index) 2 { 3 try 4 { 5 Bitmap bitmap = new Bitmap(fileinpath); 6 index = index.ToLower(); 7 switch (index) 8 { 9 case "jpg": bitmap.Save(fileoutpath, ImageFormat.Jpeg); break; 10 case "jpeg": bitmap.Save(fileoutpath, ImageFormat.Jpeg); break; 11 case "bmp": bitmap.Save(fileoutpath, ImageFormat.Bmp); break; 12 case "png": bitmap.Save(fileoutpath, ImageFormat.Png); break; 13 case "emf": bitmap.Save(fileoutpath, ImageFormat.Emf); break; 14 case "gif": bitmap.Save(fileoutpath, ImageFormat.Gif); break; 15 case "wmf": bitmap.Save(fileoutpath, ImageFormat.Wmf); break; 16 case "exif": bitmap.Save(fileoutpath, ImageFormat.Exif); break; 17 case "tiff": 18 { 19 Stream stream = File.Create(fileoutpath); 20 bitmap.Save(stream, ImageFormat.Tiff); 21 stream.Close(); 22 } 23 break; 24 case "ico": 25 { 26 Icon ico; 27 Stream stream = File.Create(fileoutpath); 28 ico = BitmapToIcon(bitmap, false); 29 ico.Save(stream); // save the icon 30 stream.Close(); 31 }; break; 32 default: return "Error!"; 33 } 34 return "Success!"; 35 } 36 catch (Exception ex) 37 { 38 return ex.Message; 39 } 40 }
以上代码均摘自网络。个人无聊作品,仅供参考。
inscan QQ:451205927