[英]silverlight draw on bitmap
Image img = new Bitmap(Image.FromFile(file.FullName));
using (Graphics g = Graphics.FromImage(img)){
g.DrawRectangle(Pens.Black, 0, 0, img.Width - 2, img.Height - 2);
}
像這樣
在白光下怎么辦?
使用WriteableBitmap
類。
使用WritableBitmap
,您可以在Control
或Canvas
上繪制一些東西,然后使用其public WriteableBitmap(UIElement element,Transform transform)
構造函數將其保存到位圖。
您無需將SL矩形渲染到WriteableBitmap中。 WriteableBitmapEx開源庫非常適合此操作。 請參見項目站點,以獲取DrawRectangle方法的示例。 http://writeablebitmapex.codeplex.com
也有實時樣本,包括Shape樣本 。
您還可以在源代碼存儲庫中找到樣本的代碼。
您可以為此使用WriteableBitmap 。 創建一個Canvas並在Canvas上繪制元素,加載其他圖像等。然后在Canvase上完成渲染后,您可以從Canvas創建WriteableBitmap,然后執行所需的所有操作。
在下面的示例中,我將位圖分配為Image
元素的Source
,以顯示最終結果。
Canvas canvas = new Canvas();
UIElement ellipse = new Ellipse()
{ Width = 100, Height = 100, Fill = new SolidColorBrush(Colors.Red) };
Canvas.SetLeft(ellipse, 100);
Canvas.SetTop(ellipse, 100);
canvas.Children.Add(ellipse);
WriteableBitmap bmp = new WriteableBitmap(canvas, null);
myImage.Source = bmp;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.