如何将图像写入另一个图像?

时间:2014-05-25 07:30:21

标签: c# windows-phone-8

我有500x500的图像,对于此图像,我想在500x500图像的右上角复制一个32x32的符号。

我试图将其渲染,但它似乎不起作用:

var statusSymbol = new Image()
{
      Source = new BitmapImage(new Uri(tempJPEG, UriKind.Relative))
};

WriteableBitmap wb = new WriteableBitmap(bitmap);
wb.Render(statusSymbol , new TranslateTransform() { X = 500-10, Y = 10 });
wb.Invalidate();

1 个答案:

答案 0 :(得分:0)

手动方式(有利有弊):

 public Bitmap AddLogo(Bitmap original_image, Bitmap logo)
    {
        /// Add validation here (not null, logo smaller then original, etc..)
        Bitmap with_logo = new Bitmap(original_image);           

        /// To get the right corner use:
        int x_start_value = (original_image.Width - logo.Width) - 1;
        int x_stop_value = original_image.Width -1;
        /// 

        /// You can add ofset (padding) by starting x and\or y from your value insted of 0

        for (int y = 0; y < logo.Height; y++)            
        {

            /// For left corner
            ///for (int x = 0; x < logo.Width; x++)
            int logo_x = 0;
            for (int x = x_start_value; x < x_stop_value; x++)                
            {
                with_logo.SetPixel(x, y, logo.GetPixel(logo_x, y));
                logo_x++;
            }
        }

        return with_logo;
    }