|
I'm using the following code to capture a screenshot :
Image myImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics gr1 = Graphics.FromImage(myImage);
IntPtr dc1 = gr1.GetHdc();
IntPtr dc2 = GetDC(GetDesktopWindow());
BitBlt(dc1, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, dc2, 0, 0, 13369376);
gr1.ReleaseHdc(dc1);
GC.Collect();
return myImage;
I'm trying to capture a screenshot of the entire desktop and transferring it to a remote PC (to create a program like PcAnywhere). The thing is, i set my screenshot timer to something like 450 ms and on my machine (Athlon XP 2000+), it uses up around 30% of the CPU power. However, if i test it on my old P3-700 Mhz machine, the CPU utilisation is very high, ranging between 75-90%.
Is there any way to reduce the CPU utilisation (maybe like reducing the color depth of the image? but how)?
|
|
|
|
|
You should be releasing the DC you get with GetDC() , using ReleaseDC() , and if you aren't going to be using gr1 anymore, you should call Dispose() on it.
What's making it slow is probably the transfer, not the capturing. I don't know if this will make it faster, or slower, but you could make a new Bitmap with a lower color depth, create a Graphics from it, and use Graphics.DrawImage() to draw the image onto the new Bitmap .
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
No, that doesn't make much difference. The code is now :
Image myImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics gr1 = Graphics.FromImage(myImage);
IntPtr dc1 = gr1.GetHdc();
IntPtr dc2 = GetDC(GetDesktopWindow());
BitBlt(dc1, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, dc2, 0, 0, 13369376);
gr1.ReleaseHdc(dc1);
ReleaseDC(GetDesktopWindow(), dc2);
GC.Collect();
return myImage;
I fail to mention earlier that i am utilising a savejpgwithcompression function and after some checking, it appears that it is the cause of the problem. It could be the compression part, but it is essential to make the file size smaller. Here's the code :
private void SaveJPGWithCompressionSetting( Image image, string szFileName, long lCompression )
{
EncoderParameters eps = new EncoderParameters(1);
eps.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, lCompression );
ImageCodecInfo ici = GetEncoderInfo("image/jpeg");
image.Save( szFileName, ici, eps );
}
private ImageCodecInfo GetEncoderInfo(string mimeType)
{
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
foreach (ImageCodecInfo codec in codecs)
{
if (codec.MimeType == mimeType){return codec;}
}
return null;
}
|
|
|
|
|
Well your first problem BitBlt is the slowest drawing technique. DirectX has BitBltFast or FastBitBlt which is twice as fast.
If your trying to accomplish fast rasterization your first problem is using the GDI. You should really use directX fucntionsin the framework or even just write c++ blocks in your cde and access the directx directly.
If possible create pages and store the bitmap data within the pages then show them at times needed
check out gamedev.net for a lot of pointers on graphics.
nick
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
OK, so I have my main form 'Form1' and i'm in another class 'controls.cs' ...
How can I change the title of my main form 'Form1' from 'controls.cs' ??
I tired...
Form1 asdf=new Form1;
asdf.text="RESPECT THE ENG";
but that dosn't work. How can I do it?
/\ |_ E X E GG
|
|
|
|
|
adf.Text , not asdf.text .
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
well, actually I have this on controls.cs...
Form1 asdf = new Form1();
asdf.Text="RESPECT THE ENG";
now... the question i guess...
on Form1, how do I call this?
/\ |_ E X E GG
|
|
|
|
|
Form1 isn't an object. It's a class. asdf is an object (instance of a class). You need to change the text on asdf, not on Form1 and you can't do that unless you have a reference to asdf.
You might need to enumerate all the forms until you find the one you want or you could pass a reference of the form to control.cs so that you can manipulate it later.
|
|
|
|
|
try passing the form on the constructor of the control.cs object, and store this in the control object. i.e.
<br />
private Form form1;<br />
<br />
public Control(Form form)<br />
{<br />
this.form1 = form;<br />
}<br />
You should then be able to make calls like form1.Text = "whatever". If that doesn't work quite try public Control(ref Form form).
|
|
|
|
|
Anyway, which ever spelling you prefer is up to you. I just want to know this, how do you convert RGB values to hex values?
|
|
|
|
|
If you are wanting the web format (#RRGGBB), use ColorTranslator.ToHtml. Otherwise, use the Color.R, Color.G, and Color.B properties, and convert them to hex using Int32.ToString("xx").
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
Hi,
I have a MDI application, which has a workspace (a form) and a tool bar window. User can create new forms and place controls from the tool bar onto this forms. They should be able to move controls on this form.
Here is the problem:
To let user move controls around on the form, I handle the MouseDown, MouseMove and MouseUp events for the selected control. In the MouseMove event handler I compute (using the location value saved in Mouse Down event) the new location for the control and set it as the location of the control. This somehow cause more mouse move events on the control - this is because, I think, the assignment of new value to the location property cause the control to move to the new location while it has the mouse pointer on it. This may generate new mouse move events!!!
Any suggestions / solutions to avoid the extra mouse move events would be highly appreciated.
Thanks,
Suhas
|
|
|
|
|
as long as the mouse moves, there will be mousemove events, try keeping track of when a control is being moved, using a boolean variable, and if its not being moved, then dont run all hte code in your MouseMove.
Another Post by NnamdiOnyeyiri l Website
|
|
|
|
|
I am sorry I do not understand your suggestion.
The control does not move on its own, it moves in response to mouse move events.
Even when the mouse has stopped moving the control continues to receive mouse move events because the control itself is moving in response to the previous mouse move events. I suspect that this extra mouse move events are generated because the control the has mouse pointer on it when it is moving.
The pseudo code is:
MyMouseMoveHandler()
{
// Compute the move distance
// Move the control - this itself it generating more mouse move events
// even though the mouse has stopped moving.
}
Thanks,
Suhas
|
|
|
|
|
try setting handled to true and that might stop the flow of events
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
1. When you click a row on the far left, it highlights the entire row.
is there a way to do this with a DataGrid method?
2. I would also like to tab down rows instead of across cells. I see where you can capture the tab change, but i don't know how to focus on a row ( relating to my first question )
any insight would be much appreciated. c# is great!
|
|
|
|
|
this.dataGrid1.Select(this.dataGrid1.CurrentRowIndex);
i thought i knew how to capture the tab change, but it doesn't work as expected.
is there a way to capture tab within the data grid? then i can use the code above to focus on the next row down.
|
|
|
|
|
sink the keydown event then use your above code
protected override bool ProcessKeyPreview( ref System.Windows.Forms.Message m)
{
Keys keyCode = (Keys)(int)m.WParam & Keys.KeyCode;
if((m.Msg == WM_KEYDOWN || m.Msg == WM_KEYUP) && keyCode == Keys.Tab)
{
dg1.Select(dg1.CurrentRowIndex++);
MessageBox.Show("Hey");
return true;
}
else
return true;
}
theres the code to override the key event but the problem is for checkbox columns it will work.
But for other columns YOU MUST extend the DataGridTextBoxColumn class and provide your own event handling inside.
CHeck this link:
Dude the everything I ever wanted to know about DatraGrids
nick
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
the first should return false sorry.
But I would inherit the grid and extend the OnCurrentCellChange method ( I think thats the name, but its real close.) in that create a delegate and raise an event cell change or inside force a new row instead of a new column.
thats would be easier or create your own extended columns thier both fast an easy.
nick
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
I want to return my defined class from my XML Services. In the test page there is no probem and it display page correctly,but in my windows appplication there is problem. When in my windows application I want to return my class from my xmlservice function I got compiler error:
Can not imlpictly convert from localhost.webservicenamespace.myclassname to Myclassnamespace.myclassname
So I change it to localhost.webservicenamespace.myclassname but now here I get null object. Should I do anything special for getting custom types from XML web services? Any idea?
Mazy
No sig. available now.
|
|
|
|
|
|
Hi Nish:
The problem was that I have to connect to internet when I want to use my web service,but it works on ASP.NET without connecting to internet.
I want to post this last night but it might it was a problemm with CP database.Any way,thanks.
Mazy
No sig. available now.
|
|
|
|
|
has anyone programmed a bot for MSN using c#?
im trying to make one myself. so i need to check out some samples.
im also new to c# programming but i'll get along well.
i found dotMSN library. but the sample that came along didnt compile. so i need to see some others before i get going on my own.
can anyone help ?
|
|
|
|
|
I have a method (name=HelloCSharp.Rand(), see below "QUESTION HERE") that's uses "uint" as parameter and return type - therefore not CLS-complaint and I was expecting a compiler error. Problem is, there was NOT a compiler error (or error of any kind)... THanks.
namespace SomenameSpace
{
using System;
public class NukeIt
{
public NukeIt(){ }
//NO PROBLEM HERE: This method NOT CLS-compliant and generated a compiler warning as expected.
public uint Rand(uint nSeed) {return nSeed;}
}
class HelloCSharp : HelloVB
{
public HelloCSharp()
{
}
public override void Hello()
{
base.Hello();
Console.WriteLine("Hello, C#");
}
public new int Add(int val1, int val2)
{
return val1+val2;
}
//QUESTION HERE: "uint" is NOT CLS-compliant and should generate a compiler warning, but, it did NOT??
public uint Rand(uint nSeed)
{
return nSeed;
}
[STAThread]
static void Main(string[] args)
{
HelloCSharp hello = new HelloCSharp();
hello.Hello();
}
}
}
Thanks!
norm
|
|
|
|
|