如何从inkcanvas直接获取位图图像(在wpf中)

发布于 2024-11-26 20:29:01 字数 169 浏览 2 评论 0原文

我正在做一个 OCR 项目。我必须从 inkcanvas 的输入中获取图像以在下一步中进行处理,即将该图像转换为二维数组。

我对如何从 inkcanvas 获取位图图像进行处理感到困惑。我一直在从许多来源寻找解决方案,但其中很多只是将 inkcanvas 保存到文件流中。

请帮我! 非常感谢

I am doing an OCR project. I must to get an image from input in inkcanvas to process in the next step, i.e. translate this image to an two-dimension array.

I am confused about that how to get a bitmap image from inkcanvas to process. I have been searching for a solution from many sources but a lot of them just save the inkcanvas to file-stream.

please help me!
thanks so much

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

贪了杯 2024-12-03 20:29:01

我知道这个问题比较旧,但我还必须从墨水画布中获取位图。因此,要回答如何直接从墨水画布获取位图的问题,这里有一个解决方案。希望它仍然有帮助。

    private System.Drawing.Image ConvertInkCanvasToImage()
    {

      //create temporary InkCanvas or send it in as a parameter
      InkCanvas inkCanvas = new InkCanvas();      
      inkCanvas = viewModel.InkCanvas;

      //render bitmap
      RenderTargetBitmap rtb = new RenderTargetBitmap((int)inkCanvas.ActualWidth, (int)inkCanvas.ActualHeight, 96, 96, System.Windows.Media.PixelFormats.Default);
      rtb.Render(inkCanvas);
      BmpBitmapEncoder encoder = new BmpBitmapEncoder();
      encoder.Frames.Add(BitmapFrame.Create(rtb));
      rtb.Render(inkCanvas);

      //save to memory stream or file 
      System.IO.MemoryStream ms = new System.IO.MemoryStream();
      encoder.Save(ms);  

      //creat bitmap with memory stream or file
      Bitmap bitmap = new Bitmap(ms);
      return bitmap;
    }

I know this question is older but I also had to get a bitmap from the ink canvas. So to answer the question on how to get a bitmap directly from the ink canvas, here is a solution. hope it still helps.

    private System.Drawing.Image ConvertInkCanvasToImage()
    {

      //create temporary InkCanvas or send it in as a parameter
      InkCanvas inkCanvas = new InkCanvas();      
      inkCanvas = viewModel.InkCanvas;

      //render bitmap
      RenderTargetBitmap rtb = new RenderTargetBitmap((int)inkCanvas.ActualWidth, (int)inkCanvas.ActualHeight, 96, 96, System.Windows.Media.PixelFormats.Default);
      rtb.Render(inkCanvas);
      BmpBitmapEncoder encoder = new BmpBitmapEncoder();
      encoder.Frames.Add(BitmapFrame.Create(rtb));
      rtb.Render(inkCanvas);

      //save to memory stream or file 
      System.IO.MemoryStream ms = new System.IO.MemoryStream();
      encoder.Save(ms);  

      //creat bitmap with memory stream or file
      Bitmap bitmap = new Bitmap(ms);
      return bitmap;
    }
潦草背影 2024-12-03 20:29:01

检查这篇博文:
http://www.centrolutions .com/Blog/post/2008/12/09/Convert-WPF-InkCanvas-to-Bitmap.aspx

这将为您提供位图的字节数组,因为你正在做 OCR,这应该足够了。

Check this blog post:
http://www.centrolutions.com/Blog/post/2008/12/09/Convert-WPF-InkCanvas-to-Bitmap.aspx

That gets you a byte array for the bitmap, since you're doing OCR that should be enough.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文