tags:

views:

27

answers:

2

how can i change the background color of a picture saving from a picturebox in vb.net.In my form there is a drawing section.after drawing i am saving the picture as jpeg.but the image's background color is black.so i can't see anything that i have drawn.the drawing pen color is also black.if anyone knows please help me.thank you.

+1  A: 

I would say that the easiest way is to paint the background when the image object is created (sample initializing the background to being white):

Dim theImage As Image = New Bitmap(someWidth, someHeight)
Using g As Graphics = Graphics.FromImage(theImage)
    g.Clear(Color.White)
End Using
Fredrik Mörk
thank you very much.its also working good.when i click the clear button the image will gone.but after i trying to draw a new one i can't draw.because i initialize the picture as picturebox1.image=new bitmap....etc in the form load.where can i place this code?thank you
I would move the initialization of the image to a separate method that you call from Form_Load, and also from the click event of the Clear button.
Fredrik Mörk
thank you very much
i added the initialization of the image in the form_load and the click event of the clear button.but when i click the clear button the image will cleared and at the mouse move on the picturebox the last drawned image will shawn .if you can please help me,and how can i validate the picturebox is empty means i doesn't want to permit to save a empty image.thank you
A: 

To use this the following code:

OpenFileDialog1.Filter = "Bmp Files(.bmp)|.bmp|Gif Files(.gif)|.gif|Jpg Files(.jpg)|.jpg" OpenFileDialog1.ShowDialog() Textbox1.Text = OpenFileDialog1.FileName PicText.Image = Image.FromFile(OpenFileDialog1.FileName)

sakthivignesh