|
Hi there,
thanks a ton. Seems to be just the perfect code. Unfortunately do I not understand even a tiny bit of what is happening there (never ever done GDI programming, ever!). Do you have an idea on how to convert it back into an Image object? I somewhat required an Image as in- as well as output.
Sure, I could look it all up and learn the ropes... But sorry, I'm probably never ever doing GDI again, so please understand that I'm just out for a solution.
Anyway, thanks again!
/matthias
I love deadlines. I like the whooshing sound they make as they fly by. [Douglas Adams]
|
|
|
|
|
So no need to convert. (Check the help or RTFM)
In memory graphics operations are performed on uncompressed bitmaps (always?)
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
How's this?
private void Form1_Load(object sender, System.EventArgs e)<br />
{<br />
OpenFileDialog dlg = new OpenFileDialog();<br />
dlg.Filter="Image files (*.BMP, *.JPG, *.GIF)|*.bmp;*.jpg;*.gif";<br />
if(dlg.ShowDialog()==DialogResult.OK)<br />
{<br />
Image colourImage = Image.FromFile(dlg.FileName);<br />
Image greyscaleImage = GreyscaleImage(colourImage);<br />
<br />
<br />
colourImage.Dispose();<br />
greyscaleImage.Dispose();<br />
}<br />
}<br />
<br />
private Image GreyscaleImage(Image img)<br />
{<br />
Bitmap bm = new Bitmap(img.Width, img.Height);<br />
Graphics g = Graphics.FromImage(bm);<br />
<br />
ColorMatrix cm = new ColorMatrix(new float[][]{ new float[]{0.5f,0.5f,0.5f,0,0},<br />
new float[]{0.5f,0.5f,0.5f,0,0},<br />
new float[]{0.5f,0.5f,0.5f,0,0},<br />
new float[]{0,0,0,1,0,0},<br />
new float[]{0,0,0,0,1,0},<br />
new float[]{0,0,0,0,0,1}});<br />
<br />
ImageAttributes ia = new ImageAttributes();<br />
ia.SetColorMatrix(cm);<br />
g.DrawImage(img,new Rectangle(0,0,img.Width,img.Height),0,0,img.Width,img.Height,GraphicsUnit.Pixel,ia);<br />
g.Dispose();<br />
<br />
return (Image)bm;<br />
}
|
|
|
|
|
Yesssss, thanks. You made my day...
/matthias
I love deadlines. I like the whooshing sound they make as they fly by. [Douglas Adams]
|
|
|
|
|
But if you don't downsize the image or downgrade it in memory you will occupy the exact same resources. I believe all of the .NET and GDI+ render operations are 32bit (even on low bit images). Shrink the size of the bitmap for the display and you will get the desired resource reduction without all of the code.
BTW, image processing ops in GDI+ seem to be a lot slower the display processing from my rather limited testing.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
Hi,
Thanks in advance. I have an application which loads the database tables with five different site codes. In future the number of site codes may increase. For each site code 14 files are sent from another server to our server.
I have to write an application which checks for all the files to arrive and converts it into UTF-8 format and then calls the PL/SQL package and this should run parallely.
So I thought of using Multithreading with one thread for each of the site codes with site code as parameter.
Here is the problem I face. For instance, I have a flag which would be set to "No" if the files are missing and "Yes" if the files exist. In multithreading if I have to preserve the variable I have to block the variable from the other threads using it. Suppose for the site code where files arrival get delayed for 5-6 hrs or for some reason and it's thread blocks the variable then the other threads has to wait for this and this is not what I want. And I have set a lot many flags for in this application. Is Multithreading useful in this scenario? Please let me know your suggestions.
Thanks & Regards,
Das.
|
|
|
|
|
Often the primary difficulty in multi-threaded apps is the logical layout. If you have many threads performing the same operation on disperate data sets you should not have one variable shared between them that controls them all. Using good OO techniques you can have one no flag across many different instances.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
Hi community!
Ich have a litte problem. I have a string 'str = textBox12'. An now I want to read this textBox like
int a = ConvertToInt16(textBox12.Text);
But this code:
int a = ConvertToInt16(str.Text);
doesn´t work. Sure, but how can I solve this problem? I have no basic approaches, so I bank on you
Thank you very much!
-- modified at 8:02 Thursday 20th July, 2006
|
|
|
|
|
Use this:
int a = Int16.Parse(textbox.Text);
|
|
|
|
|
|
|
Ok, I think I´ve explained it wrong. (Please correct me if I make mistakes with my englisch).
I have a string called 'str'. In this string is one part of a Command. str = "textBox12".
Now, I must read the textBox12. Str says to me, which textBox I must read. In this textBox12 is an integer=12 (for example)
So I want a command like:
int a = ConvertToInt16(str.Text)
str.Text stands for textBox12.Text
I hope I´ve explained it better.
|
|
|
|
|
Ah.- Iterate through the form's
Controls collection to get at the named control.
- Use Int16.TryParse() to convert the
.Text property of that control to an integer. /ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
This is what I had in mind. But I thouhgt there is a simpler way. But ok, I will try it.
|
|
|
|
|
How I can iterate through the forms collection?
|
|
|
|
|
|
so simple? I will work on it and try to solve my Problem.
I'am very pleased how fast the members answer!
|
|
|
|
|
ok, it doesn´t work. I´ve got the error, that I need an object reference for form1.controls.
Can you explain it with other words please?
|
|
|
|
|
string lookForControl = "textBox12";
string foundControlText = "";
foreach(Control ctrl in this.Controls)
{
if(ctrl.Name == lookForControl)
{
foundControlText = ctrl.Text;
}
}
MessageBox.Show("Control " + lookForControl + " has the Text: " + foundControlText);
---
How to get answers to your questions[^]
-- modified at 9:48 Thursday 20th July, 2006
|
|
|
|
|
That code won't work if the target control is in the Controls collection of a container, such as a GroupBox or Panel. You should make a recursive method which iterates ControlCollections searching for a control with the specified name.
An easier way to do this would be to use reflection to get the control by it's name, assuming that the control is not created dynamically. For example:
FieldInfo fi = this.GetType().GetField( "textBoxInfinity", BindingFlags.Instance | BindingFlags.NonPublic );
TextBox txt = fi.GetValue( this ) as TextBox;
txt.Text = "HELLO";
:josh:
My WPF Blog[^]
|
|
|
|
|
You´re right. I noticed it, because my textBoxes were in GroupBoxes .
Reflections...aha....I must read about it, I didn´t heared about reflections. (is this right -> grammar?)
Thanks to you both!
|
|
|
|
|
Schimaera wrote: I didn´t heared about reflections. (is this right -> grammar?)
No, it would be better to say "I had not heard of reflection."
:josh:
My WPF Blog[^]
|
|
|
|
|
|
Totally agree Josh, but as the OP seemed confused already I thought starting simple was the best way to go.
Had the poster come back and said "It does not work because textbox12 is inside a panel", then I would have delved into the obvious recursive method!
---
How to get answers to your questions[^]
|
|
|
|
|
very thoughtful
|
|
|
|