图像处理工具V1.0(仿彗星图片处理工具、VS2015安装界面)----个人无聊作品

以下是界面:

图像处理工具V1.0-LMLPHP

部分代码一、(摘自网络----加水印代码):

 public static void ImageWaterMarkText(Image img, string filename, string watermarkText, int watermarkStatus, int quality, string fontname, int fontsize)
{
Graphics g = Graphics.FromImage(img);
Font drawFont = new Font(fontname, fontsize, FontStyle.Regular, GraphicsUnit.Pixel);
SizeF crSize;
crSize = g.MeasureString(watermarkText, drawFont);
float xpos = ;
float ypos = ;
switch (watermarkStatus)
{
case :
xpos = (float)img.Width * (float).;
ypos = (float)img.Height * (float).;
break;
case :
xpos = ((float)img.Width * (float).) - (crSize.Width / );
ypos = (float)img.Height * (float).;
break;
case :
xpos = ((float)img.Width * (float).) - crSize.Width;
ypos = (float)img.Height * (float).;
break;
case :
xpos = (float)img.Width * (float).;
ypos = ((float)img.Height * (float).) - (crSize.Height / );
break;
case :
xpos = ((float)img.Width * (float).) - (crSize.Width / );
ypos = ((float)img.Height * (float).) - (crSize.Height / );
break;
case :
xpos = ((float)img.Width * (float).) - crSize.Width;
ypos = ((float)img.Height * (float).) - (crSize.Height / );
break;
case :
xpos = (float)img.Width * (float).;
ypos = ((float)img.Height * (float).) - crSize.Height;
break;
case :
xpos = ((float)img.Width * (float).) - (crSize.Width / );
ypos = ((float)img.Height * (float).) - crSize.Height;
break;
case :
xpos = ((float)img.Width * (float).) - crSize.Width;
ypos = ((float)img.Height * (float).) - crSize.Height;
break;
}
//g.DrawString(watermarkText, drawFont, new SolidBrush(Color.White), xpos + 1, ypos + 1);文字阴影
g.DrawString(watermarkText, drawFont, new SolidBrush(Color.Black), xpos, ypos);
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
ImageCodecInfo ici = null;
foreach (ImageCodecInfo codec in codecs)
{
if (codec.MimeType.IndexOf("jpeg") > -)
ici = codec;
}
EncoderParameters encoderParams = new EncoderParameters();
long[] qualityParam = new long[];
if (quality < || quality > )
quality = ;
qualityParam[] = quality;
EncoderParameter encoderParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qualityParam);
encoderParams.Param[] = encoderParam;
if (ici != null)
try
{
img.Save(filename, ici, encoderParams);
}
catch (Exception)
{ }
else
img.Save(filename);
g.Dispose();
img.Dispose();
}

部分代码二、(摘自网络----图片转格式代码):

 public string Convert(string fileinpath, string fileoutpath, string index)
{
try
{
Bitmap bitmap = new Bitmap(fileinpath);
index = index.ToLower();
switch (index)
{
case "jpg": bitmap.Save(fileoutpath, ImageFormat.Jpeg); break;
case "jpeg": bitmap.Save(fileoutpath, ImageFormat.Jpeg); break;
case "bmp": bitmap.Save(fileoutpath, ImageFormat.Bmp); break;
case "png": bitmap.Save(fileoutpath, ImageFormat.Png); break;
case "emf": bitmap.Save(fileoutpath, ImageFormat.Emf); break;
case "gif": bitmap.Save(fileoutpath, ImageFormat.Gif); break;
case "wmf": bitmap.Save(fileoutpath, ImageFormat.Wmf); break;
case "exif": bitmap.Save(fileoutpath, ImageFormat.Exif); break;
case "tiff":
{
Stream stream = File.Create(fileoutpath);
bitmap.Save(stream, ImageFormat.Tiff);
stream.Close();
}
break;
case "ico":
{
Icon ico;
Stream stream = File.Create(fileoutpath);
ico = BitmapToIcon(bitmap, false);
ico.Save(stream); // save the icon
stream.Close();
}; break;
default: return "Error!";
}
return "Success!";
}
catch (Exception ex)
{
return ex.Message;
}
}

以上代码均摘自网络。个人无聊作品,仅供参考。

04-26 20:55