我正在使用WinForms。我的应用程序像一个简单的图像查看器。它打开图像文件转到下一页,放大并缩小。我的应用程序的问题是,当我重新调整大小或放大图像时,图像开始变得模糊。当我缩小或放大时,如何防止图像模糊?
当我在Windows Photo Viewer上查看并重新调整相同图像大小时,图像清晰。当我在我的应用程序中打开图像时,图像是清晰的,但是一旦我开始重新调整大小,例如当我开始使用缩放时,它开始变得模糊。
我尝试在缩小方法中实现此代码,但我无法弄清楚如何执行此操作。
FileStream _stream;
Image _myImg; // setting the selected tiff
string _fileName;
private int intCurrPage = 0; // defining the current page
private void Open_Btn_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
lblFile.Text = openFileDialog1.FileName; //Shows the filename in the lable
Open_Image_Control();
Image img = Image.FromFile(openFileDialog1.FileName);
pictureBox1.Image = img;
pictureBox1.Width = img.Width;
pictureBox1.Height = img.Height;
this.pictureBox1.Image.RotateFlip(RotateFlipType.Rotate90FlipNone); // Rotates image 90 degrees
}
}
public void Open_Image_Control()
{
Image myBmp;
if (_myImg == null)
{
_fileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));
File.Copy(@lblFile.Text, _fileName);
_stream = new FileStream(_fileName, FileMode.Open, FileAccess.Read);
_myImg = Image.FromStream(_stream);
}
int intPages = _myImg.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page); // getting the number of pages of this tiff
intPages--; // the first page is 0 so we must correct the number of pages to -1
lblNumPages.Text = Convert.ToString(intPages); // showing the number of pages
lblCurrPage.Text = Convert.ToString(intCurrPage); // showing the number of page on which we're on
_myImg.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, intCurrPage); // going to the selected page
myBmp = new Bitmap(_myImg, pictureBox1.Width, pictureBox1.Height);
pictureBox1.Image = myBmp; // showing the page in the pictureBox1
}
private void ZoomIN_Btn_Click(object sender, EventArgs e)
{
this.pictureBox1.Width += 175; //Zoom width by 75
this.pictureBox1.Height += 175; //Zoom height by 75
}
private void ZoomOut_Btn_Click(object sender, EventArgs e)
{
this.pictureBox1.Width -= 175; //Zoom out width by 75
this.pictureBox1.Height -= 175; //Zoom out height by 75
}
private void NextPage_btn_Click(object sender, EventArgs e)
{
if (intCurrPage == Convert.ToInt32(lblNumPages.Text)) // if you have reached the last page it ends here
// the "-1" should be there for normalizing the number of pages
{ intCurrPage = Convert.ToInt32(lblNumPages.Text); }
else
{
intCurrPage++; //page increment (Goes to next page)
Open_Image_Control();
this.pictureBox1.Image.RotateFlip(RotateFlipType.Rotate90FlipNone); // Rotates image 90 degrees
}
}
我看的图像尺寸:
尺寸:2540 x 3289
尺寸:2533 x 3284
尺寸:2538 x 3282
尺寸:2479 x 3508
{{1}}