打印一个带有方框的位图,如下所示
本文关键字:位图 方框 一个 打印 | 更新日期: 2023-09-27 17:50:35
我想建立一个x行y列的位图,每个框的大小为10 x 10 px。
现在,当我通过:
private void printBitmap(rows, columns, numOfWhites, numOfblack, numOf(green or brown)) {
// i want to be able to build a bitmap with rows and columns with White to top right,
// black to bottom right, if green or brown fill the box with green or brown
// except the area with white or black
// how do i do this in C# ?
}
我们不是来做你的工作的,所以这里有一个提示:
创建位图:http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.aspx
,然后绘制线条:
画直线:http://msdn.microsoft.com/fr-fr/library/021a23yy.aspx
哇,超级硬!!: D
当然!
private void printBitmap(rows, columns, numOfWhites, numOfblack /*, numOf... */) {
Bitmap bmp = new Bitmap(rows * 10, columns * 10);
Graphics g = Graphics.FromImage(bmp);
SolidBrush bWhite = new SolidBrush(Color.White);
SolidBrush bBlack = new SolidBrush(Color.Black);
// ...SolidBrush bColor = new SolidBrush(Color.AnyColor);
// ...
int countNumOfWhites = 0;
int countNumOfBlacks = 0;
// int countNumOf... = 0;
// ...
for(int c = 0; c < columns; c++)
{
for(int r = 0; r < rows; r++)
{
if(countNumOfWhites < numOfWhites)
{
g.FillRectangle(bWhite, new Rectangle(r * 10, c * 10, (r + 1) * 10, (c + 1) * 10);
countNumOfWhites++;
}
else if(countNumOfBlacks < numOfBlacks)
{
g.FillRectangle(bBlack, new Rectangle(r * 10, c * 10, (r + 1) * 10, (c + 1) * 10);
countNumOfBlacks++;
}
//else if(countNumOf... < numOf...)
//{
// g.FillRectangle(b..., new Rectangle(r * 10, c * 10, (r + 1) * 10, (c + 1) * 10);
// countNumOf...++;
//}
}
}
bmp.Save("printedbitmap.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
}
这只是一个代码片段,所以我没有测试我的代码。
我希望我能帮上忙。