开发者

Print a bitmap with square Boxes such that

开发者 https://www.devze.com 2023-02-25 03:54 出处:网络
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:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号