개정판 81173d69
Scale 이미지 임시 저장 하도록 수정
Change-Id: Ia8c0864a70c8d9444d6d15bb62b7906fa53a6c14
KCOM/Controls/DecodeImage.cs | ||
---|---|---|
15 | 15 |
// [TemplatePart(Name = PART_IMAGE, Type = typeof(Image))] |
16 | 16 |
public class ScaleDecodeImage : System.Windows.Controls.Control |
17 | 17 |
{ |
18 |
// private const string PART_IMAGE = "PART_IMAGE"; |
|
18 |
// private const string PART_IMAGE = "PART_IMAGE";
|
|
19 | 19 |
//private Image ImageControl; |
20 |
private List<ScaleImage> scaleImages = new List<ScaleImage>(); |
|
20 | 21 |
|
21 | 22 |
public override void OnApplyTemplate() |
22 | 23 |
{ |
... | ... | |
54 | 55 |
{ |
55 | 56 |
if (e.NewValue != null) |
56 | 57 |
{ |
58 |
owner.scaleImages = new List<ScaleImage>(); |
|
57 | 59 |
owner.ViewSource = (BitmapImage)e.NewValue; |
58 | 60 |
owner.Scale = 1.0; |
59 | 61 |
} |
... | ... | |
76 | 78 |
|
77 | 79 |
if (owner != null) |
78 | 80 |
{ |
79 |
await owner.Dispatcher.InvokeAsync(() => { |
|
81 |
var value = owner.Scale; |
|
82 |
var scaleImage = owner.scaleImages.Where(x => x.Scale == value); |
|
80 | 83 |
|
81 |
var value = owner.Scale; |
|
82 |
|
|
83 |
if (value < 1) |
|
84 |
if (scaleImage.Count() > 0) |
|
85 |
{ |
|
86 |
owner.ViewSource = scaleImage.First().source; |
|
87 |
} |
|
88 |
else |
|
89 |
{ |
|
90 |
await owner.Dispatcher.InvokeAsync(() => |
|
84 | 91 |
{ |
85 |
TransformedBitmap tb = new TransformedBitmap(); |
|
86 |
tb.BeginInit(); |
|
87 |
tb.Source = owner.Source; |
|
88 |
tb.Transform = new ScaleTransform(value, value); |
|
89 |
tb.EndInit(); |
|
90 | 92 |
|
91 |
byte[] pixels = ImageSourceHelper.CopyPixels(tb); |
|
93 |
if (value < 1) |
|
94 |
{ |
|
95 |
TransformedBitmap tb = new TransformedBitmap(); |
|
96 |
tb.BeginInit(); |
|
97 |
tb.Source = owner.Source; |
|
98 |
tb.Transform = new ScaleTransform(value, value); |
|
99 |
tb.EndInit(); |
|
92 | 100 |
|
93 |
var brightness = (double)(value * 100) / (double)100 * (double)100 - 80;
|
|
101 |
byte[] pixels = ImageSourceHelper.CopyPixels(tb);
|
|
94 | 102 |
|
95 |
if (brightness < -30) |
|
96 |
{ |
|
97 |
pixels = ImageSourceHelper.SetBrightnessAndContrast((int)brightness, brightness * -1.0, pixels); |
|
98 |
//pixels = ImageSourceHelper.SetContrast(brightness * -1.0, pixels); |
|
103 |
var brightness = (double)(value * 100) / (double)100 * (double)100 - 80; |
|
99 | 104 |
|
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 |
} |
|
105 |
if (brightness < -30) |
|
106 |
{ |
|
107 |
pixels = ImageSourceHelper.SetBrightnessAndContrast((int)brightness, brightness * -1.0, pixels); |
|
108 |
//pixels = ImageSourceHelper.SetContrast(brightness * -1.0, pixels); |
|
108 | 109 |
|
109 |
System.Diagnostics.Debug.WriteLine($"TranFormImage Height : {tb.Height} Scale : {value} brightness : {brightness}"); |
|
110 |
|
|
111 |
} |
|
112 |
}); |
|
110 |
var bmp = new WriteableBitmap(tb.PixelWidth, tb.PixelHeight, tb.DpiX, tb.DpiY, PixelFormats.Pbgra32, null); |
|
111 |
bmp.WritePixels(new Int32Rect(0, 0, tb.PixelWidth, tb.PixelHeight), pixels, tb.PixelWidth * 4, 0); |
|
112 |
owner.ViewSource = bmp; |
|
113 |
} |
|
114 |
else |
|
115 |
{ |
|
116 |
owner.ViewSource = tb; |
|
117 |
} |
|
118 |
|
|
119 |
owner.scaleImages.Add(new ScaleImage { Scale = value, source = owner.ViewSource }); |
|
120 |
|
|
121 |
System.Diagnostics.Debug.WriteLine($"TranFormImage Height : {tb.Height} Scale : {value} brightness : {brightness}"); |
|
122 |
|
|
123 |
} |
|
124 |
}); |
|
125 |
} |
|
113 | 126 |
} |
114 | 127 |
} |
115 | 128 |
} |
129 |
|
|
130 |
public class ScaleImage |
|
131 |
{ |
|
132 |
public ImageSource source { get; set; } |
|
133 |
public double Scale { get; set; } |
|
134 |
} |
|
116 | 135 |
} |
내보내기 Unified diff