Click here to Skip to main content
15,894,460 members
Home / Discussions / C#
   

C#

 
GeneralRe: detect if application is opened on start-up or via user? Pin
teejayem10-Aug-08 14:53
teejayem10-Aug-08 14:53 
GeneralRe: detect if application is opened on start-up or via user? Pin
DragenGimp16-Aug-08 5:50
DragenGimp16-Aug-08 5:50 
QuestionWEIRD problem with CPU 40%-50% in an application. Pin
Green Fuze10-Aug-08 5:23
Green Fuze10-Aug-08 5:23 
QuestionDynamic Instantiation of Classes. Pin
dudedotnet10-Aug-08 5:06
dudedotnet10-Aug-08 5:06 
AnswerRe: Dynamic Instantiation of Classes. Pin
User 665810-Aug-08 5:13
User 665810-Aug-08 5:13 
AnswerRe: Dynamic Instantiation of Classes. Pin
Guffa10-Aug-08 6:35
Guffa10-Aug-08 6:35 
AnswerRe: Dynamic Instantiation of Classes. Pin
PIEBALDconsult10-Aug-08 7:03
mvePIEBALDconsult10-Aug-08 7:03 
QuestionGraphics.DrawImage Problem Pin
#realJSOP10-Aug-08 4:57
mve#realJSOP10-Aug-08 4:57 
Using VS2008, in a Windows.Form application...

I'm trying to fade an image onto the screen. I first load the image I want use, and then create another image that is nothing more than the same color as the form background. To fade on/off the image, I fade on the actual image, and then fade on the plain background image. Given the following code...

float m_alphaStep = 0.100000000f;
int m_X = 0;
int m_Y = 0;

public void Fade(Bitmap bitmap)
{
	float width = (float)m_bitmap.Width;
	float height = (float)m_bitmap.Height;
	Rectangle destRect = new Rectangle(0, 0, m_bitmap.Width, m_bitmap.Height);
	float alpha = 0.000000000f;

	try
	{
		for (alpha = 0.000000000f; alpha < 1.000000000f; alpha += m_alphaStep)
		{
			m_colorMatrix[3, 3] = alpha;
			m_attributes.SetColorMatrix(m_colorMatrix);
			m_graphics.DrawImage(bitmap, 
			                     destRect, 
			                    (float)m_X,
			                    (float)m_Y, 
			                    width, 
			                    height, 
			                    GraphicsUnit.Pixel, 
			                    m_attributes);

			// this line doesn't work despite intellisense saying it's a valid overload
			//m_graphics.DrawImage(bitmap, 
			//                     new Point(m_X, m_Y), 
			//                     destRect, 
			//                     GraphicsUnit.Pixel, 
			//                     m_attributes);

		}
		m_colorMatrix[3, 3] = 1.0f;
		m_attributes.SetColorMatrix(m_colorMatrix);
		m_graphics.DrawImage(bitmap, 
		                     destRect, 
		                     (float)m_X, 
		                     (float)m_Y, 
		                     width, 
		                     height, 
		                     GraphicsUnit.Pixel, 
		                     m_attributes);

		// this line doesn't work despite intellisense saying it's a valid overload
		//m_graphics.DrawImage(bitmap, 
		//                     new Point(m_X, m_Y), 
		//                     destRect, 
		//                     GraphicsUnit.Pixel, 
		//                     m_attributes);

	}
	catch (Exception ex)
	{
		if (ex != null) { }
	}
}

public void PaintItem()
{
	Fade(m_bitmap);
	Thread.Sleep(1000);
	Fade(m_offBitmap);
}


Problems:

0) The indicated call to m_graphics.DrawImage() won't compile, despite my using what intellisense claims is a valid overload.

1) The for loop determines the new alpha channel value. The nature of float values causes the alpha value to eventually become some bizarre value (usually by the 7th iteration), which forces me to only do the loop while it's less than 1.0, and then perform the final DrawImage() call after the loop has exited.

2) Performance quite frankly sucks. I can see the image redraw itself from top to bottom. Is there a better (more efficient) way to fade an image on/off the screen?

3) Immediately upon starting the application, I begin displaying the image. If I turn on double-buffering for the form, the form doesn't get displayed until the Fade() routine completes. If I don't turn on double buffering, it works as expected.


"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001


AnswerRe: Graphics.DrawImage Problem Pin
Guffa10-Aug-08 5:21
Guffa10-Aug-08 5:21 
GeneralRe: Graphics.DrawImage Problem Pin
#realJSOP10-Aug-08 5:39
mve#realJSOP10-Aug-08 5:39 
GeneralRe: Graphics.DrawImage Problem Pin
Guffa10-Aug-08 6:37
Guffa10-Aug-08 6:37 
GeneralRe: Graphics.DrawImage Problem Pin
#realJSOP10-Aug-08 23:25
mve#realJSOP10-Aug-08 23:25 
AnswerRe: Graphics.DrawImage Problem Pin
User 665810-Aug-08 5:46
User 665810-Aug-08 5:46 
GeneralRe: Graphics.DrawImage Problem Pin
#realJSOP10-Aug-08 23:29
mve#realJSOP10-Aug-08 23:29 
QuestionThe assembly 'mscorlib.XmlSerializers' failed to load in the 'LoadFrom' Pin
ezazazel10-Aug-08 4:27
ezazazel10-Aug-08 4:27 
QuestionRe: The assembly 'mscorlib.XmlSerializers' failed to load in the 'LoadFrom' Pin
Mark Salsbery10-Aug-08 9:02
Mark Salsbery10-Aug-08 9:02 
AnswerRe: The assembly 'mscorlib.XmlSerializers' failed to load in the 'LoadFrom' Pin
ezazazel10-Aug-08 9:39
ezazazel10-Aug-08 9:39 
QuestionUpdating textbox from class running in another thread Pin
__Leeloo__10-Aug-08 2:51
__Leeloo__10-Aug-08 2:51 
AnswerRe: Updating textbox from class running in another thread Pin
Green Fuze10-Aug-08 5:11
Green Fuze10-Aug-08 5:11 
GeneralRe: Updating textbox from class running in another thread Pin
PIEBALDconsult10-Aug-08 7:18
mvePIEBALDconsult10-Aug-08 7:18 
QuestionHow to Intract with Reporting Services by code ? Pin
hdv21210-Aug-08 0:43
hdv21210-Aug-08 0:43 
AnswerRe: How to Intract with Reporting Services by code ? Pin
Wendelius10-Aug-08 1:01
mentorWendelius10-Aug-08 1:01 
GeneralRe: How to Intract with Reporting Services by code ? Pin
hdv21210-Aug-08 1:06
hdv21210-Aug-08 1:06 
GeneralRe: How to Intract with Reporting Services by code ? Pin
Wendelius10-Aug-08 1:19
mentorWendelius10-Aug-08 1:19 
GeneralRe: How to Intract with Reporting Services by code ? Pin
hdv21210-Aug-08 1:49
hdv21210-Aug-08 1:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.