c# - saving drawn image into folder -
i have drawn image in picturebox, want save in folder. have tried many ways nil worked. drawing image using fallowing code. drawing image based on textbox values.
private void btntransferbottleregenerate_click(object sender, eventargs e) { float[] volumetransfer = new float[1]; volumetransfer[0] = float.parse(txttransfervolume.text); int[] percentages = new int[6]; percentages[0] = int.parse(txttransfernotidentified.text); percentages[1] = int.parse(txttransferwaterbasedmud.text); percentages[2] = int.parse(txttransferoilbasedmud.text); percentages[3] = int.parse(txttransferwater.text); percentages[4] = int.parse(txttransferhydrocarbonliq.text); percentages[5] = int.parse(txttransfergas.text); color[] colors = new color[6]; colors[0] = color.gray; colors[1] = color.chocolate; colors[2] = color.saddlebrown; colors[3] = color.blue; colors[4] = color.red; colors[5] = color.lime; // finally, phone call method drawpercentages(percentages, colors, volumetransfer); //string filename = application.startuppath + "\\volumetransfer.jpg"; // picturebox1.image.save(application.startuppath + "\\image\\picture1.jpg"); // picturebox1.refresh(); // if (picturebox1 != null) // { picturebox1.image.save(application.startuppath + "\\test.bmp"); // } } private void drawpercentages(int[] percentages, color[] colors, float[] volumetransfer) { // create graphics object draw on picturebox graphics g = picturebox1.creategraphics(); // calculate number of pixels per 1 percent float pixelsperpercent = picturebox1.height / volumetransfer[0]; // maintain track of height @ start drawing (starting bottom going up) int drawheight = picturebox1.height; // loop through percentages , draw rectangle each (int = 0; < percentages.length; i++) { // create brush current color solidbrush brush = new solidbrush(colors[i]); // update height @ next rectangle drawn. drawheight -= (int)(pixelsperpercent * percentages[i]); // draw filled rectangle g.fillrectangle(brush, 0, drawheight, picturebox1.width, pixelsperpercent * percentages[i]); } } }
}
when click "regenerate" button going draw image in picturebox after want save in folder. have design this.
a solution draw on bitmap, set image of picturebox
, save it:
private void drawpercentages(int[] percentages, color[] colors, float[] volumetransfer){ bitmap bmp = new bitmap(picturebox1.width, picturebox1.height); using(graphics g = graphics.fromimage(bmp)){ //... } picturebox1.image = bmp; }
and code should work without problem.
c# picturebox
No comments:
Post a Comment