No 74 · 以不同的透明度显示图像
来源:互联网 发布:win8系统盘克隆软件 编辑:程序博客网 时间:2024/05/26 05:51
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Drawing.Drawing2D;namespace Ex13_18{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private Bitmap SourceBitmap; private Bitmap MyBitmap; private void button2_Click(object sender, EventArgs e) { //打开图像文件 OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "图像文件(JPeg, Gif, Bmp, etc.)|*.jpg;*.jpeg;*.gif;*.bmp;*.tif; *.tiff; *.png| JPeg 图像文件(*.jpg;*.jpeg)|*.jpg;*.jpeg |GIF 图像文件(*.gif)|*.gif |BMP图像文件(*.bmp)|*.bmp|Tiff图像文件(*.tif;*.tiff)|*.tif;*.tiff|Png图像文件(*.png)| *.png |所有文件(*.*)|*.*"; if (openFileDialog.ShowDialog() == DialogResult.OK) { //得到原始大小的图像 SourceBitmap = new Bitmap(openFileDialog.FileName); //得到缩放后的图像 MyBitmap = new Bitmap(SourceBitmap, this.pictureBox1.Width, this.pictureBox1.Height); this.pictureBox1.Image = MyBitmap; } } private void button1_Click(object sender, EventArgs e) { //以不同的透明度显示图像 Graphics g = this.panel1.CreateGraphics(); g.SmoothingMode = SmoothingMode.AntiAlias; TextureBrush MyBrush = new TextureBrush(MyBitmap); g.FillRectangle(MyBrush, this.panel1.ClientRectangle); for (int i = 0; i < 255; i++) {//由透明变为不透明 g.FillRectangle(new SolidBrush(Color.FromArgb(i,Color.DarkSlateGray)), this.panel1.ClientRectangle); System.Threading.Thread.Sleep(100); } } }}