網(wǎng)站首頁 編程語言 正文
實踐過程
效果
代碼
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Image new_img;
private void ChangeAlpha()
{
pictureBox1.Refresh();
Bitmap source = new Bitmap(pictureBox1.Image);
Bitmap effect = new Bitmap(pictureBox1.Image.Width,pictureBox1.Image.Height);
Graphics _effect = Graphics.FromImage(effect);
float[][] matrixItems ={new float[]{1,0,0,0,0},
new float [] {0,1,0,0,0},
new float []{0,0,1,0,0},
new float []{0,0,0,0,0},
new float[]{0,0,0,trackBar1.Value/255f,1}};
ColorMatrix imgMatrix = new ColorMatrix(matrixItems);
ImageAttributes imgEffect = new ImageAttributes();
imgEffect.SetColorMatrix(imgMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
if (source.Width <= 368)
{
_effect.DrawImage(source, new Rectangle(0, 0, pictureBox1.Image.Width, pictureBox1.Image.Height), 0, 0, pictureBox1.Image.Width, pictureBox1.Image.Height, GraphicsUnit.Pixel, imgEffect);
}
else
{
_effect.DrawImage(pictureBox1.Image, new Rectangle(0, 0, pictureBox1.Image.Width, pictureBox1.Image.Height), 0, 0, pictureBox1.Image.Width, pictureBox1.Image.Height, GraphicsUnit.Pixel, imgEffect);
}
pictureBox1.Image = effect;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void trackBar1_ValueChanged(object sender, EventArgs e)
{
ChangeAlpha();
}
private void button1_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image = Image.FromFile(openFileDialog1.FileName);
}
}
}
partial class Form1
{
/// <summary>
/// 必需的設(shè)計器變量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的資源。
/// </summary>
/// <param name="disposing">如果應(yīng)釋放托管資源,為 true;否則為 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗體設(shè)計器生成的代碼
/// <summary>
/// 設(shè)計器支持所需的方法 - 不要
/// 使用代碼編輯器修改此方法的內(nèi)容。
/// </summary>
private void InitializeComponent()
{
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.trackBar1 = new System.Windows.Forms.TrackBar();
this.button1 = new System.Windows.Forms.Button();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(12, 80);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(424, 258);
this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// trackBar1
//
this.trackBar1.Location = new System.Drawing.Point(12, 41);
this.trackBar1.Maximum = 100;
this.trackBar1.Minimum = 1;
this.trackBar1.Name = "trackBar1";
this.trackBar1.Size = new System.Drawing.Size(424, 45);
this.trackBar1.TabIndex = 1;
this.trackBar1.TickStyle = System.Windows.Forms.TickStyle.None;
this.trackBar1.Value = 100;
this.trackBar1.ValueChanged += new System.EventHandler(this.trackBar1_ValueChanged);
//
// button1
//
this.button1.Location = new System.Drawing.Point(12, 12);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 2;
this.button1.Text = "打開圖片";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// openFileDialog1
//
this.openFileDialog1.Filter = "圖片文件|*.jpg;*.jpeg;*.png;*.bmp";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(447, 350);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.button1);
this.Controls.Add(this.trackBar1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.TrackBar trackBar1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
}
原文鏈接:https://blog.csdn.net/qq_27489007/article/details/128103871
相關(guān)推薦
- 2022-07-14 Python?socket如何實現(xiàn)服務(wù)端和客戶端數(shù)據(jù)傳輸(TCP)_python
- 2022-03-30 Android?RecyclerView曝光采集的實現(xiàn)方法_Android
- 2022-10-21 Go錯誤和異常CGO?fallthrough處理教程詳解_Golang
- 2022-07-06 python數(shù)據(jù)挖掘Apriori算法實現(xiàn)關(guān)聯(lián)分析_python
- 2022-09-05 Involution: Inverting the Inherence of Convolution
- 2022-07-09 C語言堆與二叉樹的順序結(jié)構(gòu)與實現(xiàn)_C 語言
- 2023-03-15 k8s編排之StatefulSet知識點詳解一_云其它
- 2022-07-04 C#使用System.Buffer以字節(jié)數(shù)組Byte[]操作基元類型數(shù)據(jù)_C#教程
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支