是否有任何能够在Windows 8.1移动设备上签名文档的能力?像用户可以用手或手写笔绘制签名的画布。是否有任何XAML控制这个任务或其他东西?通用Windows 8.1中的用户签名应用程序
0
A
回答
0
我一直在为这一天的最好的一段而努力。看来,内置墨曾经是在Windows Phone 7和8.0可被拉出8.1
我使用的技术在文章中通过克里斯W¯¯指出,以使该可控制控制添加到页面的XAML并处理其他所有内容。
神奇的是在WritableBitmap和PointerPressed和PointerMoved方法中。
using Windows.Foundation;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
namespace ProofOfConcept.App.Controls
{
public class SignatureCaptureControl : Canvas
{
private WriteableBitmap _writeableBitmap;
private Point _currentPoint;
private Point _oldPoint;
public SignatureCaptureControl()
{
_writeableBitmap = new WriteableBitmap(300, 130);
PointerPressed += SignatureCaptureControl_PointerPressed;
PointerMoved += SignatureCaptureControl_PointerMoved;
}
private void SignatureCaptureControl_PointerPressed(object sender, PointerRoutedEventArgs e)
{
_currentPoint = e.GetCurrentPoint(this).Position;
_oldPoint = _currentPoint;
}
void SignatureCaptureControl_PointerMoved(object sender, PointerRoutedEventArgs e)
{
_currentPoint = e.GetCurrentPoint(this).Position;
_writeableBitmap.DrawLine((int)_currentPoint.X, (int)_currentPoint.Y, (int)_oldPoint.X, (int)_oldPoint.Y, PenColor);
this.InvalidateArrange();
_oldPoint = _currentPoint;
}
public void ClearSignature()
{
_writeableBitmap.Clear();
}
}
}
使用下面所述的控制将显示一个300x130白盒作为手指或指示笔拖过它,这将画线。
<Border Background="White">
<controls:SignatureCaptureControl Height="130" Width="300"/>
</Border>
要获得的图像出我们必须提取从WritableBitmap的像素数据,然后对其进行编码为位图/ GIF/JPEG/PNG /等。
public Task<byte[]> ReadAsPngImageAsync()
{
return ReadImageFromWritableBitmapAsync(_writeableBitmap, Windows.Graphics.Imaging.BitmapEncoder.PngEncoderId);
}
internal static async Task<byte[]> ReadImageFromWritableBitmapAsync(Windows.UI.Xaml.Media.Imaging.WriteableBitmap writeableBitmap, Guid encoderId)
{
var rawPixels = await ConvertBitmapToByteArrayAsync(writeableBitmap);
var encodedPixels = await EncodePixels(rawPixels, encoderId, (uint)writeableBitmap.PixelWidth, (uint)writeableBitmap.PixelHeight);
return encodedPixels;
}
private static async Task<byte[]> ConvertBitmapToByteArrayAsync(Windows.UI.Xaml.Media.Imaging.WriteableBitmap bitmap)
{
using (var stream = bitmap.PixelBuffer.AsStream())
{
var pixels = new byte[(uint)stream.Length];
await stream.ReadAsync(pixels, 0, pixels.Length);
return pixels;
}
}
private static async Task<byte[]> EncodePixels(byte[] signaturePixels, Guid encoderId, uint pixelWidth, uint pixelHeight)
{
using (var randomAccessStream = new Windows.Storage.Streams.InMemoryRandomAccessStream())
{
var encoder = await Windows.Graphics.Imaging.BitmapEncoder.CreateAsync(encoderId, randomAccessStream);
encoder.SetPixelData(Windows.Graphics.Imaging.BitmapPixelFormat.Bgra8, Windows.Graphics.Imaging.BitmapAlphaMode.Premultiplied,
pixelWidth, pixelHeight,
96, 96, signaturePixels);
await encoder.FlushAsync();
using (var stream = randomAccessStream.GetInputStreamAt(0))
{
var pixels = new byte[(uint)randomAccessStream.Size];
stream.AsStreamForRead().Read(pixels, 0, pixels.Length);
return pixels;
}
}
}
现在我们有了代表以标准形式的图像,我们可以简单地将数据保存到本地存储或提交到服务的字节数组。
+0
嗨,你好,你有一个项目以控制为例?谢谢 – Juan 2015-07-16 15:17:30
相关问题
- 1. Windows Phone 8.1应用签名
- 2. Windows Phone 8.1到通用应用程序
- 3. Windows 8.1通用应用程序文档
- 4. Windows 8.1通用应用程序参考
- 5. 开始应用商店 - 用于Windows Phone 8.1和Windows 8.1应用程序的通用应用程序
- 6. 为Windows 8.1开发适用于Windows 8.1的通用应用程序
- 7. Windows 8.1中的通用应用程序的WebClient替代
- 8. ApplicationData.ClearAsync()在Windows 8.1中不起作用通用应用程序
- 9. Windows Phone应用程序8.1中的Epub
- 10. Windows 8.1中的UnmanagedType.CustomMarshaler应用程序
- 11. Windows 8.1应用程序中的态度
- 12. Windows 8.1中的应用程序崩溃
- 13. 通用应用程序中的Windows 8.1 WPF控件
- 14. Windows 10中的通用应用程序8.1
- 15. Cocos2dx中的PubCenter/Admob C++ Windows 8.1通用应用程序
- 16. 在Windows Phone 8.1中获取用户数据通用应用程序
- 17. 在Windows Phone 8.1中替换MediaPlayerLauncher通用应用程序
- 18. 布局conrols开发通用应用程序在Windows 8.1中
- 19. 在Windows Phone 8.1通用应用程序中设置起始页
- 20. 在Windows 8.1通用应用程序中创建选项卡
- 21. Windows应用商店应用8.1的代码签名
- 22. Windows上的Android签名应用程序
- 23. 新的Windows Phone 8.1 Silverlight应用程序
- 24. RegionInfo在Windows 8.1的应用程序
- 25. Windows Phone:如何签名应用程序
- 26. 使用Windows Store应用程序创建新的Windows 8/8.1用户
- 27. 用于开发Windows Phone 8.1和通用Windows应用程序的环境
- 28. Facebook集成在Windows 8.1通用应用程序
- 29. Windows Phone 8.1通用应用程序:清除Cookies
- 30. Windows Phone 8.1通用应用程序:ManipulationCompleted事件不会触发
听起来像你正在寻找[这样的事情](http://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh974457.aspx) – 2014-12-02 17:12:22