views:

212

answers:

2

Hello,

can anyone tell me if you know to be a problem with Bitmap and steganography for WM 6?

I am working on a project and i have to hide a digital signature in a bitmap. The algorithm works perfect, as in untill i have the image on the memory the bitmap contains the modified bytes. But after i save the image (Bitmap.Save()) and I reopen the image, than those bytes are lost. When i say lost i mean they are the orriginal bytes from when the picture was taken.

Thank you.

here is the Save method:

    {
        if (miSave.Enabled == false)
        {
            MessageBox.Show("Error, no image is opened. ", "Save Error");
        }
        else
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Filter = "Bitmap|*.bmp|JPEG|*.jpg";

            if (sfd.ShowDialog() == DialogResult.OK)
            {

                if (sfd.FileName != "")
                {
                    Bitmap origImage = pictureBox.GetBitmap();
                    ///just a test to see that the bytes are the modified ones..and they are
                    byte[] origImageByte = ImageProcessing.ConvertBitmapToByteArray(origImage, origImage.Height * origImage.Width +54); 
                    origImage.Save(sfd.FileName, formatOfImage);
                    MessageBox.Show("Succesfully ", "Image Saved");

                }

            }
        }
    }

and the open method

    {
        if (pictureBox.Visible == false)
        {
            try
            {
                OpenFileDialog dlg = new OpenFileDialog();

                dlg.Filter = "Bitmap|*.bmp|JPEG|*.jpg";

                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    Bitmap img = new Bitmap(dlg.FileName);


                    initialSize.Width = img.Width;
                    initialSize.Height = img.Height;

                    imageOpened();//this just does does some enabling buttons nothing more

                    pictureBox.SetBitmap(img, pixelSize);
                    pictureBox.ShowImage(img);

                    trackBar.TrackBarPosition(lblMinVal, lblMaxVal, this.Size);
                }
            }
            catch
            {
                DialogResult res = MessageBox.Show("Failed loading image");
            }
        }

}

A: 

You mentioned in a comment that you're only modifying the LSB. I assume you mean the least-significant-byte (and not least significant bit), if there is such a thing.

The standard Bitmap in .Net is 32-bits-per-pixel, with 1 byte each for the R, G and B components, and 1 byte for the alpha-channel, which is usually interpreted as transparency in devices that support transparency.

It's possible that you're only modifying the alpha-channel value, and since Compact Framework picture boxes don't support transparency (I think), the Bitmap looks exactly the same as it did originally.

Try modifiying some different bytes, and you should see a difference.

MusiGenesis
A: 

First, "Least significant bit" is actually correct. The least significant bit is the least significant bit in each of the R, G, B and perhaps A channels, each of which contain one byte in a 32-bit bitmap.

Second, you posted the "Save" and "Open" code - could you post the code in which you actually change the bitmap data? If you did not modify the bits in the pictureBox object then you are indeed simply saving the original image, as that is where the open method puts the data.

bowenl2