BitmapSource bitmap = null;
int degreeBrightness = ;
int degreeContrast = ; private void SetBrightness(int degree)
{
degree = degree * / ;
WriteableBitmap wb = new WriteableBitmap(bitmap);
uint[] PixelData = new uint[wb.PixelWidth * wb.PixelHeight];
wb.CopyPixels(PixelData, * wb.PixelWidth, );
for (uint y = ; y < wb.PixelHeight; y++)
{
for (uint x = ; x < wb.PixelWidth; x++)
{
uint pixel = PixelData[y * wb.PixelWidth + x];
byte[] dd = BitConverter.GetBytes(pixel);
int B = (int)dd[] + degree;
int G = (int)dd[] + degree;
int R = (int)dd[] + degree;
if (B < ) B = ;
if (B > ) B = ;
if (G < ) G = ;
if (G > ) G = ;
if (R < ) R = ;
if (R > ) R = ;
dd[] = (byte)B;
dd[] = (byte)G;
dd[] = (byte)R;
PixelData[y * wb.PixelWidth + x] = BitConverter.ToUInt32(dd, );
}
}
wb.WritePixels(new Int32Rect(, , wb.PixelWidth, wb.PixelHeight), PixelData, * wb.PixelWidth, );
//this.image.Source = wb;
}
private void SetContrast(int degree)
{
double contrast = (100.0 + degree) / 100.0;
WriteableBitmap wb = new WriteableBitmap(bitmap);
uint[] PixelData = new uint[wb.PixelWidth * wb.PixelHeight];
wb.CopyPixels(PixelData, * wb.PixelWidth, );
for (uint y = ; y < wb.PixelHeight; y++)
{
for (uint x = ; x < wb.PixelWidth; x++)
{
uint pixel = PixelData[y * wb.PixelWidth + x];
byte[] dd = BitConverter.GetBytes(pixel);
double B = (((double)dd[] / - 0.5) * contrast + 0.5) * ;
double G = (((double)dd[] / - 0.5) * contrast + 0.5) * ;
double R = (((double)dd[] / - 0.5) * contrast + 0.5) * ;
if (B < ) B = ;
if (B > ) B = ;
if (G < ) G = ;
if (G > ) G = ;
if (R < ) R = ;
if (R > ) R = ;
dd[] = (byte)B;
dd[] = (byte)G;
dd[] = (byte)R;
PixelData[y * wb.PixelWidth + x] = BitConverter.ToUInt32(dd, );
}
}
wb.WritePixels(new Int32Rect(, , wb.PixelWidth, wb.PixelHeight), PixelData, * wb.PixelWidth, );
//this.image.Source = wb;
}
private void SetCaptureImageCurrent(int degreeContrast, int degreeBrightness)
{
if (bitmap == null)
{
return;
}
WriteableBitmap wb = new WriteableBitmap(bitmap);
uint[] PixelData = new uint[wb.PixelWidth * wb.PixelHeight];
wb.CopyPixels(PixelData, * wb.PixelWidth, ); if (degreeBrightness != )
{
degreeBrightness = degreeBrightness * / ;
for (uint y = ; y < wb.PixelHeight; y++)
{
for (uint x = ; x < wb.PixelWidth; x++)
{
uint pixel = PixelData[y * wb.PixelWidth + x];
byte[] dd = BitConverter.GetBytes(pixel);
int B = (int)dd[] + degreeBrightness;
int G = (int)dd[] + degreeBrightness;
int R = (int)dd[] + degreeBrightness;
if (B < ) B = ;
if (B > ) B = ;
if (G < ) G = ;
if (G > ) G = ;
if (R < ) R = ;
if (R > ) R = ;
dd[] = (byte)B;
dd[] = (byte)G;
dd[] = (byte)R;
PixelData[y * wb.PixelWidth + x] = BitConverter.ToUInt32(dd, );
}
}
} if (degreeContrast != )
{
double contrast = (100.0 + degreeContrast) / 100.0;
for (uint y = ; y < wb.PixelHeight; y++)
{
for (uint x = ; x < wb.PixelWidth; x++)
{
uint pixel = PixelData[y * wb.PixelWidth + x];
byte[] dd = BitConverter.GetBytes(pixel);
double B = (((double)dd[] / - 0.5) * contrast + 0.5) * ;
double G = (((double)dd[] / - 0.5) * contrast + 0.5) * ;
double R = (((double)dd[] / - 0.5) * contrast + 0.5) * ;
if (B < ) B = ;
if (B > ) B = ;
if (G < ) G = ;
if (G > ) G = ;
if (R < ) R = ;
if (R > ) R = ;
dd[] = (byte)B;
dd[] = (byte)G;
dd[] = (byte)R;
PixelData[y * wb.PixelWidth + x] = BitConverter.ToUInt32(dd, );
}
}
} wb.WritePixels(new Int32Rect(, , wb.PixelWidth, wb.PixelHeight), PixelData, * wb.PixelWidth, ); PngBitmapEncoder pE = new PngBitmapEncoder();
pE.Frames.Add(BitmapFrame.Create(wb));
using (Stream stream = File.Create(SelectedImage))
{
pE.Save(stream);
}
Messenger.Default.Send(wb, "PatientImageView");
}

C#调整图片亮度和对比度的更多相关文章

  1. Opencv学习笔记4:Opencv处理调整图片亮度和对比度

    一.理论基础 在数学中我们学过线性理论,在图像亮度和对比度调节中同样适用,看下面这个公式: 在图像像素中其中: 参数f(x)表示源图像像素. 参数g(x) 表示输出图像像素. 参数a(需要满足a> ...

  2. canvas-修改图片亮度

    canvas操作-修改图片亮度 目录 canvas操作-修改图片亮度 图片亮度的概念 下面用ps截图举一个例子: 调整图片亮度的方案 实现方案一 从RGB到HSV的转换 转换的公式 javascrip ...

  3. Unity Shader-后处理:简单的颜色调整(亮度,饱和度,对比度)

    好久没坚持写blog了,是时候开始撸一波新博文了!学习Unity有一段时间了,关于Shader的书也看了几本<Unity Shader入门精要>,<Unity 3D ShaderLa ...

  4. Python-OpenCV——亮度和对比度

    亮度与对比度 亮度调整是将图像像素的强度整体变大/变小,对比度调整指的是图像暗处变得更暗,亮出变得更亮,从而拓宽某个区域内的显示精度. OpenCV中亮度和对比度应用这个公式来计算:g(x) = αf ...

  5. BackgroundCheck – 根据图片亮度智能切换元素样式

    BackgroundCheck 是一个轻量的 JavaScript 库,能够根据元素后面的图片的亮度自动切换元素样式.例如在图片幻灯片功能中,根据图片亮度调整导航箭头的颜色,这样让图片和导航的颜色形成 ...

  6. Android 播放电影时滑动屏幕调整屏幕亮度(转)

    (转自:http://blog.csdn.net/piaozhiye/article/details/6544450) 发现有一些主流的播放器播放电影时可以通过滑动屏幕调整屏幕亮度,其实实现起来也很容 ...

  7. glsl计算sprite的亮度饱和度对比度

    //glsl计算sprite的亮度饱和度对比度 #ifdef GL_ES precision mediump float; #endif uniform sampler2D u_texture; va ...

  8. Linux中如何使用gThumb批量调整图片大小

    Linux中如何使用gThumb批量调整图片大小 导读 如果你的工作涉及到图片编辑和处理,就一定会有同时对多张图片进行批量大小调整的经历.虽然大多数图片编辑应用都能够非常容易地批量调整多张图片,但对于 ...

  9. wps 批量调整图片大小 宏

    Sub 批量调整图片大小() ' ' 批量修改图片 Macro ' 宏由 zxz 录制,时间: 2014/10/29 '批量调整图片大小,避免图片太大显示不完全 '循环图片集合 For Each iS ...

随机推荐

  1. zabbix系列之六——安装后配置二Items

    https://www.zabbix.com/documentation/3.4/manual/config/items/itemtypes/snmp 1Items 1.1creating items ...

  2. HBase Scan流程分析

    HBase Scan流程分析 HBase的读流程目前看来比较复杂,主要由于: HBase的表数据分为多个层次,HRegion->HStore->[HFile,HFile,...,MemSt ...

  3. SQL Server ->> 存储过程sp_describe_first_result_set解析T-SQL语句的结果集结构信息

    返回 Transact-SQL 批处理的第一个可能结果集的元数据. 如果批处理没有返回结果,则返回一个空的结果集. 如果数据库引擎无法确定将通过执行静态分析来执行的第一个查询的元数据,则引发错误. E ...

  4. [翻译] GCDiscreetNotificationView

    GCDiscreetNotificationView GCDiscreetNotificationView is a discreet, non-modal, notification view fo ...

  5. Linux 系统安装[Ubuntu]

    1.1.1. 安装Ubuntu 下载链接[Ubuntu16.04.1-64bit-Desktop版]: http://old-releases.ubuntu.com/releases/16.04.1/ ...

  6. Android点击事件

    Android点击事件 备注 全局实现View.OnClickListener 或许需要将MainActivity设置为public 注册事件 btn_login.setOnClickListener ...

  7. 深入浅出SharePoint2013——安装SharePoint2013

    在这个页面的底部可以通过相应链接下载Sharepoint Server安装文件  https://technet.microsoft.com/en-us/library/cc262788.aspx

  8. Deadline下:写论文的总结

    终于赶在了11月底截止的时刻提交上了导航年会的论文.三天加上两个半晚上差不多干完了80%的活,无论是否能够被录,这次的写作收获很大. 认识到了: 1. 读文献时,一定要带着问题,如果是我来做,我会怎么 ...

  9. codeforces 17D Notepad

    codeforces 17D Notepad 题意 题解 TBD 更新模板(phi.欧拉降幂) 代码 #include<bits/stdc++.h> using namespace std ...

  10. RAID廉价磁盘冗余阵列介绍

    RAID(廉价磁盘冗余阵列)技术主要是为了改善磁盘的访问延迟,增强磁盘的可用性和容错能力.目前服务器级别的计算机都支持插入多块磁盘(8块或者更多),通过使用RAID技术,实现数据在多块磁盘上的并发读写 ...