Hello guys,

Can someone help me? I have a scanned document in my system. It's a tiff file.
You will see below the code i have written. The problem is that i get an error message.
The message is like this "A Graphics object cannot be created from an image that has an indexed pixel format."

My code is this:

Private Sub drawnOnPic(ByVal xpos As Integer, ByVal ypos As Integer)

imgDocument.Image = Image.FromFile(pathName & "\" & veranderImageNaam)
Dim g As Graphics = Graphics.FromImage(imgDocument.Image)

Dim Penstyle As New Pen(Color.Red, 5)
g.DrawRectangle(Penstyle, xpos, ypos, 600, 175)

End Sub

Recommended Answers

All 3 Replies

I have no problem drawing graphics on a .tif image file by using your code.

Have you tried to save the image as a different format before loading it into your PictureBox and drawing the graphics on it?

I have already tried saved the same tif file like a jpeg file. But it gives me the same error

If possible, attach the scanned image File on your next reply.

I'm scanner-less. :cool:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.