怎么显示位图中的一部分

windeer 2005-04-16 01:42:25
怎么显示一张位图中的一部分?

就是GDI中的bitblt那样的画位图!

用DirectDraw怎么实现?
...全文
53 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
windeer 2005-04-16
  • 打赏
  • 举报
回复
找出问题了! 我好晕!
windeer 2005-04-16
  • 打赏
  • 举报
回复
//**************************************************
// 函数名称: ShowBitmapEx
// 参数说明: pBitmap 位图结构指针
// cx,cy 源表面的起始点位置
// x,y 目标表面的起始位置
// width,height 画的宽度和高度
// transparent 1 过滤关键色 0 不过滤
// 功能说明:将位图从离屏表面Blt到后备缓冲
// 修改记录: Create on 2005.04.03
//***************************************************
BOOL CDDraw::ShowBitmapEx( BITMAPFILE* pBitmap,
int cx, int cy, int x,
int y, int width,
int height, int transparent )
{
RECT destrect, // the destination rectangle
sourcerect; // the source rectangle

LPDIRECTDRAWSURFACE7 source = 0;

source = pBitmap->pSurface; //CreateSurface( width, height, 1, pBitmap->color );

if( !source )
{
return 0;
}

// fill in the destination rect
destrect.left = x;
destrect.top = y;
destrect.right = x+width-1;
destrect.bottom = y+height-1;

// fill in the source rect
sourcerect.left = cx;
sourcerect.top = cy;
sourcerect.right = width-1;
sourcerect.bottom = height-1;

// test transparency flag
if (transparent)
{
// enable color key blit
// blt to destination surface
if (FAILED(lpDDSBack->Blt(&destrect, source,
&sourcerect,(DDBLT_WAIT | DDBLT_KEYSRC),
NULL)))
return 0;

} // end if
else
{
// perform blit without color key
// blt to destination surface
if (FAILED(lpDDSBack->Blt(&destrect, source,
&sourcerect,(DDBLT_WAIT),
NULL)))
return 0;

} // end if

// return success
return 1;
}

这是我的显示位图的函数。
我刚又试了

当cx,cy比较小的时候,可以画出来。

我确保参数是有效的

我是用的Direct Draw里的Clip裁剪的
windeer 2005-04-16
  • 打赏
  • 举报
回复
可是我试过了
有时候不成功!

我下先将一张位图写到离屏表面,

我整个的画到后台缓冲,再Flip,可以出来
可是我画一部分以后台缓冲的时候有时就不出来,我一直不知道原因在哪里?
chunhai12 2005-04-16
  • 打赏
  • 举报
回复
Blt的时候只画位图中的一部分

IDirectDrawSurface7::Blt

HRESULT Blt(
LPRECT lpDestRect,
LPDIRECTDRAWSURFACE7 lpDDSrcSurface,
LPRECT lpSrcRect, //位图的RECT,设置为你要显示的部分
DWORD dwFlags,
LPDDBLTFX lpDDBltFx
);

8,304

社区成员

发帖
与我相关
我的任务
社区描述
游戏开发相关内容讨论专区
社区管理员
  • 游戏开发
  • 呆呆敲代码的小Y
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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