crop image to picturebox

superbem

Member
Joined
May 17, 2007
Messages
22
Programming Experience
10+
I'm trying to crop a rectangle area from an image.
A simple cut/paste.

Anyone can help me?
 

superbem

Member
Joined
May 17, 2007
Messages
22
Programming Experience
10+
I found how:

PHP:
    Public Sub hello()
        Dim bmp As New Bitmap(2000, 2000)
        Dim srcRect As New RectangleF(100, 90, 300, 50)
        Dim g As Graphics = Graphics.FromImage(bmp)
        g.DrawImage(Image.FromFile("image.jpg"), 0, 0, srcRect, GraphicsUnit.Pixel)
        PictureBox1.Image = bmp
        ocrRegion(g) ' How to do this? I tried ocrRegion(bmp) it fails also
    End Sub

What I want is the ocr engine only ocr that region, but it want to be from a filename, is there a way to do this without saving the crop to a file?

PHP:
    Public Sub ocrRegion(ByVal bmp)
        Dim doc As MODI.Document
        Dim img As MODI.Image
        doc = CType(CreateObject("MODI.Document"), MODI.Document)
        doc.Create(bmp) ' PROBLEM RELIES HERE
        doc.OCR(MODI.MiLANGUAGES.miLANG_ENGLISH, True, False)
        For i As Integer = 0 To doc.Images.Count - 1
            img = CType(doc.Images.Item(i), MODI.Image)
            Me.RichTextBox1.Text += img.Layout.Text()
        Next
        doc.Close()
        doc = Nothing
    End Sub

Thanks in advance
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,583
Location
Norway
Programming Experience
10+
I don't know MODI, but it looks as you want to pass a Bitmap (bmp) to that Sub ocrRegion, but you are passing a Graphics (g), maybe something to consider.
 

superbem

Member
Joined
May 17, 2007
Messages
22
Programming Experience
10+
I tried that, it don't worked.
If I save to a temp file it work, but that's no good job I think, but if it aren't another way... Is there other way? :(

I'm having some problems converting types, now I just want to resize images to restrain all to same size, how to do that?
 
Last edited:

waynespangler

Well-known member
Joined
Apr 5, 2006
Messages
46
Location
West Virginia, USA
Programming Experience
10+
I don't know if this helps or not but try changing the following:
VB.NET:
ocrRegion(g)
and
Public Sub ocrRegion(ByVal bmp)
to
VB.NET:
ocrRegion(bmp)
and
Public Sub ocrRegion(ByVal bmp As Bitmap)

and also what does your documnetation say on doc.create()? Does it take a bitmap?
 
Last edited:
Top Bottom