C Board  

Go Back   C Board > General Programming Boards > C# Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 11-25-2007, 07:32 PM   #1
Super Moderator
 
Bubba's Avatar
 
Join Date: Aug 2001
Posts: 7,817
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.
Bubba is offline   Reply With Quote
Old 11-26-2007, 05:26 PM   #2
Super Moderator
 
Bubba's Avatar
 
Join Date: Aug 2001
Posts: 7,817
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#.
Bubba is offline   Reply With Quote
Old 11-26-2007, 06:32 PM   #3
Cat without Hat
 
CornedBee's Avatar
 
Join Date: Apr 2003
Posts: 8,492
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
CornedBee is offline   Reply With Quote
Old 11-26-2007, 06:37 PM   #4
Sweet
 
Join Date: Aug 2002
Location: Tucson, Arizona
Posts: 1,698
Maybe something like this Bubba.
http://msdn2.microsoft.com/en-us/lib...fromimage.aspx
prog-bman is online now   Reply With Quote
Old 11-26-2007, 08:02 PM   #5
Super Moderator
 
Bubba's Avatar
 
Join Date: Aug 2001
Posts: 7,817
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.
Bubba is offline   Reply With Quote
Old 11-26-2007, 08:35 PM   #6
Sweet
 
Join Date: Aug 2002
Location: Tucson, Arizona
Posts: 1,698
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
 
prog-bman is online now   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 02:24 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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