Hi Vicky,
Your code is correct as far as I can see, although I cannot reproduce your
code as the modify and wire data is unknown. The error would indicate you
are not producing a regular bitmap so if you are doing additional stuff to
the bitmap I would check that code.
Below is some reference code that should produce a 100x100 bitmap with a red
80x80 rectangle in the middle. This rectangle is also painted in a Panel
control using the exact same drawing code.
public Form1()
{
InitializeComponent();
panel1.Paint += new PaintEventHandler(panel1_Paint);
}
void panel1_Paint(object sender, PaintEventArgs e)
{
drawwire(e.Graphics);
}
public void drawwire(Graphics gr)
{
gr.FillRectangle(Brushes.Red, 10, 10, 80, 80);
}
private void button1_Click(object sender, EventArgs e)
{
Bitmap print = new Bitmap(100, 100);
using (Graphics pri = Graphics.FromImage(print))
{
drawwire(pri);
}
print.Save("C:\\print.bmp");
}
--
Happy Coding!
Morten Wennevik [C# MVP]
"vi*********@gmail.com" wrote:
I tried as you said. It created a bmp file. But when i open it there
was no image. It was just an empty bmp file :( When i tried to open it
with paint it said format not supported :(
this is my code
public void drawwire(Graphics gr)
{
Pen p1 = new Pen(System.Drawing.Color.Black, 6);
Color customColor = Color.Black;
SolidBrush b1 = new SolidBrush(customColor);
Point begin = new Point(), end = new Point();
for (int count1 = 1; count1 <= wire_cont; count1++)
{
if (modify.item == 1)
{
p1.Color = Color.Black;
b1.Color = Color.Black;
if (modify.no == count1)
{
p1.Color = Color.Red;
b1.Color = Color.Red;
}
}
if (wire[count1] != null)
{
begin = wire[count1].getBeginning();
end = wire[count1].getEnding();
gr.FillRectangle(b1, begin.X - 4, begin.Y - 4, 8,
8);
gr.FillRectangle(b1, end.X - 4, end.Y - 4, 8, 8);
gr.DrawLine(p1, begin, end);
}
}
}
private void toolStripButton2_Click(object sender, EventArgs e)
{
Bitmap print = new Bitmap(100, 100);
using (Graphics pri = Graphics.FromImage(print))
{
drawwire(pri);
}
print.Save("E:\\print.bmp");
}