/*说明: 保存文件时进行物理大小变化处理
public static bool KiSaveAsJPEG(Bitmap bmp, string FileName, int Qty)
{
try
{
EncoderParameter p;
EncoderParameters ps;
ps = new EncoderParameters(1);
p = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, Qty);
ps.Param[0] = p;
bmp.Save(FileName, GetCodecInfo("image/jpeg"), ps);
return true;
}
catch
{
return false;
}
}
/* 说明:获取指定格式的的ImageCodecInfo
private static ImageCodecInfo GetCodecInfo(string mimeType)
{
ImageCodecInfo[] CodecInfo = ImageCodecInfo.GetImageEncoders();
foreach (ImageCodecInfo ici in CodecInfo)
{
if (ici.MimeType == mimeType) return ici;
}
return null;
}
#endregion
/* 说明:图片裁剪
* 参数:Bitmap b--目标图片位图
* Rectangle r--裁剪范围矩形
* 返回类型:裁剪下来的图片位图
*/
public static Bitmap KiCut(Bitmap b, Rectangle r)
{
if (b == null)
{
return null;
}
int w = b.Width;
int h = b.Height;
if (r.X >= w || r.Y >= h)
{
return null;
}
if (r.X + r.Width > w)
{
r.Width = w - r.X;
}
if (r.Y + r.Height > h)
{
r.Height = h - r.Y;
}
try
{
Bitmap bmpOut = new Bitmap(r.Width, r.Height, PixelFormat.Format24bppRgb);
Graphics g = Graphics.FromImage(bmpOut);
g.DrawImage(b, new Rectangle(0, 0,r.Width ,r.Height ), new Rectangle(r.X, r.Y, r.Width, r.Height), GraphicsUnit.Pixel);
g.Dispose();
return bmpOut;
}
catch
{
return null;
}
}

3611

被折叠的 条评论
为什么被折叠?



