【问题标题】:Print a bitmap with square Boxes such that打印带有方形框的位图,使得
【发布时间】:2011-04-17 05:44:12
【问题描述】:

我想构建一个打印有 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# ?
}

【问题讨论】:

  • ummm..你能在Paint中画出来并粘贴到这里,这样我们就可以理解了..?

标签: c# colors bitmap


【解决方案1】:

我们不是来做你的工作,所以这里是一个初学者的提示:

创建位图: http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.aspx

然后画线:

画线: http://msdn.microsoft.com/fr-fr/library/021a23yy.aspx

哇超级难!! :D

【讨论】:

    【解决方案2】:

    当然!

    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);
    }
    

    这只是一个sn-p,所以我没有测试我的代码。

    希望能帮到你。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-31
      • 1970-01-01
      • 2021-02-14
      • 2020-12-17
      • 2014-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多