Author Message

Hi all,

What's the best (i.e. fastest) way to copy portions of an internal bitmap to
the graphics object? I have an internal bitmap that contains a grid of 32x32
tile images. I'm using a source RECT and destination RECT to throw them onto
the graphics object, but it's rather slow. Here's a snippet of the main
rendering loop. I loop through each visible row and get the index of the
tile in the first position of the row. Then I loop through each column, get
the number of the tile from an array describing the map, set the upper-left
corner of the source RECTANGLE, and use DrawImage to copy the tile to the
GRAPHICS object:

For MapRow = StartRow To ViewRows
    TileIndex = MapRow * m_Map.Width + StartCol
    For MapCol = StartCol To ViewCols
        TileNum = m_Map.MapData(TileIndex)
        SrcRect.X = (TileNum Mod TILESETCOLS) * m_TileSize.Width
        SrcRect.Y = (TileNum \ TILESETCOLS) * m_TileSize.Height
        g.DrawImage(m_TileBitmap, DstRect, SrcRect, GraphicsUnit.Pixel)
        TileIndex += 1
        DstRect.X = DstRect.X + MAPTILEWIDTH
    DstRect.X = StartPoint.X
    DstRect.Y = DstRect.Y + MAPTILEHEIGHT

It works, but it's rather slow. Is the MOD function slowing this down or is
it the DrawImage method? Is there a better way of doing this? Also, this
routine is in the OnPaint event procedure of a PictureBox control. It
doesn't seem to redraw the tiles when it should. Is there a different event
I should be using to draw the tiles?


Tim Overbay

Tue, 13 Jul 2004 00:12:28 GMT  
 [ 1 post ] 

 Relevant Pages 

1. bitblt gdi+/gdi

2. autoredraw and gdi+

3. 'File not Found : GDI ' when using GetDeviceCaps% Lib "GDI" API

4. GDI Halt! GDI March! DoEvents, Processes etc

5. GDI Halt! GDI March! DoEvents, Processes etc

6. XP Runtime DB causes GDI.EXE GP fault in Win 9.x

7. Windows GDI Calls And Font Display Size

8. gdi and report problems

9. GDI resources leaking with Access97

10. GDI+ question

11. GetHicon - Generic error in GDI+

12. GDI+


Powered by phpBB® Forum Software