3
Reply

SplashScreen

Faruk

Faruk

Feb 19 2010 7:24 AM
4.9k

Hello Friends,
I've started working on a game, and I'm a newbie programmer, that means I'm still learning lots of new things. That's right, I've started working on my first game, but I'm just stuck at the beginning. :S
I want to create splash screen in full screen. I've found some written codes about how to create image opacity on the net and modified them as my needs.

public static void SetImgOpacity(Image imgPic, float imgOpac, PictureBox PictureBox_Hd)
{
Bitmap bmpPic = new Bitmap(imgPic.Width, imgPic.Height);
Graphics gfxPic = Graphics.FromImage(bmpPic);
ColorMatrix cmxPic = new ColorMatrix();
cmxPic.Matrix33 = imgOpac;
ImageAttributes iaPic = new ImageAttributes();
iaPic.SetColorMatrix(cmxPic,
ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
gfxPic.DrawImage(imgPic,
new Rectangle(0, 0, bmpPic.Width, bmpPic.Height), 0, 0, imgPic.Width, imgPic.Height, GraphicsUnit.Pixel, iaPic);
gfxPic.Dispose();
PictureBox_Hd.Image = bmpPic;
bmpPic.Dispose(); ---> This code causes the problem...
}
 
I want to explain a lil' in details about my problem. I set the opacity of the image with a timer, then load the new image into the specified pixturebox. But After I load the new image (bmpPic), i can't dispose it.
without bmpPic.Dispose() code, everything works fine, but when i add that, it always give me an error.  But as you know Dispose() is a must here, otherwise, memory would be full of junks. :)
Error in Details:
//
System.ArgumentException: Parameter is not valid.
   at System.Drawing.Image.get_RawFormat()
   at System.Drawing.Graphics.IgnoreMetafileErrors(Image image, Int32& errorStatus)
   at System.Drawing.Graphics.DrawImage(Image image, Int32 x, Int32 y, Int32 width, Int32 height)
   at System.Drawing.Graphics.DrawImage(Image image, Rectangle rect)
   at System.Windows.Forms.PictureBox.OnPaint(PaintEventArgs pe)
   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
   at System.Windows.Forms.Control.WmPaint(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
//

In addition to this; Dispose method works fine in debug mode.
I don't know what causes this problem. I hope you help me. Thanks in advance.

Answers (3)