2011-06-14 16 views
2

나는 흰색 사각형 (100 x 200)을 그리고 중간에 작은 이미지 (50 x 75)를 그려서 재생중인 카드의 뒷면과 비슷하게 보이려고합니다.오버레이 이미지가 다른 오버레이 이미지

다음 코드를 사용하면 주변에 테두리가 있지만 이미지가없는 타일을 얻을 수 있습니다.

 //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 프로젝트를 사용하고 있습니다.

어떤 아이디어 ???

답변

2

임시 이미지의 레이아웃이 수행되지 않아서 렌더링 할 때 여전히 비어 있습니다. 이것을 교정하기 위해서는 Measure and Arrange를 호출해야합니다. 이것은 항상 신뢰할만한 것은 아니지만 Border에 배치하고 측정하고 정렬하는 것입니다.

이미 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)); 
+0

완벽하게 작동합니다! 고맙습니다! –

0

저는 이미지 처리 전문가가 아니지만이 경우에는 Blit 기능이 유용 할 것으로 보입니다. temporaryImage을 렌더링하는 대신 emptyTileWatermark을 소스로 사용하여 WriteableBitmap을 새로 만듭니다. 이 WriteableBItmap을 Source 매개 변수로 사용하고 wbDest 매개 변수로 사용하고 두 개의 WriteableBitmaps를 blit하십시오. (Blit 기능은 WriteableBitmapEx과 함께 제공됩니다).