您好我已创建了一个Silverlight应用程序,允许用户键入其名称,选择日期并签名(签名条)。我希望添加到我已经创建的webform。我使用网格上的silverlight中的borderInk和inkP工具构建签名条。但是我不知道如何保存图像。我想将它存储在我已经创建的数据库中。我还想将silverlight应用程序附加到我创建的webforms中。有关如何做到这一点的任何帮助??
答案 0 :(得分:0)
答案 1 :(得分:0)
您应该将绘图表面元素(网格)渲染到位图并保存结果。
示例方法应获取元素并返回jpeg图像的字节
private byte[] RenderToJpeg(FrameworkElement element)
{
using (var stream = new MemoryStream())
{
var bmp = new WriteableBitmap(element, null);
bmp.SaveJpeg(stream, bmp.PixelWidth, bmp.PixelHeight, 0, 90);
stream.Flush();
return stream.ToArray();
}
}
答案 2 :(得分:0)
如果您使用OpenFileDialog
保存图片,这可以帮助您。
decimal _imagementSize = 0;
string _imageName = "";
string _imageType = "";
Binary _image;
OpenFileDialog dialog=new OpenFileDialog();
private void btnSaveImage_Click(object sender, RoutedEventArgs e)
{
dialog.Multiselect = false;
dialog.Filter = "All Files | *.*";
if (dialog.ShowDialog() == true)
{
bool fileExist = dialog.File.Exists;
if (fileExist)
{
UploadFile();
}
}
}
private void UploadFile()
{
double fileLength = 0;
var stream = dialog.File.OpenRead();
var bnr = new BinaryReader(stream);
byte[] buffer = new byte[stream.Length + 1];
buffer = bnr.ReadBytes((int)stream.Length);
fileLength = stream.Length;
_imageName = dialog.File.Name;
_imageType = dialog.File.Extension;
_imageSize = (decimal)(fileLength / 1024);
_image = new Binary() { Bytes = buffer };
}
如果您使用WCF service
保存图片,则只需发送_image
和WCF method
喜欢
[OperationContract]
public void SaveImage(System.Data.Linq.Binary _image)
{
//save image to DB or enything
}