Windows phone 7 将图像覆盖在另一个图像上 我试图画一个白色矩形(100×200),中间画一个较小的图像(50×75),使它看起来像一张扑克牌的背面。

Windows phone 7 将图像覆盖在另一个图像上 我试图画一个白色矩形(100×200),中间画一个较小的图像(50×75),使它看起来像一张扑克牌的背面。,windows-phone-7,Windows Phone 7,在下面的代码中,我得到的只是带有边框的瓷砖,但没有图像 //generate temporary control to render image Image temporaryImage = new Image { Source = emptyTileWatermark, Width = destWidth, Height = destHeight }; //create writeableBitmap WriteableBitm

在下面的代码中,我得到的只是带有边框的瓷砖,但没有图像

        //generate temporary control to render image
        Image temporaryImage = new Image { Source = emptyTileWatermark, Width = destWidth, Height = destHeight };

        //create writeableBitmap
        WriteableBitmap wb = new WriteableBitmap(outputWidth, outputHeight);
        wb.Clear(Colors.White);

        // Closed green polyline with P1(0, 0), P2(outputWidth, 0), P3(outputWidth, outputHeight) and P4(0, outputHeight)
        var outline = new int[] { 0, 0, outputWidth, 0, outputWidth, outputHeight, 0, outputHeight, 0, 0};
        wb.DrawPolyline(outline, Colors.Black);
        wb.Invalidate();
        wb.Render(temporaryImage, new TranslateTransform { X = destX, Y = destY });
        wb.Invalidate();
我应该指出,要执行.Clear(),我使用的是WriteableBitmapEx项目


有什么想法吗?

我不是图像处理专家,但在这种情况下,
Blit
函数似乎很有用。不要试图渲染
临时图像
,而是创建一个新的
可写位图
,将
清空水印
作为其源。使用此WriteableBItmap作为
参数和
wb
作为
Dest
参数,并对两个WriteableBItmap进行blit。(Blit
Blit
功能附带了
WriteableBitmapEx
)。

您的临时图像尚未执行布局,因此渲染时仍为空白。要解决这个问题,你应该称之为测量和安排,这并不总是可靠的,但将其包装在一个边界中,测量和安排似乎是有效的

所有这些都是说,因为您已经在使用WriteableBitmapEx,所以您可以使用它的Blit方法

WriteableBitmap emptyTile = new WriteableBitmap(emptyTileWatermark);
//create writeableBitmap
WriteableBitmap wb = new WriteableBitmap(outputWidth, outputHeight);
wb.Clear(Colors.White);

// Closed green polyline with P1(0, 0), P2(outputWidth, 0), P3(outputWidth, outputHeight) and P4(0, outputHeight)
var outline = new int[] { 0, 0, outputWidth, 0, outputWidth, outputHeight, 0, outputHeight, 0, 0};
wb.DrawPolyline(outline, Colors.Black);
wb.Blit(new Rect(destX,destY,destWidth,destHeight),emptyTile,new Rect(0,0,emptyTileWatermark.PixelWidth,emptyTileWatermark.PixelHeight));