Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7688129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:51:05+00:00 2026-05-31T19:51:05+00:00

I have a program which displays an image to the windows form, and places

  • 0

I have a program which displays an image to the windows form, and places a message within the image as it paints it (this works fine) i then have a method which reads the message back. However, doing this causes the winforms screen to freeze! i must be getting stuck in an endless loop. The method does work as i do get the message back…. can anyone help un-freeze my program?

Code below:

    public partial class MyImages : Form
    {
        //I have variables related to encoding and decoding here(deleted)
        private const String MESSAGE = "2008-01-07";

        Bitmap firstLoaded;
        Bitmap theImage;
        Bitmap imageEmbedded; 
        Boolean isGetMessage = false; 
        Boolean isEmbedImage = false; 
        Boolean isLoaded = false;
        Graphics graphicsWindow;   // reference to the graphic surface of this window
        Graphics graphicsImage;     // reference to in-memory surface
        BitArray bitsOfMessage = new BitArray(8);
        String bytesOfTheMessage = null;

        public MyImages()
        {
            InitializeComponent();
            this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
        }

        private void MyImages_Paint(object sender, PaintEventArgs e)
        {
            HandlePainting(); 
        }

        public void HandlePainting()
        {
            if (isLoaded == true)
            {
                theImage = new Bitmap(Width, Height);     // bitmap for window surface copy
                graphicsWindow = CreateGraphics();   // get our current window's surface
                graphicsImage = Graphics.FromImage(theImage);     // create surfaces from the bitmaps
                graphicsImage.DrawImage(firstLoaded, 0, 0, Width, Height);

                if (isEmbedImage == true)
                {
                    theImage = embedMessageInImage(theImage);
                }
                else if (isGetMessage == true)
                {
                    getEmbeddedMessage(imageEmbedded);
                }

                if (isGetMessage == false)
                {
                    graphicsWindow.DrawImage(theImage, 0, 0);
                }
                else if (isGetMessage == true)
                {
                    graphicsWindow.DrawImage(imageEmbedded, 0, 0);
                }
            }
        }

        private void toolStripMenuItemLoadImage_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                ofd.Title = "Load Image";

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    firstLoaded = new Bitmap(ofd.FileName);
                    this.Invalidate();
                }
            }
            isLoaded = true;
        }

        private void toolStripMenuEmbedMessage_Click(object sender, EventArgs e)
        {
            isEmbedImage = true;
            isGetMessage = false; 
            this.Invalidate(); 
        }

        private void toolStripMenuItemGetMessage_Click(object sender, EventArgs e)
        {
            isEmbedImage = false;
            isGetMessage = true;
            this.Invalidate(); 
        }

        public void convertToChar(int byteChar)
        {
            char val = Convert.ToChar(byteChar);
            String nextChar = val.ToString();
            bytesOfTheMessage += nextChar;

        }

        private Bitmap embedMessageInImage(Bitmap bmp)
        {
           //Embed message in this method (deleted)

                //unlock the bitmaps
                newBitmap.UnlockBits(newData);
                bmp.Save("tina.bmp"); 
                bmp.UnlockBits(originalData);
                newBitmap.Save("tina7.bmp");
                imageEmbedded = newBitmap; 
                return newBitmap;
            }
        }

        private void getEmbeddedMessage(Bitmap bmp)
        {
            unsafe
            {
                //create an empty bitmap the same size as original
                Bitmap newBitmap = new Bitmap(bmp.Width, bmp.Height);

                //lock the original bitmap in memory
                System.Drawing.Imaging.BitmapData originalData = bmp.LockBits(
                   new Rectangle(0, 0, bmp.Width, bmp.Height),
                   System.Drawing.Imaging.ImageLockMode.ReadOnly,
                   System.Drawing.Imaging.PixelFormat.Format24bppRgb);

                //lock the new bitmap in memory
                System.Drawing.Imaging.BitmapData newData = newBitmap.LockBits(
                   new Rectangle(0, 0, bmp.Width, bmp.Height),
                   System.Drawing.Imaging.ImageLockMode.WriteOnly,
                   System.Drawing.Imaging.PixelFormat.Format24bppRgb);

                //set the number of bytes per pixel
                int pixelSize = 3;

                for (int y = 0; y < bmp.Height; y++)
                {
                    //get the data from the original image
                    byte* originalImageRow = (byte*)originalData.Scan0 + (y * originalData.Stride);

                    //get the data from the new image
                    byte* newImageRow = (byte*)newData.Scan0 + (y * newData.Stride);

                    for (int x = 0; x < bmp.Width; x++)
                    {

                        byte b = (byte)(originalImageRow[x * pixelSize + 0]); // B
                        getEachBitOfMessage(b, BLUE);

                        byte g = (byte)(originalImageRow[x * pixelSize + 1]); // G
                        getEachBitOfMessage(g, GREEN);

                        byte r = ((byte)(originalImageRow[x * pixelSize + 2])); //R
                        getEachBitOfMessage(r, RED);

                    }
                }

                //unlock the bitmaps
                newBitmap.UnlockBits(newData);
                bmp.UnlockBits(originalData);
            }
        }

        public byte changeEachBit(byte byteToManipulate, int colour, byte theMessage)
        {
            byte value = 0;
            byte returnByte = 0; 

            if (colour == BLUE)
            {
               value= (byte)(theMessage & BValueMask);
               value = (byte)(value>>5); 
               returnByte = (byte)(byteToManipulate & BlueMask);
               returnByte = (byte)(returnByte | value); 

            }
            else if (colour == GREEN)
            {
                value = (byte)(theMessage & GValueMask);
                value = (byte)(value >> 3);
                returnByte = (byte)(byteToManipulate & GreenMask);
                returnByte = (byte)(returnByte | value);

            }
            else if (colour == RED)
            {
                value = (byte)(theMessage & RValueMask);
                returnByte = (byte)(byteToManipulate & RedMask);
                returnByte = (byte)(returnByte | value);
            }

            return returnByte;
        }

        public void getEachBitOfMessage(byte byteToManipulate, int colour)
        {
            //I Input bits into image here (deleted)

        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T19:51:07+00:00Added an answer on May 31, 2026 at 7:51 pm

    Let it freeze and click the Pause button on the top toolbar.
    This will cause the debugger to break wherever execution may be, and you can then easily identify where it got stuck, and try and find out why as well (don’t forget to watch values using the watch window or hovering them).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following assembly program which displays the letter 'z' and then exits:
I have a Qt program which displays the data it receives over UDP. It
I have a program which needs installing on windows 64 boxes. Most of the
My name is Shruti.I'm new to php. I have a program which displays images
I have a small screen program which displays patients at the top there is
I have c++ program which display images, I want to move from one image
I have a program which needs to behave slightly differently on Tiger than on
I have a program which deliberately performs a divide by zero (and stores the
I have a program which has some Textareas / Labels these can be anywhere
I have a program which only needs a NotifyIcon to work as intended. So

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.