Sukasa
Sukasa

Reputation: 1700

Drawing.Graphics - Way to change pixel offset of source bitmap?

Having a small problem finding a function or method to do what I'm looking for, hoping someone might be able to give a bit of insight here.

I've got a function that's supposed to extract and return a 32x32px bitmap from a larger bitmap which has a set of 32x32 tiles inside it.

Here's the code I have now, but it's wrong since the Tile.GFX_Pos properties are telling it where in the destination image to draw, not where in the source image to draw from.

  Overloads Shared Function TileGFX(ByVal SrcGFX As Bitmap, ByVal Tile As TileDef) As System.Drawing.Bitmap
      Try
          Dim GFX As Bitmap = TileBitmap()
          Dim GGFX As Graphics = Graphics.FromImage(GFX)
          GGFX.DrawImageUnscaledAndClipped(SrcGFX, New Rectangle(Tile.GFXXPos, Tile.GFXYPos, TileSize, TileSize))

          Return GFX
      Catch ex As Exception
          Return TileBitmap()
      End Try
  End Function

So since this doesn't work, what I'm wondering is if anyone knows a good way to select where in the SrcGFX bitmap to blit from, instead of (as currently and incorrectly) selecting where in the destination bitmap to blit to.

Upvotes: 2

Views: 1030

Answers (1)

MusiGenesis
MusiGenesis

Reputation: 75276

Use the DrawImage() method instead of DrawImageUnscaledAndClipped().
DrawImage has umpteen billion overloads (ok, 30) including a bunch that let you specify both the source and destination locations.

Upvotes: 1

Related Questions