C#图片查看器
来源:互联网 发布:淘宝新品标签多久显示 编辑:程序博客网 时间:2024/05/01 20:27
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Windows.Forms;
- using System.Drawing;
- using System.IO;
- using System.Drawing.Design;
- namespace 图片查看
- {
- #region 展示大图
- class ShowPicture
- {
- #region 缩放图片尺寸
- private static Size Zoom(double x, double y,int MAX_X,int MAX_Y)
- {
- double SCALE = x / y;
- if (x > MAX_X && y > MAX_Y)
- {
- if (x > y)
- {
- for (x = MAX_X; ; )
- {
- y = x / SCALE;
- if (y <= MAX_Y)
- break;
- else
- x--;
- }
- }
- else
- {
- for (y = MAX_Y; ; )
- {
- x = SCALE * y;
- if (x <= MAX_X)
- break;
- else
- y--;
- }
- }
- }
- return new Size((int)x, (int)y);
- }
- #endregion
- public static void Show(Image OriginalImage)
- {
- if (OriginalImage != null)
- {
- Form showPicture = new Form();
- showPicture.BackColor = Color.Snow;
- showPicture.Text = "图片查看器";
- showPicture.WindowState = FormWindowState.Maximized;
- PictureBox 图片_show_pictureBox = new PictureBox();
- 图片_show_pictureBox.BackColor = Color.Black;
- 图片_show_pictureBox.BorderStyle = BorderStyle.FixedSingle;
- 图片_show_pictureBox.Size = Zoom(OriginalImage.Width, OriginalImage.Height,900,675);
- 图片_show_pictureBox.Image = OriginalImage;
- 图片_show_pictureBox.SizeMode = PictureBoxSizeMode.StretchImage;
- 图片_show_pictureBox.Location = new Point((1024 - 图片_show_pictureBox.Size.Width )/ 2, (675 - 图片_show_pictureBox.Size.Height) / 2);
- showPicture.Controls.Add(图片_show_pictureBox);
- showPicture.ShowDialog();
- GC.Collect();
- }
- }
- #endregion
- }
- #endregion
- }