Jump to content
Sign in to follow this  
chmichael

ID3D11Texture2D to TBitmap and RowPitch

Recommended Posts

Hello,

  Anyone knows how to copy the Bits from a ID3D11Texture2D  which it has different RowPitch than Bitmap.Width * 4 ?

 

  if FTexture.RowPitch = FBitmap.Width * 4 then
  for I := 0 to FBitmap.Height - 1 do
    Move(FTexture.pData[4 * FBitmap.Width * I], FBitmap.Scanline^, 4 * FBitmap.Width);
  else
    ?????

 

Thank you

 

Edited by chmichael

Share this post


Link to post
On 10/14/2023 at 3:42 PM, chmichael said:

Anyone knows how to copy the Bits from a ID3D11Texture2D  which it has different RowPitch than Bitmap.Width * 4 ?

 

It doesn't only depend to the pitch, but also on the pixel-format of the source. If that is BGR or BGRA, the following pseudo-code based on what you post

should be usable. If the color-order is different, like RGB or RGBA, you need to copy the single color-bytes. Best done by defining a record for the pixel.

// Pointers to Pixels in Source/Target to be copied
  var
    pPixS, pPixT: pByte;

    // Bytes per Pixel for the Source-Texture
    // would be 3 for BGR, 4 for BGRA
    // if the channels have a different order, like RGB,
    // then the single color bytes need to be copied.
  var
    BytesPerPixel: integer;

    // Common Width and Height of Source and Target
  var
    Width, Height: integer;

  for I := 0 to Height - 1 do
  begin
    pPixS := @FTexture.pData[FTexture.RowPitch * I];
    pPixT := FBitmap.Scanline[I];
    for j := 0 to Width - 1 do
    begin
      Move(pPixS^, pPixT^, BytesPerPixel);
      inc(pPixS, BytesPerPixel);
      inc(pPixT, 4);
    end;
  end;

 

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×