请问GDI位图和DIB的区别?

powerthinkding 2004-05-07 10:56:05
我知道GDI位图是图形设备接口,DIB是设备无关位图,但是偶不知道本质的区别。
请高手详细指教,小弟不才,多谢!!!
...全文
157 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
FengYuanMSFT 2004-05-08
  • 打赏
  • 举报
回复
Read my book, read my book, read my book.

1) DDB is device dependent. One device may know it, another device may not know it. DIB is public format, everyone can access it.

2) DDB image data is hidden by device driver, normally stored in kernel mode, could be stored on display card. DIB is stored in user mode memory when loaded into memory.

3) DDB consumes kernel mode memory, which has low limit.

4) DDB costs on GDI handle, another GDI handle for memory.

5) DDB can be writtend to through a memory DC. GDI does not support rendering into a DIB, only from.

6) You have more formats control over DIB.

...

Do not use DDB unless you want to display the same bitmap over and over again, and performance is critical; or you want to do something special with 1-bit per pixel DDB.
class CSBitmap //Bitmap类,特点紧约型数据结构,GetPixel效率高,放弃调色板,自动支持4种色深,特有的12位颜色更接近人眼可识别颜色数目;有多种缩放,色深转换,拷贝,剪切,和hBitmap转换,显示等功能;支持串行化。支持1,12,24,32位位图,对应适用于所有函数,相比于HBitmap和CSBitmap对象要简单,可直接操作数据区;同时可用于1,4,8,12,16,24,32位二维数列的储存,部分基本函数(GetPixel,SetPixel)支持; { public: CSBitmap(void); ~CSBitmap(void); unsigned int Width; //Bitmap的宽 unsigned int Height; //Bitmap的高 DWORD BitSize; //Bitmap的数据区大小(字节) BYTE* pBitData; //Bitmap的数据区指针 unsigned int BitCount; //Bitmap的色深 bool SetAttribute(unsigned int mWidth=NULL, unsigned int mHeight=NULL, unsigned int mBitCount=NULL); //设置Bitmap的属性,Bitmap会被清除 mWidth Bitmap的宽度,为NULL则不改变 mHeight Bitmap的高度,为NULL则不改变 mBitCount Bitmap的色深,为NULL则不改变 bool ImportBits(BYTE* lpBits, int mBitSize=NULL); //拷贝Bits数据进对象数据区 lpBits 拷贝数据的指针 mBitSize 拷贝数据的字节数 COLORREF GetPixel(unsigned int x, unsigned int y); //获得某点的原始数值,当为12,24,32位数时,则为RGB值 X,y 需要获取点的坐标 bool SetPixel(unsigned int x, unsigned int y, COLORREF clr); //获得某点的原始数值,当为12,24,32位数时,则为RGB值 X,y 需要设置点的坐标 bool StretchDIB(CSBitmap* DestBmp, unsigned int mWidth, unsigned int mHeight, unsigned int mFlag=0); //缩放 DestBmp用于获取缩放后图片的指针 mWidth, mHeight缩放后大小 mFlag缩放算法 取值 算法 缩小 放大 0 逆向寻点算法 效率高,质量一般 效率高,质量中 1 双线性补点 效率低,质量一般 效率低,质量高 2 平均值算法 效率低,质量好 效率高,质量差 static BYTE GetRValue12(COLORREF Clr12Bit); static BYTE GetGValue12(COLORREF Clr12Bit); static BYTE GetBValue12(COLORREF Clr12Bit); //用于12位图的获取RGB分量,24位图,32位图的COLOR分离请用GDI的GetPixel() Clr12Bit 对12位图GetPixel获得的原始值 static COLORREF RGB12(BYTE R, BYTE G, BYTE B); //用于12位图的RGB合成,24位图,32位图的COLOR合成请用GDI的RGB() static COLORREF Color24To1(COLORREF Color24); //24位色深COLORREF转1位色深(黑白)值 static COLORREF Color24To12(COLORREF Color24); //24位色深COLORREF转12位色深值 static COLORREF Color1To24(COLORREF Color2); //1位色深COLORREF转24位,32位色深(黑白)值 static COLORREF Color12To24(COLORREF Color12); //12位色深COLORREF转24位,32位色深(黑白)值 bool ConvertTo1Bit(CSBitmap* DestBmp); //12,24,36位图片转换成1位色深图 DestBmp用于接收数据的DestBmp指针,转换过程中包括自动参数重置 bool ConvertTo12Bit(CSBitmap* DestBmp); //1,24,36位图片转换成12位色深图 DestBmp用于接收数据的DestBmp指针,转换过程中包括自动参数重置 bool ConvertTo24Bit(CSBitmap* DestBmp); //1,12,36位图片转换成24位色深图 DestBmp用于接收数据的DestBmp指针,转换过程中包括自动参数重置 bool FromHandle(HBITMAP hBitmap); //从HBITMAP中获得CSBitmap对象 bool CopyPaste(CSBitmap* DestBmp, unsigned int x, unsigned int y); //复制本CSBitmap至另一DestBmp的指定位置 DestBmp 目标,对象 X,y复制后图片左上角位置 bool PaintDIB(CDC* dcDest, int x,int y,unsigned int mWidth, unsigned int mHeight); //把本图片显示至CDC对象上,支持1,12,24,26位图 dcDest 目标dc(兼容DC) x,y 拷贝到dc上的位置 mWidth,mHeight拷贝后的大小 const CSBitmap& operator=(const CSBitmap &SBmp); }; //重载了 = 赋值操作符

19,468

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧