-2

I'm having a problem in c# where when i try to fill an entire 8x8px .bmp file with black it doesn't do anything and there are no errors here is my code:

using System;
using System.Windows;
using System.Drawing;

namespace Data_Block_Test
{
    class Program
    {
        static string GetBytesFromBinaryString(String str, String output)
        {
            string result = "";
            string s = str.Replace(" ", String.Empty); ;

            while (s.Length > 0)
            {
                var first8 = s.Substring(0, 8);
                s = s.Substring(8);
                var number = Convert.ToInt32(first8, 2);
                result += (char)number;
            }

            return result;
        }

        static void Main(string[] args)
        {
            string output1 = "";

            Console.WriteLine(GetBytesFromBinaryString("01110011 01110101 01110011", output1));

            Bitmap img = new Bitmap("image.png");

            for (int x = 0; x < img.Width; x++)
            {
                for (int y = 0; y < img.Height; y++)
                {
                    Console.WriteLine("before: x = {0}, y = {1}, argb = {2}", x, y, img.GetPixel(x, y));
                    img.SetPixel(x, y, System.Drawing.Color.Black);
                    Console.WriteLine("after: x = {0}, y = {1}, argb = {2}", x, y, img.GetPixel(x, y));
                }
            }

            Console.WriteLine("Press enter to exit");
            Console.ReadLine();
        }
    }
}

im filling it pixel by pixel to experiment for something edit: also please ignore GetBytesFromBinaryString() and all references to it because it is unrelated to what i am trying to do

danny boi
  • 1
  • 2
  • Please review [MCVE] guidance on posting code and [edit] the question correspondingly. In particular `GetBytesFromBinaryString` seem to be completely unrelated to the question. Also please explain what you expect to happen - clearly you are not expecting fil on disk to change... – Alexei Levenkov Jul 12 '21 at 20:08
  • 1
    `using (var g = Graphics.FromImage(img)) { g.Clear(Color.Black); img.Save([Some Path]); }` – Jimi Jul 12 '21 at 20:23
  • _" ignore GetBytesFromBinaryString() and all references to it"_ -- if you have posted code in your question that you know should be ignored **then you have posted a poor-quality question**. You are expected to provide a proper [mcve], part of which means that _there isn't any code in the code example that doesn't absolutely need to be there to reproduce your problem_. – Peter Duniho Jul 12 '21 at 20:25

1 Answers1

0

I have reviewed the code, you need include SAVE method after "FOR" statements.

Save method:

img.Save("out.png");
Carlos J.
  • 55
  • 7