How can I merge two images into one?

2019-08-03 20:42发布

问题:

I have a mask image with opacity about 70%, and I have another image that is downloaded from server. How can I redraw them to single image that have the downloaded image lay right below the mask image? I don't want to use canvas because I will use the merge image for panorama background, and canvas wouldn't work.

Something like this:

using (Graphics grfx = Graphics.FromImage(image))
{
    grfx.DrawImage(newImage, x, y)
}

I tried this but no luck:

        BitmapImage bmp = new BitmapImage();
        BitmapImage bi = new BitmapImage();

        ImageBrush imageBrush = new ImageBrush();
        ImageBrush imageBrush2 = new ImageBrush();

        bi.UriSource = new Uri("Images/MainPage/mask_bg.png", UriKind.Relative);
        bmp.UriSource = new Uri("Images/MainPage/covertart_bg.jpg", UriKind.Relative);

        TranslateTransform translate = new TranslateTransform
        {
            X = 0,
            Y = 0
        };
        imageBrush.ImageSource = bmp;
        ImageCanvas canvas = new ImageCanvas();
        canvas.Background = imageBrush;

        WriteableBitmap w_bitmap = new WriteableBitmap(1065, 800);
        w_bitmap.Render(canvas, translate);
        w_bitmap.Invalidate();

        imageBrush2.ImageSource = w_bitmap;
        mainPanorama.Background = imageBrush2;

回答1:

Use the Blit method from the WriteableBitmapEx project