C#Webrequest上传文件并继续

时间:2014-02-01 08:57:40

标签: c# file upload webrequest

如何将简单图像上传到www.newocr.com,从下面的组合框中选择一种语言,单击“上传”按钮,然后点击“OCR”按钮,最后从源代码中获取字符串,然后存储字符串成为id

所有以编程方式。有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

点击此链接:

这可以帮助你::

OCR reading using C#

http://www.codeproject.com/Questions/157546/C-OCR-How-to-Read-a-single-character-from-image 试试这个:

Bitmap BWImage = new Bitmap(fileName);
// Lock destination bitmap in memory
System.Drawing.Imaging.BitmapData BWLockImage = BWImage.LockBits(new Rectangle(0, 0, BWImage.Width, BWImage.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, PixelFormat.Format1bppIndexed);

// Copy image data to binary array
int imageSize = BWLockImage.Stride * BWLockImage.Height;
byte[] BWImageBuffer = new byte[imageSize];
Marshal.Copy(BWLockImage.Scan0, BWImageBuffer, 0, imageSize);
DoOCR(BWLockImage, BWImageBuffer, tmpPosRect, false);



// Do the OCR with this function
public string DoOCR(System.Drawing.Imaging.BitmapData BWLockImage, byte[] BWImageBuffer, Rectangle iAusschnitt, bool isNumber)
{
    Bitmap tmpImage = Bildausschnitt1bpp(BWLockImage, BWImageBuffer, iAusschnitt);
    string file = Path.GetTempFileName();
    string tmpResult = "";
    try
    {
        tmpImage.Save(file, ImageFormat.Tiff);
        _MODIDocument.Create(file);
        // Modi parameter erstellen
        _MODIDocument.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, false, false);

        MODI.IImage myImage = (MODI.IImage)_MODIDocument.Images[0]; //first page in file
        MODI.ILayout myLayout = (MODI.ILayout)myImage.Layout;
        tmpResult = myLayout.Text;
    }
    catch
    {
        if (_MODIDocument != null)
        {
            _MODIDocument.Close(false); //Closes the document and deallocates the memory.
            _MODIDocument = null;
        }
        // Bild freigeben
        tmpImage.Dispose();
        tmpImage = null;
        // Garbage Collector ausführen
        GC.Collect();
        // Bilddatei löschen
        File.Delete(file);
    }
    return tmpResult;
}