Im a newbie and Im trying to do something that I know is simple.
Im using a picturebox to display a tif image and the following line loads the image I want displayed (I know Im using the wrong terminology when I say "load").
pictureBox1.Image = Image.FromFile(ImageName);
The image is there and Ive stretched it using
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
So far so good, but the image doesnt look too good. I want to use antialiasing and maybe pixel offsets to clean it up a little and this is where I run into trouble. Im not sure how to use these properties or call methods from another class.
Im not sure if I should even be using OnPaint or something else.
I tried overriding the OnPaint method like below and added a MessageBox statement there to see when it fires and it only seems to fire when the program begins to run, not later after Ive instantiated a picturebox object and told it which image I want displayed. How do I use the following, or whichever method is correct, so that it does the antialiasing and renders this in the picturebox? I know this cant be too hard. Im hoping its not.
protected override void OnPaint(PaintEventArgs pea)
{
Graphics grfx = pea.Graphics;
Pen pen = new Pen(ForeColor);
grfx.SmoothingMode = SmoothingMode.HighQuality;
grfx.PixelOffsetMode = PixelOffsetMode.HighQuality;
}
Last night, after getting ready to post this, I tried one more thing, thinking that I can figure this out myself.
Graphics grfx = Graphics.FromImage(pictureBox1.Image);
grfx.SmoothingMode = SmoothingMode.HighQuality;
grfx.PixelOffsetMode = PixelOffsetMode.HighQuality;
grfx.TextRenderingHint = TextRenderingHint.AntiAlias;
For the TIFF image I was trying to view I got the following exception:
"A graphics object cannot be created from an image that has an indexed pixel format".
When viewing a JPG I didnt get the error message, but the image looked no different with the graphics properties set. Now I have two problems; not only do I not know how to set these options so that the image is viewed in the picturebox using the graphics properties, but even if I can figure it out it doesnt seem to work with TIFF images and thats all Im using.
Thanks in advance,
Jeff
Im using a picturebox to display a tif image and the following line loads the image I want displayed (I know Im using the wrong terminology when I say "load").
pictureBox1.Image = Image.FromFile(ImageName);
The image is there and Ive stretched it using
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
So far so good, but the image doesnt look too good. I want to use antialiasing and maybe pixel offsets to clean it up a little and this is where I run into trouble. Im not sure how to use these properties or call methods from another class.
Im not sure if I should even be using OnPaint or something else.
I tried overriding the OnPaint method like below and added a MessageBox statement there to see when it fires and it only seems to fire when the program begins to run, not later after Ive instantiated a picturebox object and told it which image I want displayed. How do I use the following, or whichever method is correct, so that it does the antialiasing and renders this in the picturebox? I know this cant be too hard. Im hoping its not.
protected override void OnPaint(PaintEventArgs pea)
{
Graphics grfx = pea.Graphics;
Pen pen = new Pen(ForeColor);
grfx.SmoothingMode = SmoothingMode.HighQuality;
grfx.PixelOffsetMode = PixelOffsetMode.HighQuality;
}
Last night, after getting ready to post this, I tried one more thing, thinking that I can figure this out myself.
Graphics grfx = Graphics.FromImage(pictureBox1.Image);
grfx.SmoothingMode = SmoothingMode.HighQuality;
grfx.PixelOffsetMode = PixelOffsetMode.HighQuality;
grfx.TextRenderingHint = TextRenderingHint.AntiAlias;
For the TIFF image I was trying to view I got the following exception:
"A graphics object cannot be created from an image that has an indexed pixel format".
When viewing a JPG I didnt get the error message, but the image looked no different with the graphics properties set. Now I have two problems; not only do I not know how to set these options so that the image is viewed in the picturebox using the graphics properties, but even if I can figure it out it doesnt seem to work with TIFF images and thats all Im using.
Thanks in advance,
Jeff