Direct2D的位图画笔拉长 [英] Direct2D bitmap brush elongated

查看:303
本文介绍了Direct2D的位图画笔拉长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要画在屏幕外的位图我的造型,但我有一个奇怪的问题,当我试图使我的位图。

这是图像的显示方式:

这我一怎么看的位图:

以下是code我用它来创建位图刷:

 常量自动调整大小= renderTarget->的getSize();
常量自动pxSize = D2D1 :: SizeU(size.width * 4,size.height * 4);ID2D1Bitma prenderTarget * compatibleRenderTarget;
HRESULT HR = renderTarget-> CreateCompatibleRenderTarget(大小,pxSize,&安培; compatibleRenderTarget);如果(成功(HR))
{
  //计算可视面积和当前变换矩阵
  常量自动面积= get_visible_area(的RenderTarget);
  常量自动转换= D2D1 :: Matrix3x2F ::标识();  //屏幕外的位图呈现
  compatibleRenderTarget-> BeginDraw();  //绘制各种形状  compatibleRenderTarget-> EndDraw();  //从渲染目标位图。
  ID2D1Bitmap *位图;
  HR = compatibleRenderTarget-> GetBitmap(安培;位图);  //释放兼容的渲染目标
  compatibleRenderTarget->发行();  //创建位图画笔
  ID2D1BitmapBrush * bitmapBrush = nullptr;
  HR = renderTarget-> CreateBitmapBrush(位图,D2D1 :: BitmapBrushProperties(),放大器; bitmapBrush);
  bitmap->发行();
  //位图绘制
  renderTarget-> FillRectangle(面积,bitmapBrush);
}


解决方案

的作用是一个标准的行为造成的。如果使用位图画笔,您可以选择不同的扩展模式(默认为钳)。这定义,如果几何尺寸超出了位图的大小会发生什么(在你的情况与FillRect())。你必须定义扩展模式,X和Y在 D2D1_BITMAP_BRUSH_PROPERTIES 的轴系它要传递到的 ID2D1RenderTarget :: CreateBitmapBrush()

结构

您可以选择(的这里)说:


  • 夹(重复位图的最后一行)

  • 裹(瓦位图)

  • 镜像

如果你不想你的位图被夹住包裹没有,你只需要使用的 ID2D1RenderTarget :: DrawBitmap()的方法来代替。

修改:如果 sourceRectangle 的距离的 destinationRectangle 的大小不同,将拉伸位图。您可以通过指定的 D2D1_BITMAP_INTERPOLATION_MODE 的调节拉伸质量(算法)。我认为它默认为近邻,但线性插值是更好的质量。

I have to draw my shapes on a offscreen bitmap, but I have a strange problem when I try to render my bitmap.

This is how the image should be displayed:

And this how I a see the bitmap:

Following is the code I use to create the bitmap brush:

const auto size = renderTarget->GetSize();
const auto pxSize = D2D1::SizeU(size.width * 4, size.height * 4);

ID2D1BitmapRenderTarget* compatibleRenderTarget;
HRESULT hr = renderTarget->CreateCompatibleRenderTarget(size, pxSize, &compatibleRenderTarget);

if (SUCCEEDED(hr))
{
  // compute visible area and the current transformation matrix
  const auto area = get_visible_area(renderTarget);
  const auto transform = D2D1::Matrix3x2F::Identity();

  // offscreen bitmap rendering
  compatibleRenderTarget->BeginDraw();

  // draw all shapes

  compatibleRenderTarget->EndDraw();

  // Retrieve the bitmap from the render target.
  ID2D1Bitmap* bitmap;
  hr = compatibleRenderTarget->GetBitmap(&bitmap);

  // release the compatible render target
  compatibleRenderTarget->Release();

  // Create the bitmap brush
  ID2D1BitmapBrush* bitmapBrush = nullptr;
  hr = renderTarget->CreateBitmapBrush(bitmap, D2D1::BitmapBrushProperties(), &bitmapBrush);
  bitmap->Release();


  // draw bitmap
  renderTarget->FillRectangle(area, bitmapBrush);
}

解决方案

The effect is a result of a standard behavior. If you use bitmap brush you can choose different extend modes (default is clamp). This defines what will happen if the geometry size exceeds the bitmap size (as in your case with FillRect()). You have to define extend modes for X and Y axises in the D2D1_BITMAP_BRUSH_PROPERTIES structure which you are passing to ID2D1RenderTarget::CreateBitmapBrush().

You can choose between (as stated here):

  • Clamp (repeat the last line of the bitmap)
  • Wrap (tile the bitmap)
  • Mirror

If you dont want your bitmap to be clamped neither wrapped, you can just use ID2D1RenderTarget::DrawBitmap() method instead.

Edit: If sourceRectangle differs from destinationRectangle in size, the bitmap will be stretched. You can adjust the stretch quality (algorithm) by specifying D2D1_BITMAP_INTERPOLATION_MODE. I think it defaults to nearest neighbour, but linear interpolation is better quality.

这篇关于Direct2D的位图画笔拉长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆