c# - panel1.DrawToBitmap doesn't draw lines from DrawLine -


i have panel on i'm drawing lines using:

point previouspoint = new point (0,0); point newpoint = new point (10,10); pen mypen = new pen(color.black, 2); graphics mygraphics = panel1.creategraphics(); mygraphics.drawline(mypen, previouspoint, newpoint); 

this works fine. change points draw more lines, doesn't matter question. want export panel jpg file. i'm using code:

bitmap bmp = new bitmap(panel1.width, panel1.height); panel1.drawtobitmap(bmp, new rectangle(0, 0, panel1.width, panel1.height)); bmp.save("c:\\panel.jpg", system.drawing.imaging.imageformat.jpeg); 

this outputs blank jpg. background of panel gray, , background of jpg same gray, know it's exporting panel. also, added button panel see if saved, , did. reason jpg isn't saving lines being drawn.

so made workaround solves core problem. made array of points plotted draw lines, did this:

        // make sure drew         if (mylines.length > 0)         {             // instantiate stuff need             image img = new bitmap(panel1.width, panel1.height);             graphics g = graphics.fromimage(img);             pen pen = new pen(color.black, 2);              // draw every line (from every index 1 after it)             (int = 0; < mylines.length; i++)             {                 if (i % 2 == 0)                 {                     g.drawline(pen, mylines[i], mylines[i + 1]);                 }             }             img.save("c:\\panel.png", system.drawing.imaging.imageformat.png);         }     } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -