0

Does anyone know the solution to layering PNG images for windows UWP app? While preserving the transparency?

(this solution does not work in UWP application)

Merge two png images with transparency and retain transparency

End goal is to merge the PNG files to an Image object so it can be added to a Grid control.

Community
  • 1
  • 1
erotavlas
  • 4,274
  • 4
  • 45
  • 104
  • 1
    Why does it not work in a UWP app? – Cody Gray - on strike Jul 03 '16 at 18:33
  • @CodyGray Some of those classes don't exist in UWP (intellisense does not recognize most of them) Like for example there is no Bitmap object, no PixelFormat, no CompositingMode etc. I'm not sure which are the equivalent objects in UWP, or if there is some built in method to do this. My search didn't turn up very much UWP related - except for the WPF stuff. – erotavlas Jul 04 '16 at 01:39

3 Answers3

2

One possible solution is using Blit method in WriteableBitmapEx. This method copies (blits) the pixels from the WriteableBitmap source to the destination WriteableBitmap (this) and following is a simple sample.

var writeableBmp = new WriteableBitmap(1, 1);

var image1 = await writeableBmp.FromContent(new Uri("ms-appx:///Assets/image1.png"));
var image2 = await writeableBmp.FromContent(new Uri("ms-appx:///Assets/image2.png"));

image1.Blit(new Rect(0, 0, image1.PixelWidth, image1.PixelHeight), image2, new Rect(0, 0, image2.PixelWidth, image2.PixelHeight));

//BlendedImage is a Image control in XAML
BlendedImage.Source = image1;
Jay Zuo
  • 15,653
  • 2
  • 25
  • 49
  • my WriteableBitmap in UWP does not contain a method `FromContent`, nor does it contain `Blit`, is there some namespace I have to use first? – Hendra Anggrian Sep 06 '16 at 17:43
  • @HendraAnggrian You need to add the reference of WriteableBitmapEx. And it's available as [NuGet package](http://nuget.org/List/Packages/WriteableBitmapEx). – Jay Zuo Sep 07 '16 at 01:13
  • Thank you soooo much for this answer – Negar May 21 '19 at 14:43
0

I think you may use the two image control in Grid in Xaml and both have bind the transparency in viewModel.But I see the link and I also can't use it.May MS change the API.I also interesting in this.

lindexi
  • 4,182
  • 3
  • 19
  • 65
0

Lumia Imaging SDK doing just what you want. It can blend 2 ore more images together.

You can find sample code here

ad1Dima
  • 3,185
  • 2
  • 26
  • 37