Adding points to a bitmap

J

John Dann

I've never had much cause to read up in detail on GDI+ but there's a
small piece of a project where I need to add some annotation (let's
say just some small filled rectangles as markers) to a pre-existing
bitmap and then resave the bitmap. I've tried several ways of doing
this but they either don't work or give errors. Anyone able to help me
out please?

The sort of thing I'm doing is:

Dim MyBMP as Bitmap = Bitmap.Fromfile(MyFileLocation)

then I've tried eg

Dim gr as graphics = MyBMP.Creategraphics

but get a runtime error that I can't use a bitmap with indexed pixels.

I was then simply hoping to be able to say:

gr.FillRectangle(brushdetails, rectangledetails)

MyBMP.Save(AnnotatedFile)

I could go on with the various bits of code I've tried but while I'm
presuming that there is a simple approach to this, my attempts
obviously haven't hit on the right combination.

Thanks for any help.
JGD
 
L

Larry Lard

John said:
I've never had much cause to read up in detail on GDI+ but there's a
small piece of a project where I need to add some annotation (let's
say just some small filled rectangles as markers) to a pre-existing
bitmap and then resave the bitmap. I've tried several ways of doing
this but they either don't work or give errors. Anyone able to help me
out please?

The sort of thing I'm doing is:

Dim MyBMP as Bitmap = Bitmap.Fromfile(MyFileLocation)

then I've tried eg

Dim gr as graphics = MyBMP.Creategraphics

but get a runtime error that I can't use a bitmap with indexed pixels.

This seems to be the heart of the problem. From what I have read,
bitmap formats with indexed colors are not given equal treatment by
GDI+. If possible, I would suggest having the original image altered
into a non-indexed bitmap format (eg 24 bits per pixel), then you will
be able to do

Dim gr As Graphics = Graphics.FromImage(MyBMP)

and proceed as you had intended.

You might find more useful info at Bob Powell's GDI+ site (google).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top