How can I merge two images into one?

China☆狼群 提交于 2019-12-13 18:32:14

问题


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



来源:https://stackoverflow.com/questions/7186878/how-can-i-merge-two-images-into-one

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!