2016-08-15 47 views

回答

0

檢查此鏈接:

How to add wartermark text/image to a bitmap in Windows Store app

或者更好地利用Win2D庫(你可以找到它的NuGet)和摘錄如下:

CanvasDevice device = CanvasDevice.GetSharedDevice(); 
CanvasRenderTarget offscreen = new CanvasRenderTarget(device, 500, 500, 96); 

cbi = await CanvasBitmap.LoadAsync(device, "mydog.jpg"); 

using (var ds = offscreen.CreateDrawingSession()) 
{ 
    ds.DrawImage(cbi); 

    var format = new CanvasTextFormat() 
    { 
    FontSize = 24, 
    HorizontalAlignment = CanvasHorizontalAlignment.Left, 
    VerticalAlignment = CanvasVerticalAlignment.Top, 
    WordWrapping = CanvasWordWrapping.Wrap, 
    FontFamily = "Tahoma" 
    }; 

var tl = new CanvasTextLayout(ds, "Some text", format, 200, 50); // width 200 and height 50 

ds.DrawTextLayout(tl, 10, 10, Colors.Black); 

tl.Dispose(); 
} 

using (var stream = new InMemoryRandomAccessStream()) 
{ 
    stream.Seek(0); 
    await offscreen.SaveAsync(stream, CanvasBitmapFileFormat.Png); 

    BitmapImage image = new BitmapImage(); 
    image.SetSource(stream); 
    img.Source = image; 
} 
相關問題