从流访问图片框

Accessing Picturebox From Stream

如何从代码的 ocr.Image = img 位访问 picturebox1。如果我使用

加载它,我就能正常工作

ocr.Image = ImageStream.FromFile("C:/Users/John/Pictures/3.jpg"); // 把图片给库

但显然这不是我想要达到的目标。

错误是:

cannot implicitly convert type system.drawing.image to apose.ocr.iimagestream

 private void timer1_Tick(object sender, EventArgs e)
        {


            //SendKeys.Send("{PRTSC}");
            Image img = Clipboard.GetImage();
            pictureBox1.Image = img;


            //ocr processing

            ocr.Image = img;  // Give the image to the library
            if (ocr.Process()) // Start processing it
            {
                label1.Text = "Text: " + ocr.Text;
            }
        }

试试这个:

if(img!=null)
{
    var ms = new MemoryStream();
    img.Save(ms, ImageFormat.Jpeg); // put here the image format
    ms.Position = 0;

    ocr.Image = ImageStream.FromStream(ms,ImageStreamFormat.Jpg);
    ..
    ..//all your processing stuff
}