資源簡介
設置圖片亮度,和對比度。可以自動糾偏
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Drawing;
using?System.Drawing.Imaging;
using?System.Linq;
using?System.Text;
using?System.Threading.Tasks;
namespace?imagecalc
{
???public?class?CommonCalc
????{
????????///?
????????///?伽馬?Gamma校正
????????///?
????????///?輸入Bitmap
????????///?[0?<-明-?1?-暗->?2]
????????///?輸出Bitmap
????????public?static?Bitmap?KiGamma(Bitmap?bmp?float?val)
????????{
????????????if?(bmp?==?null)
????????????{
????????????????return?null;
????????????}
????????????//?1表示無變化,就不做
????????????if?(val?==?1.0000f)?return?bmp;
????????????try
????????????{
????????????????Bitmap?b?=?new?Bitmap(bmp.Width?bmp.Height);
????????????????Graphics?g?=?Graphics.FromImage(b);
????????????????ImageAttributes?attr?=?new?ImageAttributes();
????????????????attr.SetGamma(val?ColorAdjustType.Bitmap);
????????????????g.DrawImage(bmp?new?Rectangle(0?0?bmp.Width?bmp.Height)?0?0?bmp.Width?bmp.Height?GraphicsUnit.Pixel?attr);
????????????????g.Dispose();
????????????????return?b;
????????????}
????????????catch
????????????{
????????????????return?null;
????????????}
????????}
?????
????????///?
????????///?圖像對比度調整
????????///?
????????///?原始圖
????????///?對比度[-100?100]
????????///?
????????public?static?Bitmap?KiContrast(Bitmap?b?int?degree)
????????{
????????????if?(b?==?null)
????????????{
????????????????return?null;
????????????}
????????????//改成0-100,??50不變。
????????????if?(degree?-100)?degree?=?-100;
????????????if?(degree?>?100)?degree?=?100;
????????????try
????????????{
????????????????double?pixel?=?0;
????????????????double?contrast?=?(100.0?+?degree)?/?100.0;
????????????????contrast?*=?contrast;
????????????????int?width?=?b.Width;
????????????????int?height?=?b.Height;
????????????????BitmapData?data?=?b.LockBits(new?Rectangle(0?0?width?height)?ImageLockMode.ReadWrite?PixelFormat.Format24bppRgb);
????????????????unsafe
????????????????{
????????????????????byte*?p?=?(byte*)data.Scan0;
????????????????????int?offset?=?data.Stride?-?width?*?3;
????????????????????for?(int?y?=?0;?y?????????????????????{
????????????????????????for?(int?x?=?0;?x?????????????????????????{
????????????????????????????//?處理指定位置像素的對比度
????????????????????????????for?(int?i?=?0;?i?3;?i++)
????????????????????????????{
????????????????????????????????pixel?=?((p[i]?/?255.0?-?0.5)?*?contrast?+?0.5)?*?255;
????????????????????????????????if?(pixel?0)?pixel?=?0;
????????????????????????????????if?(pixel?>?255)?pixel?=?255;
????????????????????????????????p[i]?=?(byte)pixel;
????????????????????????????}?//?i
????????????????????????????p?+=?3;
????????????????????????}?//?x
????????????????????????p?+=?offset;
???
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????2946??2020-12-09?15:34??imagecalc.sln
?????目錄???????????0??2020-12-10?09:59??imagecalc\
?????文件?????????189??2020-12-04?14:51??imagecalc\App.config
?????目錄???????????0??2020-12-04?14:51??imagecalc\bin\
?????目錄???????????0??2020-12-08?11:51??imagecalc\bin\Debug\
?????文件??????932747??2020-12-04?16:52??imagecalc\bin\Debug\1.jpg
?????文件?????1011091??2020-12-05?14:31??imagecalc\bin\Debug\2.jpg
?????文件?????1234985??2020-01-20?14:08??imagecalc\bin\Debug\3.jpg
?????文件?????1397640??2020-01-20?14:08??imagecalc\bin\Debug\4.jpg
?????文件??????372438??2020-11-30?16:51??imagecalc\bin\Debug\5.jpg
?????文件??????505480??2020-11-30?16:51??imagecalc\bin\Debug\6.jpg
?????文件??????540280??2020-11-30?16:51??imagecalc\bin\Debug\7.jpg
?????文件??????589616??2020-11-30?16:51??imagecalc\bin\Debug\8.jpg
?????文件?????1239013??2020-11-30?16:51??imagecalc\bin\Debug\9.jpg
?????文件???????24064??2020-12-10?09:59??imagecalc\bin\Debug\imagecalc.exe
?????文件?????????189??2020-12-04?14:51??imagecalc\bin\Debug\imagecalc.exe.config
?????文件???????69120??2020-12-10?09:59??imagecalc\bin\Debug\imagecalc.pdb
?????文件??????920918??2020-12-05?14:51??imagecalc\bin\Debug\test.jpg
?????文件??????971723??2020-12-10?09:59??imagecalc\bin\Debug\糾偏1.jpg
?????文件????????4548??2020-12-09?11:28??imagecalc\CommonCalc.cs
?????文件????????5329??2020-12-04?15:03??imagecalc\Deskew.cs
?????文件????????1301??2020-12-04?16:56??imagecalc\deskew2.cs
?????文件????????9097??2020-12-04?16:56??imagecalc\DeskewOperat.cs
?????文件????????7956??2020-12-10?09:59??imagecalc\Form1.cs
?????文件???????14112??2020-12-10?09:59??imagecalc\Form1.Designer.cs
?????文件????????5817??2020-12-10?09:59??imagecalc\Form1.resx
?????文件????????5269??2020-12-04?16:56??imagecalc\gmseDeskew.cs
?????文件????????3855??2020-12-04?16:56??imagecalc\imagecalc.csproj
?????目錄???????????0??2020-12-04?14:51??imagecalc\obj\
?????目錄???????????0??2020-12-10?09:59??imagecalc\obj\Debug\
?????文件????????1443??2020-12-08?11:47??imagecalc\obj\Debug\DesignTimeResolveAssemblyReferences.cache
............此處省略20個文件信息
- 上一篇:asp.net 生命周期
- 下一篇:精易C#模塊
評論
共有 條評論