|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
//文件 ImageBase.h
|
|
|
//主要功能:
|
|
|
//
|
|
|
//程序编写: 2005-12-07
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
#include "CxImage\CxImage\ximage.h"
|
|
|
|
|
|
//图像序列化格式支持
|
|
|
#define IMAGE_SERIALIZE_BITAMP 1 //序列化为位图格式
|
|
|
#define IMAGE_SERIALIZE_JPEG 2
|
|
|
#define IMAGE_SERIALIZE_PNG 3
|
|
|
#define IMAGE_SERIALIZE_ICO 4
|
|
|
#define IMAGE_SERIALIZE_TIFF 5
|
|
|
#define IMAGE_SERIALIZE_GIF 6
|
|
|
|
|
|
namespace NImage
|
|
|
{
|
|
|
|
|
|
class AFX_EXT_CLASS CImageBase : public CxImage
|
|
|
{
|
|
|
public:
|
|
|
CImageBase(void);
|
|
|
virtual ~CImageBase();
|
|
|
|
|
|
BOOL Create(int nWidth, int nHeight, int nBPP, DWORD imagetype=CXIMAGE_FORMAT_BMP);
|
|
|
void Destroy(void);
|
|
|
|
|
|
HBITMAP Detach();
|
|
|
void Attach( HBITMAP hBitmap);
|
|
|
|
|
|
BOOL PastFromClipboard(void); //从剪切板上粘贴图像
|
|
|
BOOL CopyToClipboard(HWND hWnd=NULL);
|
|
|
|
|
|
BOOL Draw(CDC& hDestDC, CRect8& rectScreenDest, CRect* clientRect);
|
|
|
long Draw(HDC hDestDC, const RECT& rectDest, const RECT& rectSrc, DWORD dwRop = SRCCOPY); //显示图像,支持透明显示
|
|
|
long Draw(HDC hDestDC, int xDest, int yDest, int nDestWidth, int nDestHeight,
|
|
|
int xSrc, int ySrc, int nSrcWidth, int nSrcHeight, DWORD dwRop = SRCCOPY);
|
|
|
void Erase(COLORREF pColor);
|
|
|
|
|
|
void operator = (const CImageBase& isrc);
|
|
|
|
|
|
HBITMAP MakeBitmap32(HDC hdc = NULL);
|
|
|
|
|
|
bool GetColorTable( RGBQUAD** pprgbColors );
|
|
|
void SetColorTable( RGBQUAD* prgbColors );
|
|
|
int GetMaxColorTableEntries(void);
|
|
|
|
|
|
BYTE* GetPixelAddress(long x, long y);
|
|
|
COLORREF GetPixel(long x, long y);
|
|
|
void SetPixel(long x, long y, COLORREF color);
|
|
|
int GetType(void);
|
|
|
int GetBpp(void);
|
|
|
|
|
|
int GetSerializeType(CString strFileExt);
|
|
|
|
|
|
BOOL LoadImage(LPCTSTR lpszImageName);
|
|
|
BOOL LoadImage(CFile& fr);
|
|
|
BOOL SaveAs(LPCTSTR lpszImageName, CRect8* pRect=NULL);
|
|
|
BOOL SaveAs(CFile& fw);
|
|
|
bool Serialize(CArchive& ar, const short &ver);
|
|
|
|
|
|
INT_PTR FileDialog( BOOL bOpenFileDialog, CString& fileName, CString strTitle=_T(""), DWORD lFlags=OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT );
|
|
|
CString GetImageFilter(BOOL bOpenFileDialog);
|
|
|
|
|
|
//CImage
|
|
|
bool ReadBitmap(CArchive& ar, CImage* pImage);
|
|
|
bool WriteBitmap(CArchive& ar, CImage* pImage);
|
|
|
HBITMAP CreateBitmapIndirect(HBITMAP hScrBitmap);
|
|
|
HBITMAP CreateBitmapIndirect(LPBITMAPINFO lpBitmapInfo, const void* lpSrcBits);
|
|
|
|
|
|
bool Gamma(double gamma);//0.1至5
|
|
|
bool Light(long brightness, long contrast=0);
|
|
|
void MirrorX(void);
|
|
|
void MirrorY(void);
|
|
|
void TowColor(int NoBegin, int NoEnd);
|
|
|
long ReplaceColor(COLORREF oldColor, COLORREF newColor);
|
|
|
|
|
|
static int GetImageType(LPCTSTR lpszImageName);
|
|
|
static void* GetSupportImageType(int* pOutCount); //获得支持的所有图像类型
|
|
|
|
|
|
void DrawCurve(void* pCurve, void *pZoom, COLORREF col);//CCurve* pCurve, CGrid* pZoom
|
|
|
void LineTo(CPoint point, COLORREF col);
|
|
|
void MoveTo(CPoint point);
|
|
|
//以x0为轴,//IsPositive=0画负轴,=1画正轴,=2两边都画
|
|
|
void DrawSolid(int x0, int x1, int x2, int y1, int y2, COLORREF col, int IsPositive);
|
|
|
|
|
|
/**
|
|
|
* 获取当前透明模式
|
|
|
* 透明模式通过位运算存储,可能同时存在多种状态
|
|
|
*
|
|
|
* \return 返回当前的透明模式值,表示不同的透明模式状态
|
|
|
*/
|
|
|
uint32_t GetTransparentMode();
|
|
|
|
|
|
/**
|
|
|
* 设置透明模式
|
|
|
*
|
|
|
* \param transparentMode 透明模式
|
|
|
*/
|
|
|
void SetTransparentMode(uint32_t transparentMode);
|
|
|
|
|
|
/**
|
|
|
* 清理透明模式
|
|
|
*
|
|
|
* \param transparentMode 透明模式
|
|
|
*/
|
|
|
void ClearTransparentMode(uint32_t transparentMode);
|
|
|
|
|
|
protected:
|
|
|
bool Lut(BYTE* pTable);
|
|
|
CPoint PointBegin; //for MoveTo, LineTo
|
|
|
public:
|
|
|
|
|
|
private:
|
|
|
uint32_t m_transparentMode = 0;
|
|
|
};
|
|
|
|
|
|
};
|
|
|
|
|
|
using namespace NImage;
|