📄 baseimage.cs
字号:
namespace Imps.Utils
{
using System;
using System.Drawing;
public class BaseImage : IImage, ICloneable, IDisposable
{
private Bitmap _bitmap;
private Size _size;
public BaseImage(Bitmap bitmap)
{
this._bitmap = bitmap;
if (this._bitmap != null)
{
this._size = this._bitmap.Size;
}
}
public object Clone()
{
return new BaseImage(this._bitmap);
}
public void Dispose()
{
if (this._bitmap != null)
{
this._bitmap.Dispose();
this._bitmap = null;
}
}
public Color GetPixel(int x, int y)
{
Color pixel;
try
{
pixel = this._bitmap.GetPixel(x, y);
}
catch (ArgumentException)
{
if ((x < 0) || (x >= this.Width))
{
throw new ArgumentOutOfRangeException("x", x, "x 坐标超出范围!");
}
if ((y >= 0) && (y < this.Height))
{
throw;
}
throw new ArgumentOutOfRangeException("y", y, "y 坐标超出范围!");
}
return pixel;
}
public void SetPixel(int x, int y, Color color)
{
try
{
this._bitmap.SetPixel(x, y, color);
}
catch (ArgumentException)
{
if ((x < 0) || (x >= this.Width))
{
throw new ArgumentOutOfRangeException("x", x, "x 坐标超出范围!");
}
if ((y >= 0) && (y < this.Height))
{
throw;
}
throw new ArgumentOutOfRangeException("y", y, "y 坐标超出范围!");
}
}
public int Height
{
get
{
return this._size.Height;
}
}
public System.Drawing.Image Image
{
get
{
return this._bitmap;
}
set
{
if (value == null)
{
throw new NullReferenceException();
}
Bitmap bitmap = this._bitmap;
try
{
this._bitmap = new Bitmap(value);
this._size = this._bitmap.Size;
}
catch
{
}
finally
{
if (bitmap != null)
{
bitmap.Dispose();
}
}
}
}
public int Width
{
get
{
return this._size.Width;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -