개정판 566f0526
Image 밝기 & 색 농도 조절
Change-Id: I80feb7c7a64fbaf8d1d85a32bdf8baa813be2d4c
KCOM/Controls/DecodeImage.cs | ||
---|---|---|
1 |
using System; |
|
1 |
using KCOM.Common; |
|
2 |
using System; |
|
2 | 3 |
using System.Collections.Generic; |
3 | 4 |
|
4 | 5 |
using System.Linq; |
... | ... | |
69 | 70 |
set => SetValue(ScaleProperty, value); |
70 | 71 |
} |
71 | 72 |
|
72 |
private static void ScalePropertyChaged(DependencyObject d, DependencyPropertyChangedEventArgs e) |
|
73 |
private static async void ScalePropertyChaged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
73 | 74 |
{ |
74 | 75 |
var owner = d as ScaleDecodeImage; |
75 | 76 |
|
76 | 77 |
if (owner != null) |
77 | 78 |
{ |
78 |
var value = owner.Scale; |
|
79 |
//System.Windows.Media.Imaging.BitmapImage image = owner.Source.Clone(); |
|
80 |
|
|
81 |
//image.DecodePixelWidth = (int)(image.PixelWidth * value); |
|
82 |
//image.DecodePixelHeight = (int)(image.PixelHeight * value); |
|
83 |
|
|
84 |
//owner.ViewSource = image; |
|
85 |
|
|
86 |
if (value < 1) |
|
87 |
{ |
|
88 |
TransformedBitmap tb = new TransformedBitmap(); |
|
89 |
tb.BeginInit(); |
|
90 |
tb.Source = owner.Source; |
|
91 |
tb.Transform = new ScaleTransform(value, value); |
|
92 |
tb.EndInit(); |
|
93 |
System.Diagnostics.Debug.WriteLine($"TranFormImage Height : {tb.Height} Scale : {value}"); |
|
94 |
owner.ViewSource = tb; |
|
95 |
} |
|
79 |
await owner.Dispatcher.InvokeAsync(() => { |
|
80 |
|
|
81 |
var value = owner.Scale; |
|
82 |
|
|
83 |
if (value < 1) |
|
84 |
{ |
|
85 |
TransformedBitmap tb = new TransformedBitmap(); |
|
86 |
tb.BeginInit(); |
|
87 |
tb.Source = owner.Source; |
|
88 |
tb.Transform = new ScaleTransform(value, value); |
|
89 |
tb.EndInit(); |
|
90 |
|
|
91 |
byte[] pixels = ImageSourceHelper.CopyPixels(tb); |
|
92 |
|
|
93 |
var brightness = (double)(value * 100) / (double)100 * (double)100 - 80; |
|
94 |
|
|
95 |
if (brightness < -30) |
|
96 |
{ |
|
97 |
pixels = ImageSourceHelper.SetBrightnessAndContrast((int)brightness, brightness * -1.0, pixels); |
|
98 |
//pixels = ImageSourceHelper.SetContrast(brightness * -1.0, pixels); |
|
99 |
|
|
100 |
var bmp = new WriteableBitmap(tb.PixelWidth, tb.PixelHeight, tb.DpiX, tb.DpiY, PixelFormats.Pbgra32, null); |
|
101 |
bmp.WritePixels(new Int32Rect(0, 0, tb.PixelWidth, tb.PixelHeight), pixels, tb.PixelWidth * 4, 0); |
|
102 |
owner.ViewSource = bmp; |
|
103 |
} |
|
104 |
else |
|
105 |
{ |
|
106 |
owner.ViewSource = tb; |
|
107 |
} |
|
108 |
|
|
109 |
System.Diagnostics.Debug.WriteLine($"TranFormImage Height : {tb.Height} Scale : {value} brightness : {brightness}"); |
|
110 |
|
|
111 |
} |
|
112 |
}); |
|
96 | 113 |
} |
97 | 114 |
} |
98 | 115 |
} |
내보내기 Unified diff