graphics object probs (same as 2 weeks ago)

  • Thread starter Thread starter EricJ
  • Start date Start date
E

EricJ

back at the saturday job ;)

all help is welcome ( if there is an other way of doing this i don't mind as
long as it works)

i have to compose an image in code.
I have a background image (a bitmap but i can convert it if needed) and an
image of a cross (bit like the close button on an xp form)
i have to place the cross a limited nr of times on the background image at
specific coordinates
when this is done i have to save the new image w crosses in an sql db (this
should not be a prob)

code below

when i try to get the graphicsfrom the bitmap i get an error :
Graphics object cannot be created from an image that has an indexed pixel
format.

tnx in advance

eric

Private schGra As Graphics

Try
Dim s As System.Drawing.Image
s = System.Drawing.Image.FromFile("F:\OvrAlles4.bmp")
schGra = Graphics.FromImage(s) ' this gives the error
Dim kr As New Bitmap(imgLijst.Images(0))
Dim t As Image
t = imgLijst.Images(0)
For i As Integer = 0 To 100
If kruisjes(i).Visible Then
schGra.DrawImage(t, (kruisjes(i).Left),
(kruisjes(i).Top))
'schGra.DrawImage()

End If
Next
PictureBox1.Image = s
Catch ex As Exception
MessageBox.Show(ex.HelpLink & " " & ex.Message & " button2 klik
", "fout", MessageBoxButtons.OK)
End Try
 
Hi Eric,

Did I just write today that you would not be here this weekend are you here.

This code I extracted from that program I did made, it is not the same and I
did change some things about the rectangle's, but with that you see how that
goes with the bitmap. In your program I thought you are missing that layer
for the bitmap.

Maybe Herfried correct that because in this area I am very a newbie.

\\\
Dim fdlOpen As New OpenFileDialog
Dim origineleImage As Image
Dim nieuweImage As Image
fdlOpen.Filter = "All Image Formats (*.bmp;*.jpg;*.jpeg;*.gif;*.tif)|" & _
"*.bmp;*.jpg;*.jpeg;*.gif;*.tif|Bitmaps
(*.bmp)|*.bmp|" & _
"GIFs (*.gif)|*.gif|JPEGs (*.jpg)|*.jpg;*.jpeg|TIFs
(*.tif)|*.tif"
If fdlOpen.ShowDialog() = DialogResult.OK Then
origineleImage = Image.FromFile(fdlOpen.FileName)

'Before this is just that you could copy that, than would you not have to
write
' it again I am always strugling with that mask.

Dim bmp As Bitmap = New Bitmap(origineleImage.Width,
origineleImage.Height)
Dim grBitmap As Graphics = Graphics.FromImage(bmp)
grBitmap.DrawImage(origineleImage, origineleImage.Width,
origineleImage.Height)
nieuweImage = bmp
grBitmap.Dispose()
End If
///
 
* "EricJ said:
all help is welcome ( if there is an other way of doing this i don't mind as
long as it works)

i have to compose an image in code.
I have a background image (a bitmap but i can convert it if needed) and an
image of a cross (bit like the close button on an xp form)
i have to place the cross a limited nr of times on the background image at
specific coordinates
when this is done i have to save the new image w crosses in an sql db (this
should not be a prob)

code below

when i try to get the graphicsfrom the bitmap i get an error :
Graphics object cannot be created from an image that has an indexed pixel
format.

You will have to create a new bitmap object with non-indexed pixel
format, obtain a 'Graphics' object for it and paint the indexed bitmap
onto this image.
 
Hi Herfried,

Do us a favor and check my sample that I did send to Eric, this is a result
what I did made after that sample from Fergus, and maybe there is much to
much in it (this is not what Fergus did made but something else that I made
from the documentation).

And this is (one of ) your specialities.

Cor
 
its working :)
if you want to you can come over (westerlo belgium) free drinks for you ;p,
we'll trow in a chinese dinner ;) (stuur maar een mailtje als je
geïnteresseerd bent)

i still have a scaling problem but i'm going to try it myself first.

eric
 
* "Cor said:
Do us a favor and check my sample that I did send to Eric, this is a result
what I did made after that sample from Fergus, and maybe there is much to
much in it (this is not what Fergus did made but something else that I made
from the documentation).

Your code is ok.

;-)
 
Hi Eric,

I am much honoured by your inventation but am not able to accept, but it is
really a very nice inventetion.

Thanks

Cor
 
we had been struggeling on that one for a while :)
ps the scale thing is also working, a bit more parameters on the drawimage
 
Hi Eric

I hope you got a good time.

OHM had in this newsgroup something that he could buy Stella cheap in
England. I did not give comments because than maybe I had made him unhappy.

:-)

The scaling was the Rectangle I gues, did you see that the thumbnail is also
very usefull.

Cor
 
OHM had in this newsgroup something that he could buy Stella cheap in
England. I did not give comments because than maybe I had made him unhappy.

:-)
stella from the source ;p
i'm more of a palm hoegaarden type ;p
The scaling was the Rectangle I gues, did you see that the thumbnail is also
very usefull.

Cor

i saw that 2 but i managed using a constructor w top,left,width and height
(seting those to the size of the picbox used to place the crosses, before
herfried jumps in no i couldn't take a screenshot of that becouse the image
has other colours ...) ;)

once you know it its easy, but there isn't a lot of documentation to get to
know it :/ .

eric
 
Back
Top