|
I have .jpeg image with dimension(2000 * 1500), scanned with 200 DPI....When I check pixel color of some (x,y) in Photoshop and retrieve same pixel in GDI+ using bitmap.GetPixel(), I found the difference of 25+ in each color(R,G,B). And When I use some third party Image library (which is wrapper on .NET) gives approximately same color components as Photoshop.
so, Whats up!!!!
Any help regarding this would greatly be appriciated.
Regards.
MaulikCE
Life's a game, full of surprises!!
|
|
|
|
|
You probably have ICC profiles configured in Photoshop. ICC profiles are used to match colors on different devices. With GDI+ (namely, the System.Drawing members in the .NET BCL) you must explicitly state to use ICC profiles. You can do this, for one example, by passing true for the icm parameter of various Bitmap constructor overloads.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
while i just read int this forum abt statement related "using".
Its sumthing like using { graphis g = e.Graphics }
while i want to ask is there any keyword like using for replacing :
try
{
}
catch
{
}
finally
{
}
just like using replaces try{}finally{}
Regards
|
|
|
|
|
Using doesn't replace try/finally. Using ensures that the object you "use" is disposed (ie, IDisposable.Dispose() is called) as soon as the using block is exited. It also ensures that Dispose() is called properly when an exception is thrown that isn't handled within the using block.
Using only works on objects that implement IDisposable, IE:
<br />
using (Font myFont = new Font("Arial", 10.0f))<br />
{<br />
}
In answer to your question though: there is no shorthand syntax for try/catch/finally.
This space for rent!
My Blog
|
|
|
|
|
You might want to look at the IL for code using the using statement. When you compile the using construct is expanded to a try/finally (not a try/catch/finally, though):
using (Graphics g = Graphics.FromImage(img))
g.Clear(Color.White); Becomes
Graphics g = Graphics.FromImage(img);
try
{
g.Clear(Color.White);
}
finally
{
g.Dispose();
} Using ildasm.exe that ships with the .NET Framework SDK is handy for examing build outputs.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Yeah, you're right. I knew that was the case, and I was thinking of adding that to my post before you mentioned it and never got around to it (sidetracked). I got confused when he said it replaces try/finally and didn't mention the Dispose() part of it. Though I guess with a little logical leap I could've worked it out
I've heard a lot of people talk about ildasm, but I've never used it before. Perhaps this is as good a time as any to start.
Thanks Heath.
This space for rent!
My Blog
|
|
|
|
|
You'll need to learn IL, but ildasm.exe is good for that, too. There's also decompilers like .NET Reflector[^] but you won't learn as much as if you know IL.
IMO, it's also more 37337, if you get my drift.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
You generally do not dispose objects you didn't create. This includes the PaintEventArgs.Graphics property. Whether you override OnPaint (best for owner drawing when extending a control, including Form s) or handle the Paint event on another control, the default Control implementation will create a Graphics object from the HDC (handle to a device context, which is what Windows uses to paint to various devices like your monitor, a printer, etc.). When OnPaint returns and any event handlers are finished, the object will be disposed.
You should, for example, dispose a Graphics object when you've created one from a Bitmap or other Image using Graphics.FromImage . You should also dispose the Graphics object returned from Control.CreateGraphics .
If you dispose of the Graphics too early you may find that the control isn't painted properly or that an exception is thrown, most likely from a native AV (access violation) exception being thrown.
So, again, as a general rule don't dispose what you didn't create.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi,
I use ShellExecute to open standard email program und create an email with predefined content and allow user to change it before he send it out. As following, the code compiles, but any email program is opened and no email is created. Why, what may I do?
[DllImport("shell32.dll")]
public static extern IntPtr ShellExecute(...)
private void cmdEmail_Click(object sender, System.EventArgs e){
string sEmail = "mailto:le.nhan@freenet.de?"
+ "subject=Error notification"
+ "&body=%0D%0A%0D%0A%0D%0A" + "Description : ";
ShellExecute((System.IntPtr)0, "open", sEmail, null, null, 1);
}
Thanks
TNL
|
|
|
|
|
Why not just use Process.Start ? You P/Invoked what has already been encapsualted for you.
Simply:
Process.Start("mailto:le.nhan@freenet.de?subject=Error notification"); Many email clients do not support the body parameter, which may be the source of your error.
If you tell us what email program you're using, that may help as well. Not giving us any details is like giving a small chunk of code and simply stating that "it doesn't work". Please be specific.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks,
but it doesn't work too, I don't know why. The errormessage:
An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in system.dll.
I call simply so:
System.Diagnostics.Process.Start("mailto:le.nhan@freenet.de?subject=Error");
I use Outlook 2000
I don't know, which Email program will the users use, therefore I used shellexecute in VB, VC, now I want to use it again.
I saw in this site, there are many email solutions, but I can not decide, which suits my aim, simply send a text to a receiver, the user can change the text, but he don't need to login...
Thanks
TNL
|
|
|
|
|
Process.Start uses ShellExecute . If you use an IL disassembler like ildasm.exe or a decompiler like .NET Reflector[^] you can see that. Of course, the ProcessStartInfo.UseShellExecute property should be a pretty good indication, too.
This does work and many, many people use it. Something else with your setup is wrong. What were the details of the Win32Exception ? Just telling me the exception type doesn't typically help much, especially for the Win32Exception . I need to know the error code and any exception text that was returned to you. Only then do you have some chance of figuring out what is wrong.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
is there a class made for dealing with bit stuff like setting bits removing bits and pre defined bit values?
|
|
|
|
|
Read about the BitVector32 structure in the .NET Framework SDK. You can also use the BitArray , but the former structure is more efficient.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I created a Windows Form. The form contains a button called "Line". When I click the button I want a line do be drawn on the Form. I also want the button to disappear.
While I appreciate any help/advice things like "just call DrawLine" or "create a Graphics object" are beyond obvious as general concepts. I would like specifics or even the code fragment.
thanks very much-
|
|
|
|
|
Hi
Here's the code you'll need. If comments aren't enough, just reply:
bool bPaintLine = false;
Pen p = new Pen(Color.Blue);
private void btnLine_Click(object sender, System.EventArgs e)
{
bPaintLine = true;
this.Invalidate();
btnLine.Visible = false;
}
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
if(bPaintLine)
{
using(Graphics g = e.Graphics)
{
Point pStart = new Point(10,10);
Point pEnd = new Point(500,500);
g.DrawLine(p,pStart,pEnd);
}
}
}
Cheers,
Simon
sig :: "Don't try to be like Jackie. There is only one Jackie.... Study computers instead.", Jackie Chan on career choices.
article :: animation mechanics in SVG blog:: brokenkeyboards "Most of us are programmers, but a few use VB", Christian Graus
|
|
|
|
|
SimonS wrote:
using(Graphics g = e.Graphics)
That's bad. Do NOT dispose the Graphics given to you in the PaintEventArgs . It will do this itself and may require the HDC that's attacked to it that you've disposed. The OnPaint event handler that fires the Paint event may need it before, after, or both in relation to when the event is fired.
Besides, when extending a class in which you want to paint it is far more efficient to override the event handler instead of handling the event in the very same class. For example:
public class Form1 : Form
{
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
}
} This requires less overhead and gives you more control. There may be times - like when overriding WndProc - that you don't want to call the base implementation. So don't. With an event you can't do that. With events you also can't control when the base implementation is called, while you can with an override.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Simon,
Thanks very much for you help. If you have a second I have two questions:
1. Why is "this" in "this.Invalidate();" the Form and not the button?
2. I've never seen the "using(Graphics g = e.Graphics)" syntax. Don't you have to create a new Graphics(); ?
thanks again...
|
|
|
|
|
1. Because the line is being painted on the form, not the button. Invalidate invalidates a region of a window (controls are windows, too, BTW) and the next time a paint message (WM_PAINT ) is sent to the window the line is painted.
2. using compiles to the following:
Graphics g = e.Graphics;
try
{
}
finally
{
g.Dispose();
} The using block is documented in the C# Language specification.
As I said in my reply, though, do not dispose the Graphics object. You only dispose Graphics objects (and pretty much anything else, for that matter) that you create. Since your code did not create the Graphics object via Control.CreateGraphics , Graphics.FromImage , or several other methods you should not dispose it yourself. The default implementation will dispose of the Graphics it created (which is actually from Graphics.FromHdc internally) when the OnPaint method (and any event handlers attached to the Paint event) return.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
To rephrase Heath's response in more plain english:
1.
I'm basically telling the form that something has changed and it needs to redraw itself. In a way, it is like calling the Paint event.
2.
As per Heath's quick response, it is exactly the same as writing: Graphics g = e.Graphics;
Except that you are automatically handling the disposing of the object yourself. Whether this is correct or not is, in my opinion, secondary to getting the code written, by hey, it's new year's and I've had a bit to drink... Thanks for point ing that out, H.
Cheers,
Simon
sig :: "Don't try to be like Jackie. There is only one Jackie.... Study computers instead.", Jackie Chan on career choices.
article :: animation mechanics in SVG blog:: brokenkeyboards "Most of us are programmers, but a few use VB", Christian Graus
|
|
|
|
|
Before you say it's just your opinion, you may want to look at the IL for the Control.WndProc and Control.OnPaint methods. If you have experience with GDI the reason is obvious: the Graphics is the HDC for the control to paint in, and if you dispose of it before it is used again the control will not be painted right and - depending on the implementation - may cause an AV (access violation) exception.
As a general rule of thumb you only dispose what you've created.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks for all the help... here's what I have so far...
/////////
bool bPaintLine = false;
Pen p = new Pen(Color.Plum);
private void btnGraph_Click(object sender, System.EventArgs e)
{
bPaintLine = true;
this.Invalidate();
btnGraph.Visible = false;
}
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
if(bPaintLine)
{
Point pt1 = new Point(10, 0);
Point pt2 = new Point(10, 400);
for(int i = pt1.X; i <= 40;)
{
Graphics g = e.Graphics;
g.DrawLine(p, pt1, pt2);
pt1.X += 10;
pt2.X += 10;
}
}
}
PROBLEM: It draws the lines and indeed the button disappears - but then it hangs up and crashes if I try to close the Form.....
|
|
|
|
|
What are you trying to do?
It looks like you have an infinite loop, if we assume that you really didn't indend to end your for statement with a -- Nevertheless it looks like you intended this:
for(int i = pt1.X; i <= 40; )
{
...
}
Which doesn't seem to make any sense. Since i is never changed, it is an infinite loop.
Are you trying to draw one line or several lines? If several, you might want to change to a scheme where instead of using a boolean (bPaintLine), you maintain a collection of lines to draw. Whenever you want to draw a line, you add it to the collection. Your OnPaint() draws whatever lines are in the collection.
By the way, it is probably a CP bug that it interprets emoticons inside preformatted blocks.
Matt Gerrans
|
|
|
|
|
hi all here and happy new year
i have bringing out thes problim yesterday in vb.net thread but i don't have any suggestion
i wish if any body here could help me the problem was published as :
i have urgent problem i don't know what i must do to solve it
the project that i work on consist of server and client application
it represent real Time system
and have three connections
on the client sied the problem is that:
i have found that the CPU usage is 100% this isn't the usaual case of the client
first :when i watch the threads from control panal-->performance i found that one thread go up
and take most resource
i don't know how to catch this thread
second :i note that if i put any break point to stop the applecation then let it run again
the CPU usage go down to a good level
Aswanee
|
|
|
|
|
|