I want to build a bitmap printed with x rows and y columns such that each box is 10 x 10 px size.
Now, when I pass:
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# ?
}
We are not here to do your work so here is a hint for a starter :
Create a bitmap : http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.aspx
and then draw lines :
DrawLine : http://msdn.microsoft.com/fr-fr/library/021a23yy.aspx
Wow super hard !! :D
Sure!
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);
}
This is only a snippet, so I did not test my code.
I hope I can be of help.
精彩评论