有一个CBitmap对象,怎么才能够将它(??)赋值给DIB指针(图象问题初步)

Belle 2001-12-03 12:21:30
想对CBitmap对象进行一些DIB处理
问题也提不清
对图象不熟,多多指点
...全文
221 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
Belle 2001-12-09
  • 打赏
  • 举报
回复
问题解决,特来散分
Belle 2001-12-06
  • 打赏
  • 举报
回复
GDI图象怎么生成 DIB呢??
帮忙呀
分少了再加
rockswang 2001-12-06
  • 打赏
  • 举报
回复
呵呵,我帮你顶^^
mzm100 2001-12-06
  • 打赏
  • 举报
回复
其实这段代码来自MSDN的例子中的DIB.c,自己看看,什么都懂了。
mzm100 2001-12-06
  • 打赏
  • 举报
回复
一个例子:
HANDLE DibFromBitmap (hbm, biStyle, biBits, hpal)
HBITMAP hbm;
DWORD biStyle;
WORD biBits;
HPALETTE hpal;
{
BITMAP bm;
BITMAPINFOHEADER bi;
BITMAPINFOHEADER FAR *lpbi;
DWORD dwLen;
HANDLE hdib;
HANDLE h;
HDC hdc;

if (!hbm)
return NULL;

if (hpal == NULL)
hpal = GetStockObject(DEFAULT_PALETTE);

GetObject(hbm,sizeof(bm),(LPSTR)&bm);

if (biBits == 0)
biBits = bm.bmPlanes * bm.bmBitsPixel;

bi.biSize = sizeof(BITMAPINFOHEADER);
bi.biWidth = bm.bmWidth;
bi.biHeight = bm.bmHeight;
bi.biPlanes = 1;
bi.biBitCount = biBits;
bi.biCompression = biStyle;
bi.biSizeImage = 0;
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 0;
bi.biClrImportant = 0;

dwLen = bi.biSize + PaletteSize(&bi);

hdc = GetDC(NULL);
hpal = SelectPalette(hdc,hpal,FALSE);
RealizePalette(hdc);

hdib = GlobalAlloc(GHND,dwLen);

if (!hdib)
{
SelectPalette(hdc,hpal,FALSE);
ReleaseDC(NULL,hdc);
return NULL;
}

lpbi = (VOID FAR *)GlobalLock(hdib);

*lpbi = bi;

/* call GetDIBits with a NULL lpBits param, so it will calculate the
* biSizeImage field for us
*/
GetDIBits(hdc, hbm, 0, (WORD)bi.biHeight,
NULL, (LPBITMAPINFO)lpbi, DIB_RGB_COLORS);

bi = *lpbi;
GlobalUnlock(hdib);

/* If the driver did not fill in the biSizeImage field, make one up */
if (bi.biSizeImage == 0)
{
bi.biSizeImage = WIDTHBYTES((DWORD)bm.bmWidth * biBits) * bm.bmHeight;

if (biStyle != BI_RGB)
bi.biSizeImage = (bi.biSizeImage * 3) / 2;
}

/* realloc the buffer big enough to hold all the bits */
dwLen = bi.biSize + PaletteSize(&bi) + bi.biSizeImage;
if (h = GlobalReAlloc(hdib,dwLen,0))
hdib = h;
else
{
GlobalFree(hdib);
hdib = NULL;

SelectPalette(hdc,hpal,FALSE);
ReleaseDC(NULL,hdc);
return hdib;
}

/* call GetDIBits with a NON-NULL lpBits param, and actualy get the
* bits this time
*/
lpbi = (VOID FAR *)GlobalLock(hdib);

if (GetDIBits( hdc,
hbm,
0,
(WORD)bi.biHeight,
(LPSTR)lpbi + (WORD)lpbi->biSize + PaletteSize(lpbi),
(LPBITMAPINFO)lpbi, DIB_RGB_COLORS) == 0)
{
GlobalUnlock(hdib);
hdib = NULL;
SelectPalette(hdc,hpal,FALSE);
ReleaseDC(NULL,hdc);
return NULL;
}

bi = *lpbi;
GlobalUnlock(hdib);

SelectPalette(hdc,hpal,FALSE);
ReleaseDC(NULL,hdc);
return hdib;
}
Belle 2001-12-04
  • 打赏
  • 举报
回复
再来...
shesh 2001-12-03
  • 打赏
  • 举报
回复
HBITMAP CreateDIBSection(
HDC hdc, // handle to device context
CONST BITMAPINFO *pbmi,
// pointer to structure containing bitmap size,
// format, and color data
UINT iUsage, // color data type indicator: RGB values or
// palette indexes
VOID *ppvBits, // pointer to variable to receive a pointer to
// the bitmap's bit values
HANDLE hSection, // optional handle to a file mapping object
DWORD dwOffset // offset to the bitmap bit values within the
// file mapping object
);
去看看MSDN 中的Bitmap Functions
Belle 2001-12-03
  • 打赏
  • 举报
回复
我也看到GetDiBits 了,有代码吗(我是不是要得太过分了)
Happy_Wawe 2001-12-03
  • 打赏
  • 举报
回复
GetDiBits
Belle 2001-12-03
  • 打赏
  • 举报
回复
哪儿有呀??
pinel 2001-12-03
  • 打赏
  • 举报
回复
有网上下载的cdib类可以看看
xxtliu 2001-12-03
  • 打赏
  • 举报
回复
up
hoco 2001-12-03
  • 打赏
  • 举报
回复
我建议你还是先去了解一下位图文件(bmp)的格式吧,这样对你以后的编程学习是很有好处的!
其实对了图像的编程的总体思路就是:
平面图象可以看成是由很多很多的像素组成的。每一个像素由位置坐标和颜色来组成。
你对位图的操作只不过是改变不同位置上的像素的颜色而已!
好了,先说这么多吧!呵呵

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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