1

I want to draw a bitmap in different shades for example green. Any width and height. To begin with, let it be 5 * 5.

What i do:

  pictureBox2.SizeMode = PictureBoxSizeMode.Zoom;
  Bitmap this_bitmap = new Bitmap(7, 7);
  Random rand = new Random();
  for (int x=0;x<5;x++){
     for (int y=0;y<5;y++){
          this_bitmap.SetPixel(x, y,Color.FromArgb(rand.Next(0, 255), Color.Red));
  }

   pictureBox1.Image = this_bitmap;

I want get this:

enter image description here

But I get this:

On this image size bitmap 3*10

How i can get result, how it showing on the first image? Display pixels with squares.

Community
  • 1
  • 1
engineer_7
  • 23
  • 1
  • 6
  • https://stackoverflow.com/questions/29157/how-do-i-make-a-picturebox-use-nearest-neighbor-resampling – Bradley Uffner Oct 09 '17 at 12:30
  • This image doesn't looks like `3*10`. Why do you chage [PictureBox.SizeMode](https://msdn.microsoft.com/en-us/library/system.windows.forms.picturebox.sizemode(v=vs.110).aspx)? Leave it [Normal](https://msdn.microsoft.com/en-us/library/system.windows.forms.pictureboxsizemode(v=vs.110).aspx) and then you will see your picture correctly (I guess). – Sinatr Oct 09 '17 at 12:39
  • @Sinatr, pictureBox have 500*500 size, i just stretch bitmap to this size. – engineer_7 Oct 09 '17 at 12:41
  • @BradleyUffner, it similar to my problem, only as it to apply bitmap. – engineer_7 Oct 09 '17 at 12:43
  • @engineer_7 It's the same problem, look at the accepted answer to that question. It shows how to make the `PictureBox` display using Nearest-Neighbor (large square pixels), when zoomed in. – Bradley Uffner Oct 09 '17 at 12:48
  • Don't. Just force a redraw: `Invalidate()`...or even `Refresh()` if you it must be more immediate. – DonBoitnott Oct 09 '17 at 13:55

0 Answers0