我想构建一个用x行和y列打印的位图,使每个框的大小为10 x 10像素。
现在,当我通过时:
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# ?
}
答案 0 :(得分:2)
我们不是来做你的工作,所以这里有一个启动者的提示:
创建位图: http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.aspx
然后画线:
DrawLine: http://msdn.microsoft.com/fr-fr/library/021a23yy.aspx
哇超级难啊! :d答案 1 :(得分:1)
当然!
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);
}
这只是一个片段,所以我没有测试我的代码。
我希望我可以提供帮助。