📄 freeimagebitmap.cs
字号:
/// <param name="thumbHeight">The height, in pixels, of the requested thumbnail image.</param>
/// <param name="callback">Ignored.</param>
/// <param name="callBackData">Ignored.</param>
/// <returns>A <see cref="FreeImageBitmap"/> that represents the thumbnail.</returns>
public FreeImageBitmap GetThumbnailImage(int thumbWidth, int thumbHeight,
Image.GetThumbnailImageAbort callback, IntPtr callBackData)
{
EnsureNotDisposed();
FreeImageBitmap result = null;
FIBITMAP newDib = FreeImage.Rescale(
dib, thumbWidth, thumbHeight, FREE_IMAGE_FILTER.FILTER_BICUBIC);
if (!newDib.IsNull)
{
result = new FreeImageBitmap();
result.dib = newDib;
}
return result;
}
/// <summary>
/// Returns a thumbnail for this <see cref="FreeImageBitmap"/>, keeping aspect ratio.
/// <paramref name="maxPixelSize"/> defines the maximum width or height
/// of the thumbnail.
/// </summary>
/// <param name="maxPixelSize">Thumbnail square size.</param>
/// <param name="convert">When true HDR images are transperantly
/// converted to standard images.</param>
/// <returns>The thumbnail in a new instance.</returns>
public FreeImageBitmap GetThumbnailImage(int maxPixelSize, bool convert)
{
EnsureNotDisposed();
FreeImageBitmap result = null;
FIBITMAP newDib = FreeImage.MakeThumbnail(dib, maxPixelSize, convert);
if (!newDib.IsNull)
{
result = new FreeImageBitmap();
result.dib = newDib;
}
return result;
}
/// <summary>
/// Returns an instance of <see cref="Scanline<T>"/>, representing the scanline
/// specified by <paramref name="scanline"/> of this <see cref="FreeImageBitmap"/>.
/// Since FreeImage bitmaps are always bottum up aligned, keep in mind that scanline 0 is the
/// bottom-most line of the image.
/// </summary>
/// <param name="scanline">Number of the scanline to retrieve.</param>
/// <returns>An instance of <see cref="Scanline<T>"/> representing the
/// <paramref name="scanline"/>th scanline.</returns>
/// <remarks>
/// List of return-types of <b>T</b>:<para/>
/// <list type="table">
/// <listheader><term>Color Depth / Type</term><description><see cref="Type">Result Type</see></description></listheader>
/// <item><term>1 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="FI1BIT"/></description></item>
/// <item><term>4 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="FI4BIT"/></description></item>
/// <item><term>8 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="Byte"/></description></item>
/// <item><term>16 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="UInt16"/></description></item>
/// <item><term>16 - 555 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="FI16RGB555"/></description></item>
/// <item><term>16 - 565 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="FI16RGB565"/></description></item>
/// <item><term>24 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="RGBTRIPLE"/></description></item>
/// <item><term>32 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="RGBQUAD"/></description></item>
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_COMPLEX"/></term><description><see cref="FICOMPLEX"/></description></item>
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_DOUBLE"/></term><description><see cref="Double"/></description></item>
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_FLOAT"/></term><description><see cref="Single"/></description></item>
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_INT16"/></term><description><see cref="Int16"/></description></item>
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_INT32"/></term><description><see cref="Int32"/></description></item>
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_RGB16"/></term><description><see cref="FIRGB16"/></description></item>
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_RGBA16"/></term><description><see cref="FIRGBA16"/></description></item>
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_RGBAF"/></term><description><see cref="FIRGBAF"/></description></item>
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_RGBF"/></term><description><see cref="FIRGBF"/></description></item>
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_UINT16"/></term><description><see cref="UInt16"/></description></item>
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_UINT32"/></term><description><see cref="UInt32"/></description></item>
/// </list>
/// </remarks>
/// <example>
/// <code>
/// FreeImageBitmap bitmap = new FreeImageBitmap(@"C:\Pictures\picture.bmp");
/// if (bitmap.ColorDepth == 32)
/// {
/// Scanline<RGBQUAD> scanline = (Scanline<RGBQUAD>)bitmap.GetScanline(0);
/// foreach (RGBQUAD pixel in scanline)
/// {
/// Console.WriteLine(pixel);
/// }
/// }
/// </code>
/// </example>
/// <exception cref="ArgumentException">
/// The bitmap's type or color depth are not supported.
/// </exception>
/// <exception cref="ArgumentOutOfRangeException">
/// <paramref name="scanline"/> is no valid value.
/// </exception>
public Scanline<T> GetScanline<T>(int scanline) where T : struct
{
EnsureNotDisposed();
return new Scanline<T>(dib, scanline);
}
/// <summary>
/// Returns an instance of <see cref="Scanline<T>"/>, representing the scanline
/// specified by <paramref name="scanline"/> of this <see cref="FreeImageBitmap"/>.
/// Since FreeImage bitmaps are always bottum up aligned, keep in mind that scanline 0 is the
/// bottom-most line of the image.
/// </summary>
/// <param name="scanline">Number of the scanline to retrieve.</param>
/// <returns>An instance of <see cref="Scanline<T>"/> representing the
/// <paramref name="scanline"/>th scanline.</returns>
/// <remarks>
/// List of return-types of <b>T</b>:<para/>
/// <list type="table">
/// <listheader><term>Color Depth / Type</term><description><see cref="Type">Result Type</see></description></listheader>
/// <item><term>1 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="FI1BIT"/></description></item>
/// <item><term>4 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="FI4BIT"/></description></item>
/// <item><term>8 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="Byte"/></description></item>
/// <item><term>16 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="UInt16"/></description></item>
/// <item><term>16 - 555 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="FI16RGB555"/></description></item>
/// <item><term>16 - 565 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="FI16RGB565"/></description></item>
/// <item><term>24 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="RGBTRIPLE"/></description></item>
/// <item><term>32 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="RGBQUAD"/></description></item>
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_COMPLEX"/></term><description><see cref="FICOMPLEX"/></description></item>
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_DOUBLE"/></term><description><see cref="Double"/></description></item>
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_FLOAT"/></term><description><see cref="Single"/></description></item>
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_INT16"/></term><description><see cref="Int16"/></description></item>
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_INT32"/></term><description><see cref="Int32"/></description></item>
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_RGB16"/></term><description><see cref="FIRGB16"/></description></item>
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_RGBA16"/></term><description><see cref="FIRGBA16"/></description></item>
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_RGBAF"/></term><description><see cref="FIRGBAF"/></description></item>
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_RGBF"/></term><description><see cref="FIRGBF"/></description></item>
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_UINT16"/></term><description><see cref="UInt16"/></description></item>
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_UINT32"/></term><description><see cref="UInt32"/></description></item>
/// </list>
/// </remarks>
/// <example>
/// <code>
/// FreeImageBitmap bitmap = new FreeImageBitmap(@"C:\Pictures\picture.bmp");
/// if (bitmap.ColorDepth == 32)
/// {
/// Scanline<RGBQUAD> scanline = (Scanline<RGBQUAD>)bitmap.GetScanline(0);
/// foreach (RGBQUAD pixel in scanline)
/// {
/// Console.WriteLine(pixel);
/// }
/// }
/// </code>
/// </example>
/// <exception cref="ArgumentException">
/// The type of the bitmap or color depth are not supported.
/// </exception>
/// <exception cref="ArgumentOutOfRangeException">
/// <paramref name="scanline"/> is no valid value.
/// </exception>
public object GetScanline(int scanline)
{
EnsureNotDisposed();
object result = null;
int width = (int)FreeImage.GetWidth(dib);
switch (FreeImage.GetImageType(dib))
{
case FREE_IMAGE_TYPE.FIT_BITMAP:
switch (FreeImage.GetBPP(dib))
{
case 1u: result = new Scanline<FI1BIT>(dib, scanline, width); break;
case 4u: result = new Scanline<FI4BIT>(dib, scanline, width); break;
case 8u: result = new Scanline<Byte>(dib, scanline, width); break;
case 16u:
if ((RedMask == FreeImage.FI16_555_RED_MASK) &&
(GreenMask == FreeImage.FI16_555_GREEN_MASK) &&
(BlueMask == FreeImage.FI16_555_BLUE_MASK))
{
result = new Scanline<FI16RGB555>(dib, scanline, width);
}
else if ((RedMask == FreeImage.FI16_565_RED_MASK) &&
(GreenMask == FreeImage.FI16_565_GREEN_MASK) &&
(BlueMask == FreeImage.FI16_565_BLUE_MASK))
{
result = new Scanline<FI16RGB565>(dib, scanline, width);
}
else
{
result = new Scanline<UInt16>(dib, scanline, width);
}
break;
case 24u: result = new Scanline<RGBTRIPLE>(dib, scanline, width); break;
case 32u: result = new Scanline<RGBQUAD>(dib, scanline, width); break;
default: throw new ArgumentException("Color depth is not supported.");
}
break;
case FREE_IMAGE_TYPE.FIT_COMPLEX: result = new Scanline<FICOMPLEX>(dib, scanline, width); break;
case FREE_IMAGE_TYPE.FIT_DOUBLE: result = new Scanline<Double>(dib, scanline, width); break;
case FREE_IMAGE_TYPE.FIT_FLOAT: result = new Scanline<Single>(dib, scanline, width); break;
case FREE_IMAGE_TYPE.FIT_INT16: result = new Scanline<Int16>(dib, scanline, width); break;
case FREE_IMAGE_TYPE.FIT_INT32: result = new Scanline<Int32>(dib, scanline, width); break;
case FREE_IMAGE_TYPE.FIT_RGB16: result = new Scanline<FIRGB16>(dib, scanline, width); break;
case FREE_IMAGE_TYPE.FIT_RGBA16: result = new Scanline<FIRGBA16>(dib, scanline, width); break;
case FREE_IMAGE_TYPE.FIT_RGBAF: result = new Scanline<FIRGBAF>(dib, scanline, width); break;
case FREE_IMAGE_TYPE.FIT_RGBF: result = new Scanline<FIRGBF>(dib, scanline, width); break;
case FREE_IMAGE_TYPE.FIT_UINT16: result = new Scanline<UInt16>(dib, scanline, width); break;
case FREE_IMAGE_TYPE.FIT_UINT32: result = new Scanline<UInt32>(dib, scanline, width); break;
case FREE_IMAGE_TYPE.FIT_UNKNOWN:
default: throw new ArgumentException("Type is not supported.");
}
return result;
}
/// <summary>
/// Returns a pointer to the specified scanline.
/// Due to FreeImage bitmaps are bottum up,
/// scanline 0 is the most bottom line of the image.
/// </summary>
/// <param name="scanline">Number of the scanline.</param>
/// <returns>Pointer to the scanline.</returns>
public IntPtr GetScanlinePointer(int scanline)
{
EnsureNotDisposed();
return FreeImage.GetScanLine(dib, scanline);
}
/// <summary>
/// Returns a list of structures, representing the scanlines of this <see cref="FreeImageBitmap"/>.
/// Due to FreeImage bitmaps are bottum up, scanline 0 is the
/// bottom-most line of the image.
/// Each color depth has a different representing structure due to different memory layouts.
/// </summary>
/// <remarks>
/// List of return-types of <b>T</b>:<para/>
/// <list type="table">
/// <listheader><term>Color Depth / Type</term><description><see cref="Type">Result Type of IEnmuerable<Scanline<T>></see></description></listheader>
/// <item><term>1 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="FI1BIT"/></description></item>
/// <item><term>4 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="FI4BIT"/></description></item>
/// <item><term>8 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="Byte"/></description></item>
/// <item><term>16 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="UInt16"/></description></item>
/// <item><term>16 - 555 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="FI16RGB555"/></description></item>
/// <item><term>16 - 565 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="FI16RGB565"/></description></item>
/// <item><term>24 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="RGBTRIPLE"/></description></item>
/// <item><term>32 (<see cref="FREE_IMAGE_TYPE.FIT_BITMAP"/>)</term><description><see cref="RGBQUAD"/></description></item>
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_COMPLEX"/></term><description><see cref="FICOMPLEX"/></description></item>
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_DOUBLE"/></term><description><see cref="Double"/></description></item>
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_FLOAT"/></term><description><see cref="Single"/></description></item>
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_INT16"/></term><description><see cref="Int16"/></description></item>
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_INT32"/></term><description><see cref="Int32"/></description></item>
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_RGB16"/></term><description><see cref="FIRGB16"/></description></item>
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_RGBA16"/></term><description><see cref="FIRGBA16"/></description></item>
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_RGBAF"/></term><description><see cref="FIRGBAF"/></description></item>
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_RGBF"/></term><description><see cref="FIRGBF"/></description></item>
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_UINT16"/></term><description><see cref="UInt16"/></description></item>
/// <item><term><see cref="FREE_IMAGE_TYPE.FIT_UINT32"/></term><description><see cref="UInt32"/></description></item>
/// </list>
/// </remarks>
public IList GetScanlines()
{
EnsureNotDisposed();
int height = (int)FreeImage.GetHeight(dib);
IList list;
switch (FreeImage.GetImageType(dib))
{
case FREE_IMAGE_TYPE.FIT_BITMAP:
switch (FreeImage.GetBPP(dib))
{
case 1u: list = new List<Scanline<FI1BIT>>(height); break;
case 4u: list = new List<Scanline<FI4BIT>>(height); break;
case 8u: list = new List<Scanline<Byte>>(height); break;
case 16u:
if (FreeImage.IsRGB555(dib))
{
list = new List<Scanline<FI16RGB555>>(height);
}
else if (FreeImage.IsRGB565(dib))
{
list = new List<Scanline<FI16RGB565>>(height);
}
else
{
list = new List<Scanline<UInt16>>(height);
}
break;
case 24u: list = new List<Scanline<RGBTRIPLE>>(height); break;
case 32u: list = new List<Scanline<RGBQUAD>>(height); break;
default: throw new ArgumentException("Color depth is not supported.");
}
break;
case FREE_IMAGE_TYPE.FIT_COMPLEX: list = new List<Scanline<FICOMPLEX>>(height); break;
case FREE_IMAGE_TYPE.FIT_DOUBLE: list = new List<Scanline<Double>>(height); break;
case FREE_IMAGE_TYPE.FIT_FLOAT: list = new List<Scanline<Single>>(height); break;
case FREE_IMAGE_TYPE.FIT_INT16: list = new List<Scanline<Int16>>(height); break;
case FREE_IMAGE_TYPE.FIT_INT32: list = new List<Scanline<Int32>>(height); break;
case FREE_IMAGE_TYPE.FIT_RGB16: list = new List<Scanline<FIRGB16>>(height); break;
case FREE_IMAGE_TYPE.FIT_RGBA16: list = new List<Scanline<FIRGBA16>>(height); break;
case FREE_IMAGE_TYPE.FIT_RGBAF: list = new List<Scanline<FIRGBAF>>(height); break;
case FREE_IMAGE_TYPE.FIT_RGBF: list = new List<Scanline<FIRGBF>>(height); break;
case FREE_IMAGE_TYPE.FIT_UINT16: list = new List<Scanline<UInt16>>(height); break;
case FREE_IMAGE_TYPE.FIT_UINT32: list = new List<Scanline<UInt32>>(height); break;
case FREE_IMAGE_TYPE.FIT_UNKNOWN:
default: throw new ArgumentException("Type is not supported.");
}
for (int i = 0; i < height; i++)
{
list.Add(GetScanline(i));
}
return list;
}
/// <summary>
/// Removes the specified property item from this <see cref="FreeImageBitmap"/>.
/// </summary>
/// <param name="propid">The ID of the property item to remove.</param>
public void RemovePropertyItem(int propid)
{
EnsureNotDisposed();
ImageMetadata mdata = new ImageMetadata(dib, true);
foreach (MetadataModel model in mdata)
{
foreach (MetadataTag tag in model)
{
if (tag.ID == propid)
{
model.RemoveTag(tag.Key);
return;
}
}
}
}
/// <summary>
/// This method rotates, flips, or rotates and flips this <see cref="FreeImageBitmap"/>.
/// </summary>
/// <param name="rotateFlipType">A RotateFlipType member
/// that specifies the type of rotation and flip to apply to this <see cref="FreeImageBitmap"/>.</param>
public void RotateFlip(RotateFlipType rotateFlipType)
{
EnsureNotDisposed();
FIBITMAP newDib = 0;
uint bpp = FreeImage.GetBPP(dib);
switch (rotateFlipType)
{
case RotateFlipType.RotateNoneFlipX:
FreeImage.FlipHorizontal(dib);
break;
case RotateFlipType.RotateNoneFlipY:
FreeImage.FlipVertical(dib);
break;
case RotateFlipType.RotateNoneFlipXY:
FreeImage.FlipHorizontal(dib);
FreeImage.FlipVertical(dib);
break;
case RotateFlipType.Rotate90FlipNone:
newDib = (bpp == 4u) ? FreeImage.Rotate4bit(dib, 90d) : FreeImage.RotateClassic(dib, 90d);
break;
case RotateFlipType.Rotate90FlipX:
newDib = (bpp == 4u) ? FreeImage.Rotate4bit(dib, 90d) : FreeImage.RotateClassic(dib, 90d);
FreeImage.FlipHorizontal(newDib);
break
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -