Fast way to blit between bitmaps

This is a discussion on Fast way to blit between bitmaps within the C# Programming forums, part of the General Programming Boards category; Anyone know of a fast way to take a smaller bitmap from a larger bitmap? Bitmap.Clone() runs out of memory ...

  1. #1
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596

    Fast way to blit between bitmaps

    Anyone know of a fast way to take a smaller bitmap from a larger bitmap?

    Bitmap.Clone() runs out of memory after 30 images. I need to create hundreds of tiles from a larger image.

    All the examples I've found use LockBits which requires some unmanaged pointers. Not that I don't like pointers but dealing with them in C# does not look fun and the Marshal class appears to only copy much like memcpy does. So it's not possible to specify a rectangle nor control the areas it copies unless I copy one scan line at a time.

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Well since no one seems to have a better solution yet I'm going to code a C++ module that uses inline assembly to do the copying and then create an ATL COM DLL so I can use it easily in C#.

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Hmm ... doesn't the GDI+ have some blitting functions? It's from DC to DC, but memory DCs work well.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,806

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Nah that creates a graphics object from an image. I'm using that to create a graphics object from my bitmap which represents the screen. Similar to creating a memory DC and then blitting from that to the client DC.

    I've nearly completed the assembly code but I'm so rusty at it. My main problem is when doing a rep movsd if the length in ecx is not evenly divisible by 4 (the size of a DWORD) then some bytes are left.

    I think a simple and operation followed by a rep movsb ought to do the trick to get the remaning bytes.

  6. #6
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,806
    So something like this wouldn't work for you Bubba
    Code:
    protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);
    
        //Load a bitmap and create a new one to draw a sub bitmap
        Bitmap greenRed = (Bitmap)Bitmap.FromFile("greenred.bmp");
        Bitmap destImage = new Bitmap(20, greenRed.Height);
    
        //Grab the drawing surface for the new image
        Graphics destGraphics = Graphics.FromImage(destImage);
    
        //Draw the old one into the new ones smaller space
        destGraphics.DrawImage(greenRed, 0, 0);
    
        //Draw both on the screen
        e.Graphics.DrawImage(greenRed, new Point(0, 0));
        e.Graphics.DrawImage(destImage, new Point(100,0));
    }
    Attached Images Attached Images  

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Drawing bitmaps efficiently
    By scwizzo in forum Windows Programming
    Replies: 28
    Last Post: 06-30-2009, 08:25 PM
  2. DX9 Not Displaying Bitmaps
    By Sentral in forum Game Programming
    Replies: 9
    Last Post: 01-31-2006, 04:35 AM
  3. MFC: Multiple clicks shows multiple bitmaps - how?
    By BrianK in forum Windows Programming
    Replies: 0
    Last Post: 06-20-2004, 07:25 PM
  4. textprintf - how to blit it?
    By GaPe in forum Game Programming
    Replies: 5
    Last Post: 05-04-2003, 03:22 AM
  5. using standard bitmaps in the toolbar editor
    By Kibble in forum Windows Programming
    Replies: 0
    Last Post: 12-23-2002, 07:43 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21