using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Imaging;
namespace 可選擇欲處理影像
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
open.InitialDirectory = @"D:\MyPhoto\";
if (open.ShowDialog() == DialogResult.OK)
{
ImageForm MyImage = new ImageForm(open.FileName);
MyImage.Show();
}
}
class ImageForm : Form
{
Image image;
public ImageForm(String Filename)
{
image = Image.FromFile(Filename);
this.Text = Filename;
}
protected override void OnPaint(PaintEventArgs e)
{
this.Height = image.Height ;
this.Width = image.Width ;
e.Graphics.DrawImage(image,0,0) ;
}
}
}
}
看到結果會發現,只能照原圖解析度秀出,所以下一篇要寫調整圖片大小。
沒有留言:
張貼留言