cximage函数总结

本文总结了CXImage库中的图像处理函数,包括加载、保存图片,获取图像尺寸,颜色处理如灰度化、二值化,以及翻转、膨胀、腐蚀等操作。此外,还介绍了调整亮度、对比度和自适应阈值等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、加载图片Load():bool Load(const TCHAR* filename, uint32_t imagetype=0);

参数1:图片名字
参数2:图片格式(下面列举)

以下是所有类型枚举:
----------------------------------------------------------------------------------
enum ENUM_CXIMAGE_FORMATS{
CXIMAGE_FORMAT_UNKNOWN = 0,
#if CXIMAGE_SUPPORT_BMP
CXIMAGE_FORMAT_BMP = 1,
#endif
#if CXIMAGE_SUPPORT_GIF
CXIMAGE_FORMAT_GIF = 2,
#endif
#if CXIMAGE_SUPPORT_JPG
CXIMAGE_FORMAT_JPG = 3,
#endif
#if CXIMAGE_SUPPORT_PNG
CXIMAGE_FORMAT_PNG = 4,
#endif
#if CXIMAGE_SUPPORT_ICO
CXIMAGE_FORMAT_ICO = 5,
#endif
#if CXIMAGE_SUPPORT_TIF
CXIMAGE_FORMAT_TIF = 6,
#endif
#if CXIMAGE_SUPPORT_TGA
CXIMAGE_FORMAT_TGA = 7,
#endif
#if CXIMAGE_SUPPORT_PCX
CXIMAGE_FORMAT_PCX = 8,
#endif
#if CXIMAGE_SUPPORT_WBMP
CXIMAGE_FORMAT_WBMP = 9,
#endif
#if CXIMAGE_SUPPORT_WMF
CXIMAGE_FORMAT_WMF = 10,
#endif
#if CXIMAGE_SUPPORT_JP2
CXIMAGE_FORMAT_JP2 = 11,
#endif
#if CXIMAGE_SUPPORT_JPC
CXIMAGE_FORMAT_JPC = 12,
#endif
#if CXIMAGE_SUPPORT_PGX
CXIMAGE_FORMAT_PGX = 13,
#endif
#if CXIMAGE_SUPPORT_PNM
CXIMAGE_FORMAT_PNM = 14,
#endif
#if CXIMAGE_SUPPORT_RAS
CXIMAGE_FORMAT_RAS = 15,
#endif
#if CXIMAGE_SUPPORT_JBG
CXIMAGE_FORMAT_JBG = 16,
#endif
#if CXIMAGE_SUPPORT_MNG
CXIMAGE_FORMAT_MNG = 17,
#endif
#if CXIMAGE_SUPPORT_SKA
CXIMAGE_FORMAT_SKA = 18,
#endif
#if CXIMAGE_SUPPORT_RAW
CXIMAGE_FORMAT_RAW = 19,
#endif
#if CXIMAGE_SUPPORT_PSD
CXIMAGE_FORMAT_PSD = 20,
#endif
CMAX_IMAGE_FORMATS = CXIMAGE_SUPPORT_BMP + CXIMAGE_SUPPORT_GIF + CXIMAGE_SUPPORT_JPG +
					 CXIMAGE_SUPPORT_PNG + CXIMAGE_SUPPORT_MNG + CXIMAGE_SUPPORT_ICO +
					 CXIMAGE_SUPPORT_TIF + CXIMAGE_SUPPORT_TGA + CXIMAGE_SUPPORT_PCX +
					 CXIMAGE_SUPPORT_WBMP+ CXIMAGE_SUPPORT_WMF +
					 CXIMAGE_SUPPORT_JBG + CXIMAGE_SUPPORT_JP2 + CXIMAGE_SUPPORT_JPC +
					 CXIMAGE_SUPPORT_PGX + CXIMAGE_SUPPORT_PNM + CXIMAGE_SUPPORT_RAS +
					 CXIMAGE_SUPPORT_SKA + CXIMAGE_SUPPORT_RAW + CXIMAGE_SUPPORT_PSD + 1
-------------------------------------------------------------------------------------------------------------

2、保存图片:bool Save(const TCHAR* filename, uint32_t imagetype);

参数以及格式与加载图片一模一样,可参考上面。

3、得到图形大小:long GetSize();

4、得到图形高度和宽度:

DWORD CxImage::GetHeight();
DWORD CxImage::GetWidth();

5、得到文件类型:DWORD CxImage::GetType() const;

6、得到最后一个错误:char* CxImage::GetLastError();

7、在界面中绘制出来

long CxImage::Draw(HDC hdc, const RECT& rect, RECT* pClipRect=NULL)
参数:
HDC 绘图设备,
rect 绘图的区域,确定绘图的左上角和右下角坐标。
pClipRect,裁剪区域,一般可以和绘图区域一样大小

8、图片处理,提高图片质量

bool Filter(int32_t* kernel, int32_t Ksize, int32_t Kfactor, int32_t Koffset);

9、copy图片:

void	Copy(const CxImage &src, bool copypixels = true, bool copyselection = true, bool copyalpha = true);

10、自定义图片大小(缩放):

Resample(int32_t newx, int32_t newy, int32_t mode = 1, CxImage* iDst = NULL);

11、调整图片饱和度:

bool Saturate(const int32_t saturation, const int32_t colorspace = 1);

12、图像灰度化:

bool GrayScale();

13、图片上下翻转:

bool Flip(bool bFlipSelection = false, bool bFlipAlpha = true);

14、图片左右翻转:

bool Mirror(bool bMirrorSelection = false, bool bMirrorAlpha = true);

15、图片颜色取反(255-原值):

bool Negative();

16、图片二值化;

	bool Threshold(uint8_t level);
	bool Threshold(CxImage* pThresholdMask);

17、converts the image to B&W using the desired method ;

bool Dither(int32_t method = 0);

18、自适应阈值:

bool AdaptiveThreshold(int32_t method = 0, int32_t nBoxSize = 64, CxImage* pContrastMask = 0, int32_t nBias = 0, float fGlobalLocalBalance = 0.5f);

19、膨胀:

bool Dilate(int32_t Ksize=2);

20、腐蚀:

bool Erode(int32_t Ksize=2);

21、IsValid检查图片是否正确初始化:

bool IsValid() const;

22、light图像亮度和对比度调整:

bool Light(int32_t brightness, int32_t contrast = 0);

23、设置像素颜色值

void	SetPixelColor(int32_t x,int32_t y,RGBQUAD c, bool bSetAlpha = false);
void	SetPixelColor(int32_t x,int32_t y,COLORREF cr);

几个函数的实现:

WORD CxImage::GetBpp() const return: 1, 4, 8, 24. 每像素所占得字节数
{
return head.biBitCount;
}


DWORD CxImage::GetEffWidth() const return DWORD aligned width of the image. 每行所站的字节数

{
return info.dwEffWidth;
}


DWORD CxImage::GetNumColors() const return 2, 16, 256; 0 for RGB images.  
{
return head.biClrUsed;
}


DWORD CxImage::GetWidth() const   获得图像的宽
{
return head.biWidth;
}


DWORD CxImage::GetHeight() const   获得图像的高
{
return head.biHeight;
}


void* CxImage::GetDIB() const return internal hDib object 指向DIB对象,即是指向图像
{
return pDib;
}


long CxImage::GetSize()return the size in bytes of the internal pDib object返回在内部pDib对象的字节大小   就是信息头,调色板,位图数据的大小。
{
return head.biSize + head.biSizeImage + GetPaletteSize();
}

bool CxImage ::Light (long brightness , long contrast )
{
       if (! pDib) return false;
       float c=(100 + contrast)/100.0f;
       brightness+=128;

       BYTE cTable[256]; //<nipper>
       for ( int i=0; i<256; i++) {
             cTable[ i] = ( BYTE) max(0, min(255,( int)(( i-128)* c + brightness + 0.5f)));
      }
      return Lut( cTable);
}

想了解更多自己看下面原文:

/*
 * File:	ximage.h
 * Purpose:	General Purpose Image Class 
 */
/*
  --------------------------------------------------------------------------------

	COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:

	CxImage version 7.0.2 07/Feb/2011

	CxImage : Copyright (C) 2001 - 2010, Davide Pizzolato

	Original CImage and CImageIterator implementation are:
	Copyright (C) 1995, Alejandro Aguilar Sierra (asierra(at)servidor(dot)unam(dot)mx)

	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.

	Permission is hereby granted to use, copy, modify, and distribute this
	source code, or portions hereof, for any purpose, including commercial applications,
	freely and without fee, subject to the following restrictions: 

	1. The origin of this software must not be misrepresented; you must not
	claim that you wrote the original software. If you use this software
	in a product, an acknowledgment in the product docu
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值