|
michael@cohen wrote: b = new Bitmap(width, height);
i = Image.FromHbitmap(b.GetHbitmap());
g = Graphics.FromImage(i);
How utterly bizarre. This is a waste of time. You can call Graphics.FromImage on a Bitmap, in fact, because of bugs in .NET, even if you create an Image, a Bitmap is created.
You should use using blocks to auto dispose where you can.
If you want images to be smaller, try saving them as jpeg or another compressed format. Otherwise, they are the size of the number of pixels x 3, you can't change that.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Hi,
your code could be simplified to a single constructor, see new Bitmap(Image, Size) , however that would lead to the same result.
As Christian said, the smallest file will be obtained by saving it in a format that applies compression, so use JPEG for it.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
I have installed the SNMP in my machine and the printer Server.
The printer Server is a PC,its OS is WinXP.
The PC is in another subnet to my Loacal PC.
Now i can obtain the Printer's name and the other infomation by SNMP.
But i want to obtain the total printing pages.
Can i use MIB to do it? Any help will be appreciated!
modified on Monday, September 21, 2009 4:46 AM
|
|
|
|
|
Hi,
Please help me on the thread scheduling problem described below.
The method Play() plays a sound file using WMPLib and
the method DoSomething() does some kind of time consuming tasks (just for testing).
I wonder why the two cases below showed me different results in spite of using thread for asynchronous processing.
It's been killing me...
public void Play()
{
player.controls.stop();
player.currentMedia = player.newMedia(path);
player.controls.play();
}
public void DoSomething()
{
int z = 1;
for(int i=0; i<1000000; i++) {
z = i + 1000;
z = z - 1000;
string str = "Test String";
str = str + " What's up?";
}
MessageBox.Show("Something done");
}
private void button1_Click(object sender, EventArgs e)
{
Play();
ThreadPool.QueueUserWorkItem(new WaitCallback(DoSomething));
}
private void button2_Click(object sender, EventArgs e)
{
ThreadPool.QueueUserWorkItem(new WaitCallback(Play));
DoSomething();
}
Thanks in advance.
Roh
modified on Monday, September 21, 2009 10:37 PM
|
|
|
|
|
Kwonhyung Roh wrote: showed me different results
And those would be ....??
You've got one major problem that I see. You're launching a MsgBox and touching UI controls from a non-UI thread. Both are not good ideas and can give you screwy results.
|
|
|
|
|
Thanks.
In case1, it starts playing the sound file and, at the same time, starts DoSomething. And while the sound file is being played, the MessageBox shows up which means end of DoSomething. (Asynchronous)
But in case2, DoSomething starts first. After showing up the MessageBox, it starts playing the sound file. (Synchronous)
I used the MessageBox just to mark the end of DoSomething.
And codes for the method Play() were originally parts of the event handler.
(But it made no difference.)
I rewrote them as the method for convenience' sake.
Thanks again.
Roh
|
|
|
|
|
Like I said, touching a UI control (MessageBox, and the WMP) from anything other than the thread your app started on, will yield very weird results. You cannot call the Play method directly from the background worker thread. You cannot directly touch any UI control from a different thread than it was created on.
Kwonhyung Roh wrote: I rewrote them as the method for convenience' sake
You can Invoke the Play method from the background thread, which tells the thread that Form1 is on to execute the code. Something like:
Private Delegate Sub PlayDelegate()
.
.
.
' This would be inside the BackgroundWorker target.
Form1.Invoke(New PlayDelegate(AddressOf Play))
|
|
|
|
|
Thanks.
With your help, I can go back to my original problem.
Please refer to the code snippet below.
private void button2_Click(object sender, EventArgs e)
{
filename = listBox1.SelectedItem.ToString();
path = directory + "\\" + filename;
player.controls.stop();
player.currentMedia = player.newMedia(path);
player.controls.play();
int z = 1;
for(int i=0; i<1000000; i++) {
z = i + 1000;
z = z - 1000;
string str = "Test String";
str = str + " What's up?";
}
MessageBox.Show("Iteration Ends");
}
This code snippet is processed in the order
1. Do for-block first (for about 4 seconds)
2. Show MessageBox
3. And then play sound.
But what I expected and wanted is the order
1. Play sound/Do for-block at the same time
2. Show MessageBox while the sound is being played
If I put another MessageBox just before the for block like
MessageBox.Show("Now Starting...");
int z = 1;
for(int i=0; i<1000000; i++) {
}
MessageBox.Show("Iteration Ends");
The result order (of processing) is
1. Play sound/Show the first MessageBox at the same time (maybe not exactly the same time but I felt it was )
2. Do for-block (for about 4 seconds)
3. Show the second MessageBox while the sound is being played
I wanted to know where all of these differences come from.
Thanks.
|
|
|
|
|
First, 1000000 iterations will not take 4 seconds to complete. It'll complete in the blink of an eye.
Next, since you start playing the audio and then immediately block the thread with the loop, the player can't start playing the audio. The player has to do this on the UI thread, so as long as you've got the UI thread blocked doing other thing, the audio won't play. You have to move the loop code to a seperate thread.
|
|
|
|
|
Dave, I really appreciate your help.
You guide me to understand the big picture.
Thanks.
|
|
|
|
|
Hi forum...
Im trying to use the TaoFramework libraries in c# but I always get this error
Unable to load the DLL file 'freeglut.dll'. (Excepción de HRESULT: 0x8007007E)
when i call the function at this line
Glut.glutInit();
I have this code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using Tao.FreeGlut;
using Tao.OpenGl;
...
class program
{
static int alto = 512;
static int ancho = 512;
static double imgalfaspect;
static int alto_original = alto;
static void Main(string[] args)
{
Glut.glutInit();
Glut.glutInitWindowSize(ancho, alto);
Glut.glutInitDisplayMode(Glut.GLUT_RGBA | Glut.GLUT_DOUBLE);
Glut.glutCreateWindow("test opengl");
Glut.glutDisplayFunc(display);
Glut.glutReshapeFunc(resize);%
imgalfaspect = ((double)ancho / (double)alto) * 0.5;
Glut.glutMainLoop();
}
...
}
I have added the references to my project, but i don't know what to do to fix this problem.
Thanks in advance
|
|
|
|
|
You are far more likely to get an answer from their site, than here!
taoFramework.com[^].
Is Google not working where you are?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hello Henry
Thanks for your answer...
Where i am, my google web site is working... I have been looking a lot in google, but i have could not find an answer for this.
for this reason i am here writing, because maybe you have a response for this.
thanks again
|
|
|
|
|
billy_iii wrote: for this reason i am here writing, because maybe you have a response for this.
Henry gave you the best reponse anyone is going to come up with. Ask the people who wrote the library you're having problems with.
|
|
|
|
|
Have you got the answer already?
You may create a WinForm aplication project,and try it again.
|
|
|
|
|
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics gfx = e.Graphics;
gfx.DrawString("135", new Font("Freestyle Script",
40f, FontStyle.Bold),
new SolidBrush(Color.Red),
new Point(20,20));
How would you know when the mouse cursor is inside a rectangle area of the above drawn text??
|
|
|
|
|
well.. You need to trap mousemove to get the cursor position.
check value of EventArgs that comes along with the Event Delegate.
|
|
|
|
|
Hi,
there is a sibbling method called MeasureString, when used correctly it provides information about the size a DrawString is going to take. However there are minor deviations, there even is a CP article on that subject.
I expect most text processors (when using a proportional font) would draw only one word at a time, and store all the coordinates; so you would need MeasureString only inside a word, and visual feedback with a caret sufficiently solves inaccuracies.
BTW: the few lines of code you have shown are horrible for performance and memory, as they create new objects (Font, Brush) for every Paint, and don't Dispose of them.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Thanks Luc, Actually I know about the measureString thing but wanted to hear your opinions.. And don't worry, I just posted the shortest segment I can to show my problem
|
|
|
|
|
Luc Pattyn wrote: there is a sibbling method called MeasureString, when used correctly it provides information about the size a DrawString is going to take. However there are minor deviations, there even is a CP article on that subject.
I expect most text processors (when using a proportional font) would draw only one word at a time, and store all the coordinates; so you would need MeasureString only inside a word, and visual feedback with a caret sufficiently solves inaccuracies.
The inaccuracies with MeasureString make it unusable for text processors. When selecting text, you need to be able to draw text in two parts (because the selected part has a different color) at exactly the same position (other text will start to 'jump around' if you select stuff). AFAIK this isn't possible with MeasureString+DrawString - it might work for some fonts (mostly the mono-spaced ones), but the inaccuracies will cause trouble for other fonts.
Use the Measure+Draw methods from the System.Windows.Forms.TextRenderer class instead - those work much better. You might have to specify some TextFormatFlags to keep the TextRenderer from adding padding.
|
|
|
|
|
Hi Daniel,
thanks for the info. I'll have to experiment with it some day, I've never used TextRenderer so far.
Cheers.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Hi,
I am using unmanaged Dll in a managed C# project, where callbacks are made from the unmanaged code to the managed code.
My project compiles fine, when I run the application (in debug mode), which is basically a client that communicates with a server application, intermittently I get a NullReferenceException dialog box. But my problem is it does not point to a specific line of code where this exception is occurring. The dialog just shows in the middle of the IDE (VS 2008) and I have to stop the application.
Does anyone know how can I verify where this exception is occurring???
Appreciate your suggestions.
|
|
|
|
|
This happens sometimes when error is happening to an external dll. Say you have added a dll called a.dll which doesnt have the pdb associated with it or no Debug Symbols for that dll is loaded into memory... Thus .NET cant show you the actual source, and hence shows this error.
You can see the assembly code.. but if you dont know it, it wouldnt be meaningful to you.
What you can do is always add the dll from bin folder of your project. This ensures that the dll is loaded with debug symbols.
|
|
|
|
|
I have added the dll from bin folder of the project.
modified on Sunday, September 20, 2009 4:43 PM
|
|
|
|
|
I mean I have been doing that already before I posted this question, It did not help.
|
|
|
|