📄 imagehelper.cs
字号:
return RotateImage(Image.FromFile(path), angle);
}
catch
{
return null;
}
}
[Obsolete("请使用TryGetTransparentImage替代", true)]
public static void SetAlphaImage(Image img, float percent)
{
Bitmap bitmap = new Bitmap(img);
for (int i = 0; i < bitmap.Width; i++)
{
for (int j = 0; j < bitmap.Height; j++)
{
Color pixel = bitmap.GetPixel(i, j);
if (pixel.A > 0)
{
int alpha = Convert.ToInt32((float) (pixel.A * percent));
bitmap.SetPixel(i, j, Color.FromArgb(alpha, pixel.R, pixel.G, pixel.B));
}
}
}
}
public static Image SetOverlapImage(Image orignalImage, string overlapPath, int x, int y)
{
if (orignalImage == null)
{
throw new ArgumentNullException("orignalImage");
}
if (!File.Exists(overlapPath))
{
throw new FileNotFoundException(overlapPath);
}
try
{
Image overlapImage = Image.FromFile(overlapPath);
return SetOverlapImage(orignalImage, overlapImage, x, y, overlapImage.Width, overlapImage.Height);
}
catch
{
return null;
}
}
public static Image SetOverlapImage(string path, Image overlapImage, int x, int y)
{
if (!File.Exists(path))
{
throw new FileNotFoundException(path);
}
if (overlapImage == null)
{
throw new ArgumentNullException("overlapImage");
}
try
{
return SetOverlapImage(Image.FromFile(path), overlapImage, x, y, overlapImage.Width, overlapImage.Height);
}
catch
{
return null;
}
}
public static Image SetOverlapImage(string path, string overlapPath, int x, int y)
{
if (!File.Exists(path))
{
throw new FileNotFoundException(path);
}
if (!File.Exists(overlapPath))
{
throw new FileNotFoundException(overlapPath);
}
try
{
Image overlapImage = Image.FromFile(overlapPath);
return SetOverlapImage(Image.FromFile(path), overlapImage, x, y, overlapImage.Width, overlapImage.Height);
}
catch
{
return null;
}
}
public static Image SetOverlapImage(Image image, Image overlapImage, int x, int y, int width, int height)
{
if (image == null)
{
throw new ArgumentNullException("image");
}
if (overlapImage == null)
{
throw new ArgumentNullException("overlapImage");
}
ImpOverlayTranform tf = new ImpOverlayTranform(overlapImage, x, y, width, height);
return Transform(image, tf);
}
public static Image SetOverlapImage(Image orignalImage, string overlapPath, int x, int y, int width, int height)
{
if (orignalImage == null)
{
throw new ArgumentNullException("orignalImage");
}
if (!File.Exists(overlapPath))
{
throw new FileNotFoundException(overlapPath);
}
try
{
return SetOverlapImage(orignalImage, Image.FromFile(overlapPath), x, y, width, height);
}
catch
{
return null;
}
}
public static Image SetOverlapImage(string path, Image overlapImage, int x, int y, int width, int height)
{
if (!File.Exists(path))
{
throw new FileNotFoundException(path);
}
if (overlapImage == null)
{
throw new ArgumentNullException("overlapImage");
}
try
{
return SetOverlapImage(Image.FromFile(path), overlapImage, x, y, width, height);
}
catch
{
return null;
}
}
public static Image SetOverlapImage(string path, string overlapPath, int x, int y, int width, int height)
{
if (!File.Exists(path))
{
throw new FileNotFoundException(path);
}
if (!File.Exists(overlapPath))
{
throw new FileNotFoundException(overlapPath);
}
try
{
return SetOverlapImage(Image.FromFile(path), Image.FromFile(overlapPath), x, y, width, height);
}
catch
{
return null;
}
}
public static Image SetOverlapImageEx(Image originalImage, Image overlapImage, int x, int y)
{
if (originalImage == null)
{
throw new ArgumentNullException("originalImage");
}
if (overlapImage == null)
{
throw new ArgumentNullException("overlapImage");
}
try
{
return SetOverlapImageEx(originalImage, overlapImage, x, y, overlapImage.Width, overlapImage.Height);
}
catch
{
return null;
}
}
public static Image SetOverlapImageEx(Image originalImage, string overlapPath, int x, int y)
{
if (originalImage == null)
{
throw new ArgumentNullException("originalImage");
}
if (!File.Exists(overlapPath))
{
throw new FileNotFoundException(overlapPath);
}
try
{
return SetOverlapImageEx(originalImage, Image.FromFile(overlapPath), x, y);
}
catch
{
return null;
}
}
public static Image SetOverlapImageEx(string path, Image overlapImage, int x, int y)
{
if (!File.Exists(path))
{
throw new FileNotFoundException(path);
}
if (overlapImage == null)
{
throw new ArgumentNullException("overlapImage");
}
try
{
return SetOverlapImageEx(Image.FromFile(path), overlapImage, x, y);
}
catch
{
return null;
}
}
public static Image SetOverlapImageEx(Image image, Image overlapImage, int x, int y, int width, int height)
{
if (image == null)
{
throw new ArgumentNullException("image");
}
if (overlapImage == null)
{
throw new ArgumentNullException("overlapImage");
}
ImpOverlayTranformEx tf = new ImpOverlayTranformEx(overlapImage, x, y, width, height);
return Transform(image, tf);
}
public static Image SetOverlapImageEx(string path, Image overlapImage, int x, int y, int width, int height)
{
if (!File.Exists(path))
{
throw new FileNotFoundException(path);
}
if (overlapImage == null)
{
throw new ArgumentNullException("overlapImage");
}
try
{
return SetOverlapImageEx(Image.FromFile(path), overlapImage, x, y, width, height);
}
catch
{
return null;
}
}
public static Image Transform(IImage image, IImageTransform tf)
{
return tf.Transform(image).Image;
}
public static Image Transform(Bitmap bitmap, IImageTransform tf)
{
BaseImage image = new BaseImage(bitmap);
return Transform(image, tf);
}
public static Image Transform(Image image, IImageTransform tf)
{
using (Bitmap bitmap = new Bitmap(image))
{
return Transform(bitmap, tf);
}
}
public static Image Transform(Stream stream, IImageTransform tf)
{
return Transform(Image.FromStream(stream), tf);
}
public static Image Transform(string filePath, IImageTransform tf)
{
return Transform(Image.FromFile(filePath), tf);
}
public static void TryGetHighQualifiedJpegStream(MemoryStream ms, Image input, int size)
{
TryGetHighQualifiedJpegStream(ms, input, size, Color.White);
}
public static void TryGetHighQualifiedJpegStream(MemoryStream ms, string path, int size)
{
TryGetHighQualifiedJpegStream(ms, path, size, Color.White);
}
public static void TryGetHighQualifiedJpegStream(MemoryStream ms, Image input, int size, Color bgColor)
{
try
{
GetHighQualifiedJpegStream(ms, input, size, Color.White);
}
catch
{
}
}
public static void TryGetHighQualifiedJpegStream(MemoryStream ms, string path, int size, Color bgColor)
{
try
{
GetHighQualifiedJpegStream(ms, Image.FromFile(path), size, bgColor);
}
catch
{
}
}
public static Image TryGetScaleGifImage(Image image, int width, int height, bool keepRatio)
{
if (image == null)
{
return null;
}
return null;
}
public static Image TryGetScaleGifImage(string path, int width, int height, bool keepRatio)
{
if (!File.Exists(path))
{
return null;
}
try
{
return GetScaleGifImage(Image.FromFile(path), width, height, keepRatio);
}
catch
{
return null;
}
}
public static Image TryGetSlicedImage(Image image, int x, int y, int width, int height)
{
if (image == null)
{
return null;
}
try
{
ImpSliceTransform tf = new ImpSliceTransform(x, y, width, height);
return Transform(image, tf);
}
catch
{
return image;
}
}
public static Image TryGetSlicedImage(string path, int x, int y, int width, int height)
{
if (!File.Exists(path))
{
return null;
}
try
{
return GetSlicedImage(Image.FromFile(path), x, y, width, height);
}
catch
{
return null;
}
}
public static Image TryGetSquareThumbnailImage(Image image, int size)
{
if (image == null)
{
return null;
}
try
{
ImpSquareScaleTransform tf = new ImpSquareScaleTransform(size);
return Transform(image, tf);
}
catch
{
return image;
}
}
public static Image TryGetSquareThumbnailImage(string path, int size)
{
if (!File.Exists(path))
{
return null;
}
try
{
return GetSquareThumbnailImage(Image.FromFile(path), size);
}
catch
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -