[.net] Copying Bitmaps to big Bitmap

Started by
13 comments, last by DrGUI 18 years, 3 months ago
Quote:Original post by capn_midnight
sounds like something fxord with your system. I use the Save method with PNGs all the time. I even have a little program that I wrote for making 1% sized png thumbnails.


That's nice to know :p
Maybe the images are just too big for the codec to handle? EDIT: it had that error again on a bmp approx 250x350 so maybe not. My system must be fxord! Jpeg doesn't seem to work either.
But if my system got fxord when I have a good firewall and don't install lots of random programs on it, how fxord must end users' computers be!!
Advertisement
Quote:Original post by DrGUI
Quote:Original post by capn_midnight
sounds like something fxord with your system. I use the Save method with PNGs all the time. I even have a little program that I wrote for making 1% sized png thumbnails.


That's nice to know :p
Maybe the images are just too big for the codec to handle? EDIT: it had that error again on a bmp approx 250x350 so maybe not. My system must be fxord! Jpeg doesn't seem to work either.
But if my system got fxord when I have a good firewall and don't install lots of random programs on it, how fxord must end users' computers be!!


it's not necessarily a virus. It actually sounds like the GDI+ dll is corrupt, and that could be just random bit rot. Try running the system repair from your OS disk (winxp, win2k, whatever). There is also a patch for GDI+ that was a really big deal quite a few months back and even brand new computers don't ship with it. So, you might want to run windows update and see if the "GDI+ detection tool" comes up.

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

Hey, I fixed it; rates for your post.

I assumed that once you created a bitmap from a stream you could dispose the stream, but evidently not. I can't help thinking that I would have solved this problem much earlier if the error message had been better... I guess the bitmap holds on to the stream as a backing store or something.

/////OLD///////Load a bitmap from the stream and save again in new formatSystem.Drawing.Bitmap bitmap;using (bitmapStream){	bitmap = new System.Drawing.Bitmap(bitmapStream);}//Save bitmapSaveBitmap(bitmap);/////NEW///////Load a bitmap from the stream and save again in new formatusing (bitmapStream){	System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(bitmapStream);	//Save bitmap  (using block has to encompass this else GDI+ error)	SaveBitmap(bitmap);}


Thanks for all your help!
One simple solution: don't use .Width and .Height in the for loop condition. These actually are incredibly slow. Just make width and height ints first, and use those in the condition.
Graphics make the game! 8-)
Quote:Original post by NexusOne
One simple solution: don't use .Width and .Height in the for loop condition. These actually are incredibly slow. Just make width and height ints first, and use those in the condition.


Thanks for your reply, I assume you are talking about my first solution.
Yes, I see what you mean now; there I was assuming that they would inline to a simple memory fetch and it's actually an interop to GDI+!
public int get_Width(){      int num1;      int num2 = SafeNativeMethods.Gdip.GdipGetImageWidth(new HandleRef(this, this.nativeImage), out num1);      if (num2 != 0)      {            throw SafeNativeMethods.Gdip.StatusException(num2);      }      return num1;}

Also, GDI+ interop in each GetPixel and SetPixel, little wonder the capn's DrawImage approach was much faster!

Cheers NexusOne

This topic is closed to new replies.

Advertisement