@@ -23,25 +23,26 @@ public partial class MainWindow : Window
23
23
Image drawingImage ;
24
24
Image paletteImage ;
25
25
26
+ // bitmap settings
26
27
int canvasResolutionX = 16 ;
27
28
int canvasResolutionY = 16 ;
28
-
29
29
int paletteResolutionX = 4 ;
30
30
int paletteResolutionY = 16 ;
31
-
32
- int prevX ;
33
- int prevY ;
34
-
35
31
int canvasScaleX = 1 ;
36
32
int paletteScaleX = 1 ;
37
33
int paletteScaleY = 1 ;
38
-
39
34
int dpiX = 96 ;
40
35
int dpiY = 96 ;
41
36
37
+ // colors
42
38
PixelColor currentColor ;
43
39
PixelColor [ ] palette ;
44
40
int currentColorIndex = 0 ;
41
+ byte opacity = 255 ;
42
+
43
+ // mouse
44
+ int prevX ;
45
+ int prevY ;
45
46
46
47
47
48
public MainWindow ( )
@@ -58,7 +59,7 @@ void Start()
58
59
RenderOptions . SetEdgeMode ( drawingImage , EdgeMode . Aliased ) ;
59
60
w = ( MainWindow ) Application . Current . MainWindow ;
60
61
canvasScaleX = ( int ) drawingImage . Width / canvasResolutionX ;
61
- canvasBitmap = new WriteableBitmap ( canvasResolutionX , canvasResolutionY , dpiX , dpiY , PixelFormats . Bgr32 , null ) ;
62
+ canvasBitmap = new WriteableBitmap ( canvasResolutionX , canvasResolutionY , dpiX , dpiY , PixelFormats . Bgra32 , null ) ;
62
63
drawingImage . Source = canvasBitmap ;
63
64
64
65
// drawing events
@@ -77,14 +78,13 @@ void Start()
77
78
dpiY = 96 ;
78
79
paletteScaleX = ( int ) paletteImage . Width / paletteResolutionX ;
79
80
paletteScaleY = ( int ) paletteImage . Height / paletteResolutionY ;
80
- paletteBitmap = new WriteableBitmap ( paletteResolutionX , paletteResolutionY , dpiX , dpiY , PixelFormats . Bgr32 , null ) ;
81
+ paletteBitmap = new WriteableBitmap ( paletteResolutionX , paletteResolutionY , dpiX , dpiY , PixelFormats . Bgra32 , null ) ;
81
82
paletteImage . Source = paletteBitmap ;
82
83
83
84
// palette events
84
85
paletteImage . MouseLeftButtonDown += new MouseButtonEventHandler ( PaletteLeftButtonDown ) ;
85
86
//paletteImage.MouseRightButtonDown += new MouseButtonEventHandler(PaletteRightButtonDown);
86
87
87
-
88
88
// init
89
89
LoadPalette ( ) ;
90
90
currentColorIndex = 5 ;
@@ -129,11 +129,8 @@ void LoadPalette()
129
129
x = i % paletteResolutionX ;
130
130
y = ( i % len ) / paletteResolutionX ;
131
131
}
132
-
133
-
134
132
}
135
133
136
-
137
134
void SetPixel ( WriteableBitmap bitmap , int x , int y , int color )
138
135
{
139
136
try
@@ -278,7 +275,6 @@ void PaletteLeftButtonDown(object sender, MouseButtonEventArgs e)
278
275
279
276
void UpdateCurrentColor ( )
280
277
{
281
- // var col = Color.FromArgb(palette[currentColorIndex].Alpha, palette[currentColorIndex].Red, palette[currentColorIndex].Green, palette[currentColorIndex].Blue);
282
278
var col = Color . FromArgb ( currentColor . Alpha , currentColor . Red , currentColor . Green , currentColor . Blue ) ;
283
279
rectCurrentColor . Fill = new SolidColorBrush ( col ) ;
284
280
}
@@ -377,7 +373,7 @@ private void OnClearButton(object sender, RoutedEventArgs e)
377
373
// clears bitmap by re-creating it
378
374
void ClearImage ( WriteableBitmap target )
379
375
{
380
- canvasBitmap = new WriteableBitmap ( canvasResolutionX , canvasResolutionY , dpiX , dpiY , PixelFormats . Bgr32 , null ) ;
376
+ canvasBitmap = new WriteableBitmap ( canvasResolutionX , canvasResolutionY , dpiX , dpiY , PixelFormats . Bgra32 , null ) ;
381
377
drawingImage . Source = canvasBitmap ;
382
378
}
383
379
@@ -417,5 +413,13 @@ public static void UseDefaultExtAsFilterIndex(FileDialog dialog)
417
413
}
418
414
}
419
415
416
+ private void OpacitySliderValueChanged ( object sender , RoutedPropertyChangedEventArgs < double > e )
417
+ {
418
+ var slider = sender as Slider ;
419
+ opacity = ( byte ) slider . Value ;
420
+ currentColor . Alpha = opacity ;
421
+ // ... Set Window Title.
422
+ //this.Title = "Value: " + value.ToString("0.0") + "/" + slider.Maximum;
423
+ }
420
424
} // class
421
425
} // namespace
0 commit comments