Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

 

here's 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

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:

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

 

It doesn't 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.

Posted

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:

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

Posted

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:

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.

Posted
Just a cautionary notice, when using a Graphics object you should always remember to call the Dispose method when your done with it.
Anybody looking for a graduate programmer (Midlands, England)?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...