📄 freeimage.cs
字号:
// ==========================================================
// FreeImage.NET 3
//
// Design and implementation by
// - David Boland (davidboland@vodafone.ie)
//
// Contributors:
// - Andrew S. Townley
//
// This file is part of FreeImage 3
//
// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS,
// WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
// INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED CODE IS
// FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR
// NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE
// OF THE COVERED CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE
// DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL DEVELOPER OR ANY
// OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY SERVICING,
// REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN
// ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS
// AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
//
// Use at your own risk!
//
// ==========================================================
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace FreeImageAPI
{
using PVOID = IntPtr;
using FIBITMAP = UInt32;
using FIMULTIBITMAP = UInt32;
[StructLayout(LayoutKind.Sequential)]
public class RGBQUAD
{
public byte rgbBlue;
public byte rgbGreen;
public byte rgbRed;
public byte rgbReserved;
}
/* [StructLayout(LayoutKind.Sequential)]
public class FreeImageIO
{
public FI_ReadProc readProc;
public FI_WriteProc writeProc;
public FI_SeekProc seekProc;
public FI_TellProc tellProc;
}
[StructLayout(LayoutKind.Sequential)]
public class FI_Handle
{
public FileStream stream;
}
public delegate void FI_ReadProc(IntPtr buffer, uint size, uint count, IntPtr handle);
public delegate void FI_WriteProc(IntPtr buffer, uint size, uint count, IntPtr handle);
public delegate int FI_SeekProc(IntPtr handle, long offset, int origin);
public delegate int FI_TellProc(IntPtr handle);
*/
[StructLayout(LayoutKind.Sequential)]
public class BITMAPINFOHEADER
{
public uint size;
public int width;
public int height;
public ushort biPlanes;
public ushort biBitCount;
public uint biCompression;
public uint biSizeImage;
public int biXPelsPerMeter;
public int biYPelsPerMeter;
public uint biClrUsed;
public uint biClrImportant;
}
[StructLayout(LayoutKind.Sequential)]
public class BITMAPINFO
{
public BITMAPINFOHEADER bmiHeader;
public RGBQUAD bmiColors;
}
public enum FIF
{
FIF_UNKNOWN = -1,
FIF_BMP = 0,
FIF_ICO = 1,
FIF_JPEG = 2,
FIF_JNG = 3,
FIF_KOALA = 4,
FIF_LBM = 5,
FIF_IFF = FIF_LBM,
FIF_MNG = 6,
FIF_PBM = 7,
FIF_PBMRAW = 8,
FIF_PCD = 9,
FIF_PCX = 10,
FIF_PGM = 11,
FIF_PGMRAW = 12,
FIF_PNG = 13,
FIF_PPM = 14,
FIF_PPMRAW = 15,
FIF_RAS = 16,
FIF_TARGA = 17,
FIF_TIFF = 18,
FIF_WBMP = 19,
FIF_PSD = 20,
FIF_CUT = 21,
FIF_XBM = 22,
FIF_XPM = 23,
FIF_DDS = 24,
FIF_GIF = 25
}
public enum FI_QUANTIZE
{
FIQ_WUQUANT = 0,
FIQ_NNQUANT = 1
}
public enum FI_DITHER
{
FID_FS = 0,
FID_BAYER4x4 = 1,
FID_BAYER8x8 = 2,
FID_CLUSTER6x6 = 3,
FID_CLUSTER8x8 = 4,
FID_CLUSTER16x16= 5
}
public enum FI_FILTER
{
FILTER_BOX = 0,
FILTER_BICUBIC = 1,
FILTER_BILINEAR = 2,
FILTER_BSPLINE = 3,
FILTER_CATMULLROM = 4,
FILTER_LANCZOS3 = 5
}
public enum FI_COLOR_CHANNEL
{
FICC_RGB = 0,
FICC_RED = 1,
FICC_GREEN = 2,
FICC_BLUE = 3,
FICC_ALPHA = 4,
FICC_BLACK = 5
}
public enum FIT // FREE_IMAGE_TYPE
{
FIT_UNKNOWN = 0,
FIT_BITMAP = 1,
FIT_UINT16 = 2,
FIT_INT16 = 3,
FIT_UINT32 = 4,
FIT_INT32 = 5,
FIT_FLOAT = 6,
FIT_DOUBLE = 7,
FIT_COMPLEX = 8
}
public delegate void FreeImage_OutputMessageFunction(FIF format, string msg);
public class FreeImage
{
// Init/Error routines ----------------------------------------
[DllImport("FreeImage.dll", EntryPoint="FreeImage_Initialise")]
public static extern void Initialise(bool loadLocalPluginsOnly);
// alias for Americans :)
[DllImport("FreeImage.dll", EntryPoint="FreeImage_Initialise")]
public static extern void Initialize(bool loadLocalPluginsOnly);
[DllImport("FreeImage.dll", EntryPoint="FreeImage_DeInitialise")]
public static extern void DeInitialise();
// alias for Americians :)
[DllImport("FreeImage.dll", EntryPoint="FreeImage_DeInitialise")]
public static extern void DeInitialize();
// Version routines -------------------------------------------
[DllImport("FreeImage.dll", EntryPoint="FreeImage_GetVersion")]
public static extern string GetVersion();
[DllImport("FreeImage.dll", EntryPoint="FreeImage_GetCopyrightMessage")]
public static extern string GetCopyrightMessage();
// Message Output routines ------------------------------------
// missing void FreeImage_OutputMessageProc(int fif,
// const char *fmt, ...);
[DllImport("FreeImage.dll", EntryPoint="FreeImage_SetOutputMessage")]
public static extern void SetOutputMessage(FreeImage_OutputMessageFunction omf);
// Allocate/Clone/Unload routines -----------------------------
[DllImport("FreeImage.dll", EntryPoint="FreeImage_Allocate")]
public static extern FIBITMAP Allocate(int width, int height,
int bpp, uint red_mask, uint green_mask, uint blue_mask);
[DllImport("FreeImage.dll", EntryPoint="FreeImage_AllocateT")]
public static extern FIBITMAP AllocateT(FIT ftype, int width,
int height, int bpp, uint red_mask, uint green_mask,
uint blue_mask);
[DllImport("FreeImage.dll", EntryPoint="FreeImage_Clone")]
public static extern FIBITMAP Clone(FIBITMAP dib);
[DllImport("FreeImage.dll", EntryPoint="FreeImage_Unload")]
public static extern void Unload(FIBITMAP dib);
// Load/Save routines -----------------------------------------
[DllImport("FreeImage.dll", EntryPoint="FreeImage_Load")]
public static extern FIBITMAP Load(FIF format, string filename, int flags);
// missing FIBITMAP FreeImage_LoadFromHandle(FIF fif,
// FreeImageIO *io, fi_handle handle, int flags);
[DllImport("FreeImage.dll", EntryPoint="FreeImage_Save")]
public static extern bool Save(FIF format, FIBITMAP dib, string filename, int flags);
// missing BOOL FreeImage_SaveToHandle(FIF fif, FIBITMAP *dib,
// FreeImageIO *io, fi_handle handle, int flags);
// Plugin interface -------------------------------------------
// missing FIF FreeImage_RegisterLocalPlugin(FI_InitProc proc_address,
// const char *format, const char *description,
// const char *extension, const char *regexpr);
//
// missing FIF FreeImage_RegisterExternalPlugin(const char *path,
// const char *format, const char *description,
// const char *extension, const char *regexpr);
[DllImport("FreeImage.dll", EntryPoint="FreeImage_GetFIFCount")]
public static extern int GetFIFCount();
[DllImport("FreeImage.dll", EntryPoint="FreeImage_SetPluginEnabled")]
public static extern int SetPluginEnabled(FIF format, bool enabled);
[DllImport("FreeImage.dll", EntryPoint="FreeImage_IsPluginEnabled")]
public static extern int IsPluginEnabled(FIF format);
[DllImport("FreeImage.dll", EntryPoint="FreeImage_GetFIFFromFormat")]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -