Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 位图正在拉伸而不是平铺_C++_Windows_Image_Mfc_Bitmap - Fatal编程技术网

C++ 位图正在拉伸而不是平铺

C++ 位图正在拉伸而不是平铺,c++,windows,image,mfc,bitmap,C++,Windows,Image,Mfc,Bitmap,我正在尝试获取位图以平铺如下内容: ---- ---- ---- | || || | ---- ---- ---- 以执行以下操作为例: CD2DBitmapBrush* m_pBitBrush; m_pBitBrush = new CD2DBitmapBrush(GetRenderTarget(), _T("grass.bmp")); POINT pt; pt.x = 0; pt.y = 0; CRect rect = new CRect(pt, m_pBit

我正在尝试获取位图以平铺如下内容:

 ----  ----  ----
|    ||    ||    |
 ----  ----  ----
以执行以下操作为例:

CD2DBitmapBrush* m_pBitBrush;
m_pBitBrush = new CD2DBitmapBrush(GetRenderTarget(), _T("grass.bmp"));

POINT pt;
pt.x = 0;
pt.y = 0;
CRect rect = new CRect(pt, m_pBitBrush->GetBitmap()->GetSize());

pRenderTarget->FillRectangle(rect, m_pBitBrush);


for(int i = 0; i < 5; i++)
{
    pt.x += 40; 
    rect = new CRect(pt, m_pBitBrush->GetBitmap()->GetSize()); 
    pRenderTarget->FillRectangle(rect, m_pBitBrush);
}
另外,我尝试过在第一次调用画笔后更改画笔使用的图像,但在原始画笔之后什么也不显示

CRect rect = new CRect(pt, m_pBitBrush->GetBitmap()->GetSize());
pRenderTarget->FillRectangle(rect, m_pBitBrush); 

CD2DBitmap* bit = new CD2DBitmap(GetRenderTarget()/*pRenderTarget*/, _T("stone.bmp"));  
m_pBitBrush->SetBitmap(bit);
for(int i = 0; i < 5; i++)
{
    pt.x += 40;
    rect = new CRect(pt, m_pBitBrush->GetBitmap()->GetSize()); 
    pRenderTarget->FillRectangle(rect, m_pBitBrush);
}
CRect rect=new-CRect(pt,m_pBitBrush->GetBitmap()->GetSize());
pRenderTarget->FillRectangle(矩形,m_pBitBrush);
CD2DBitmap*bit=新的CD2DBitmap(GetRenderTarget()/*pRenderTarget*/,_T(“stone.bmp”);
m_pBitBrush->SetBitmap(位);
对于(int i=0;i<5;i++)
{
pt.x+=40;
rect=new-CRect(pt,m_-pBitBrush->GetBitmap()->GetSize());
pRenderTarget->FillRectangle(矩形,m_pBitBrush);
}

当然,我在这里做错了什么,因为我是新来的,但我似乎无法让这个工作。有人能给我指出正确的方向吗?

您想在
CD2BitmapBrush
上使用
SetExtendModeX(D2D1\U扩展模式)
和/或
SetExtendModeY(D2D1\U扩展模式)
。默认值似乎是
D2D1\u EXTEND\u MODE.D2D1\u EXTEND\u MODE\u CLAMP
,这会导致拉伸。您需要
D2D1\u扩展\u模式。D2D1\u扩展\u模式\u包装


参考资料:

+1即使只是用于漂亮的ASCII图表。我想如果没有它们可能会让人困惑。希望这有助于澄清我想说的话。谢谢你迄今为止的帮助!这对初始的平铺/画笔非常有效,但是,如果我想更改画笔使用的图像,在填充初始矩形后将不会显示任何内容。你知道这可能是什么原因吗?注意:重新创建画笔,如
m_pBitBrush=new CD2DBitmapBrush(pRenderTarget,_T(“stone.bmp”)
还替换了原始画笔的填充。我不知道是什么原因造成的,但将每个画笔限制为一个图像在一定程度上是有意义的。因此,创建单独的画笔确实可行,但如果创建新的瓷砖类型,这会有点不方便。我是否应该就如何实现这一目标提出单独的问题?
CRect rect = new CRect(pt, m_pBitBrush->GetBitmap()->GetSize());
pRenderTarget->FillRectangle(rect, m_pBitBrush); 

CD2DBitmap* bit = new CD2DBitmap(GetRenderTarget()/*pRenderTarget*/, _T("stone.bmp"));  
m_pBitBrush->SetBitmap(bit);
for(int i = 0; i < 5; i++)
{
    pt.x += 40;
    rect = new CRect(pt, m_pBitBrush->GetBitmap()->GetSize()); 
    pRenderTarget->FillRectangle(rect, m_pBitBrush);
}