Home All Groups Group Topic Archive Search About

Adding points to a bitmap

Author
2 Jul 2005 6:14 PM
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

Author
4 Jul 2005 8:57 AM
John Dann
Anyone able to help please?

JGD
Author
4 Jul 2005 9:46 AM
Larry Lard
John Dann wrote:
Show quoteHide quote
> 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).

--
Larry Lard
Replies to group please
Author
4 Jul 2005 12:44 PM
Supra
http://www.vbdotnetheaven.com/Sections/GDI+.asp

John Dann wrote:

Show quoteHide quote
>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

>