-
Notifications
You must be signed in to change notification settings - Fork 127
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
42 lines (37 loc) · 1.51 KB
/
MainWindow.xaml.cs
File metadata and controls
42 lines (37 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System.IO;
using System.Windows;
using System.Windows.Media.Imaging;
namespace WriteableBitmapExBlitAlphaRepro.Wpf
{
public partial class MainWindow
{
public MainWindow()
{
InitializeComponent();
}
private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
{
var unmodifiedBmp = LoadFromFile("Assets/Overlays/19.jpg");
var sticker = LoadFromFile("Assets/Overlays/nEW.png");
ImgOrg.Source = unmodifiedBmp;
ImgOrgOverlay.Source = sticker;
ImgMod.Source = Overlay(unmodifiedBmp, sticker, new Point(10, 10));
ImgModPrgba.Source = Overlay(BitmapFactory.ConvertToPbgra32Format(unmodifiedBmp), BitmapFactory.ConvertToPbgra32Format(sticker), new Point(10, 10));
}
public static WriteableBitmap Overlay(WriteableBitmap bmp, WriteableBitmap overlay, Point location)
{
var result = bmp.Clone();
var size = new Size(overlay.PixelWidth, overlay.PixelHeight);
result.Blit(new Rect(location, size), overlay, new Rect(new Point(0, 0), size), WriteableBitmapExtensions.BlendMode.Alpha);
return result;
}
public static WriteableBitmap LoadFromFile(string fileName)
{
using (var fileStream = File.OpenRead(fileName))
{
var wb = BitmapFactory.FromStream(fileStream);
return wb;
}
}
}
}