Skip to content

CopyRectangle

Chuck Walbourn edited this page Jun 21, 2015 · 9 revisions

Copies a rectangle of pixels from one image to another.

Block compressed images are not supported as either the source or destination. Use [Decompress] to uncompress BC images before using this function.

HRESULT CopyRectangle( const Image& srcImage, const Rect& srcRect,
   const Image& dstImage,
   DWORD filter, size_t xOffset, size_t yOffset );

Parameters

srcRect: A rectangle described with x, y of the upper right corner, and w and h with the width and height, which indicates pixel location from srcImage to copy. The w and h also define the size of the destination rectangle in dstImage. Both rectangles must be valid for the size of the images (i.e. the API does not support clipping).

filter: See Filter Flags. Source and destination images do not need to be the same format, in which case conversions will use these flags.

xOffset, yOffset: Pixel location of destination rectangle in dstImage. The width and height of the destination rectangle is the same as srcRect.w and srcRect.h.

Example

Here's an example that copies a source image to the location (100,50) location in a new, larger image.

ScratchImage srcImage;

...

ScratchImage destImage;
destImage.Iniitalize2D( ... );

auto mdata = srcImage.GetMetadata();
Rect r( 0, 0, mdata.width, mdata.height );
hr = CopyRectangle( *srcImage.GetImage(0,0,0), r, *dstImage.GetImage(0,0,0), 
   TEX_FILTER_DEFAULT, 100, 50 );
if ( FAILED(hr) )
    ...

Remarks

Behavior of this function is not defined if the source and destination image are the same and the source and destination rectangles overlap.

For Use

  • Universal Windows Platform apps
  • Windows desktop apps
  • Windows 11
  • Windows 10
  • Windows 8.1
  • Xbox One
  • Xbox Series X|S
  • Windows Subsystem for Linux

Architecture

  • x86
  • x64
  • ARM64

For Development

  • Visual Studio 2022
  • Visual Studio 2019 (16.11)
  • clang/LLVM v12 - v18
  • GCC 10.5, 11.4, 12.3
  • MinGW 12.2, 13.2
  • CMake 3.20

Related Projects

DirectXTex Rust bindings

DirectX Tool Kit for DirectX 11

DirectX Tool Kit for DirectX 12

DirectXMesh

DirectXMath

Tools

Test Suite

Content Exporter

DxCapsViewer

See also

DirectX Landing Page

Clone this wiki locally