0

在我的应用程序中有一个完整尺寸的框架和一个较小尺寸的内部图片。我希望内部的在框架内部和顶部。所以这就是我所做的:

var resourceStream = Application.GetResourceStream(new Uri("Assets/Frame.png", UriKind.Relative));
var frame = new BitmapImage();
frame.SetSource(resourceStream.Stream);

WriteableBitmap finalImage = new WriteableBitmap(frame);

using (MemoryStream memoryStream = new MemoryStream())
{
    BitmapImage innerImage = new BitmapImage(new Uri(string.Format("Assets/Pages/{0}.png", page), UriKind.Relative));
    Image image = new Image();
    image.Height = innerImage.PixelHeight;
    image.Width = innerImage.PixelWidth;
    image.Source = innerImage;

    TranslateTransform translateTransform = new TranslateTransform();
    translateTransform.X = 52;
    translateTransform.Y = 60;

    finalImage.Render(image, translateTransform);
    finalImage.Invalidate();

    finalImage.SaveJpeg(memoryStream, frame.PixelWidth, frame.PixelHeight, 0, 100);
    memoryStream.Seek(0, System.IO.SeekOrigin.Begin);

    PagePicture.Source = finalImage;
}

但我只看到没有内部图像的框架。我猜可能是在框架后面。我该如何解决这个问题?

或者也许我可以在不合并的情况下同时拥有两个控件?让我试试

4

1 回答 1

1

希望这个链接能指导你。请访问这里。详细说明请参考 MSDN SAmple。两者相同,但您可以在此处获取描述。

现在试试这个

    using (MemoryStream mem = new MemoryStream())
        {
            //Inner Image
            BitmapImage innerImage = new BitmapImage();
            innerImage.SetSource(System.Windows.Application.GetResourceStream(new Uri("test.jpg", UriKind.Relative)).Stream);
            WriteableBitmap wb = new WriteableBitmap(innerImage);

            //Frame Images
            BitmapImage finalImage = new BitmapImage();
            finalImage.SetSource(System.Windows.Application.GetResourceStream(new Uri("White.jpg", UriKind.Relative)).Stream);
            WriteableBitmap wbFinal = new WriteableBitmap(finalImage);

            Image image = new Image();
            image.Height = innerImage.PixelHeight;
            image.Width = innerImage.PixelWidth;
            image.Source = innerImage;

            // TranslateTransform                      
            TranslateTransform tf = new TranslateTransform();
            tf.X = 52;
            tf.Y = 60;
            wbFinal.Render(image, tf);

            wbFinal.Invalidate();
            wbFinal.SaveJpeg(mem, wb.PixelWidth, wb.PixelHeight, 0, 100);
            mem.Seek(0, System.IO.SeekOrigin.Begin);

            // Show image.               
            PagePicture.Source = wbFinal;
        }
于 2013-06-28T04:35:12.320 回答