2011-03-04 52 views
1

以下代码适用于Windows窗体。 我该怎么做到Silverlight? 我想没有图形对象。从Windows窗体到Silverlight的图形?

 

Bitmap bm = new Bitmap(600, 600); 
Graphics g = Graphics.FromImage(bm); 
Brush b = new LinearGradientBrush(
new Point(1, 1), new Point(600, 600), 
Color.White, Color.Red); 
Point[] points = new Point[] 
{new Point(10, 10), 
new Point(77, 500), 
new Point(590, 100), 
new Point(250, 590), 
new Point(300, 410)}; 
g.FillPolygon(b, points); 
bm.Save("testandoImagem.jpg", ImageFormat.Jpeg); 

 

回答

2

艾伦,即使从SL客户端应用程序,你可以做到这一切的服务器端,你是不是显示用户界面什么,我会把这段代码中具有完全访问.NET业务层框架。请记住,从SL你不能直接保存在客户机上,所以你应该用另一种方式。

1

您可以将形状渲染为WriteableBitmap,但Silverlight没有内置的支持将数据编码为JPEG。

看到这些StackOverflow的问题:

How to save BitmapImage/WriteableBitmap using SaveFileDialog in Silverlight 3.0?

Best Jpeg Encoder for Silverlight 4.0

http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.writeablebitmap.render(v=VS.95).aspx

 WriteableBitmap wb = new WriteableBitmap(600, 600); 
     Polygon p = new Polygon(); 
     p.Points = new PointCollection() { new Point(10, 10), new Point(77, 500), new Point(590, 100), new Point(250, 590), new Point(300, 410) }; 
     p.Fill = new LinearGradientBrush() 
     { 
      //Gradient angle is 0,0 to 1,1 by default 
      GradientStops = new GradientStopCollection() { 
       new GradientStop() { Color = Colors.White, Offset = 0 }, 
       new GradientStop() { Color = Colors.Red, Offset = 1 } } 
     }; 

     wb.Render(p, null); 
     wb.Invalidate(); 

     //Save WriteableBitmap as described in other questions