Share via

Increase Dots size in rectangle.

Shashank Sivakoti 1 Reputation point
2022-11-03T19:19:08.297+00:00

Hi Team,

How to increase the white dots sizes? Please refer the attached image.

using System;  
using System.Drawing;  
using System.Drawing.Drawing2D;  
using System.Drawing.Imaging;  
using System.IO;  
static void Main(string[] args)  
{  
//Image image = new Bitmap(1000, 1000, PixelFormat.Format32bppArgb);  
Bitmap bitmap = new Bitmap(100, 100, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);  
Graphics graph = Graphics.FromImage(bitmap);  
Pen pen = new Pen(Brushes.Green);  
Rectangle rect = new Rectangle(0, 0, 100, 100);  
graph.DrawRectangle(pen, rect);  
Brush b = new HatchBrush(HatchStyle.Percent90, Color.Orange, Color.White);  
// Fill rectangle to screen.  
graph.FillRectangle(b, rect);  
bitmap.Save("myImage.png", System.Drawing.Imaging.ImageFormat.Png);  
}

Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.


1 answer

Sort by: Most helpful
  1. Viorel 126.9K Reputation points
    2022-11-03T20:10:01.77+00:00

    I think that you can use a TextureBrush. For example, you can build it dynamically:

    Bitmap bitmap = new Bitmap( 100, 100, System.Drawing.Imaging.PixelFormat.Format32bppPArgb );  
      
    Graphics graph = Graphics.FromImage( bitmap );  
    Rectangle rect = new Rectangle( 0, 0, 100, 100 );  
      
    using( var img = new Bitmap( 8, 8, graph ) )  
    {  
        using( var g = Graphics.FromImage( img ) )  
        {  
            g.Clear( Color.Orange );  
            g.FillRectangle( Brushes.White, 0, 6, 2, 2 );  
            g.FillRectangle( Brushes.White, 4, 3, 2, 2 );  
        }  
      
        var tb = new TextureBrush( img );  
      
        graph.FillRectangle( tb, rect );  
    }  
      
    bitmap.Save( "myImage.png", System.Drawing.Imaging.ImageFormat.Png );  
    

    You can load the texture brush from an existing image too, made by a Graphical Editor or Visual Studio, saved as a file or embedded resource.

    It is also possible to scale it using tb.ScaleTransform.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.