scanning

IxiRancid

Well-known member
Joined
Jun 16, 2004
Messages
104
Location
Europe
OK, I got the WIA thingy working etc. Now I have a problem. My app scans predefined forms which contain a small square for a signature and a paraf. Signature is divided from the paraf with a thin black line.

heres how the process goes:
1. scan a picture with a WIA compatible scanner
2. save entire A4 image in TIFF
3. again with WIA I crop the abovementioned square + save the Tiff and delete the original one, and load the crop into PictureBox
4. then I do this
Code:
Private Sub pictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)
        Dim g As Graphics = e.Graphics
        g.FillRectangle(System.Drawing.Brushes.White, 529, 0, 7, PictureBox1.Bottom)
    End Sub
the dividing line of the square is gone :)

then this:
Code:
Dim img As Image
        img = PictureBox1.Image
        img.Save("C:\enaa.TIFF", ImageFormat.Tiff)

It doesnt save the picture WITHOUT the dividing line (step 4. is ignored, although I see the picture after fillRectangle just as I want it!)

The question? How can I save my image from PicBox as I see it, with the dividing line cleared? If you like I can post some sample pics.
 
The picturebox has an image property. It also has a surface like all controls that you can paint on. The two have nothing to do with each other. In your picturebox paint event you draw on the surface of the picturebox. There is no way to capture this drawing on the surface easily (need to capture the screen). The image property of the picturebox holds a bitmap and this is not effected by the drawing you did on the surface.
What you should do is:

load the cropped image into a bitmap
create a graphics from the bitmap
draw with the graphics onto the bitmap
save the bitmap, set the picturebox.image property to the bitamp
no need to do anything in the paint event.

something like:
Code:
dim bm as bitmap = bitmap.fromfile("cropped.tiff")
dim g as graphics = graphics.fromimage(bm)
g.FillRectangle(System.Drawing.Brushes.White, ????? )
bm.Save("C:\enaa.TIFF", ImageFormat.Tiff)
picturebox1.image = bm
 
Well, thats nice! I dont really even want to show the picture in the Box, so this is a fine solution.
Didnt know about the surface and image below!

Thanks!
 
Ok, I tried it and had this error:
<A generic error occurred in GDI+>

went to this page
KB article
and then added a new save name for the file (& "1.TIFF"), the code as it follows:
Code:
Dim bm As Bitmap = Bitmap.FromFile(usr_profile & "\desktop\" & imepriimek & ".TIFF")
        Dim g As Graphics = Graphics.FromImage(bm)
        g.FillRectangle(System.Drawing.Brushes.White, 529, 0, 7, bm.Height)
        bm.Save(usr_profile & "\desktop\" & imepriimek & "1.TIFF", ImageFormat.Tiff)
and delete the original cropped file.
 
Back
Top