位图保存问题

发布于 2024-08-25 06:43:48 字数 2030 浏览 2 评论 0原文

谁能告诉我您是否知道 WM 6 的位图和隐写术有问题?

我正在开发一个项目,我必须在位图中隐藏数字签名。该算法工作完美,直到我将图像存储在内存中,位图才包含修改后的字节。 但是在我保存图像(Bitmap.Save())并重新打开图像后,这些字节就会丢失。当我说丢失时,我的意思是它们是拍摄照片时的原始字节。

谢谢。

这是保存方法:

    {
        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");

                }

            }
        }
    }

和打开方法

    {
        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");
            }
        }

}

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");
            }
        }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初心 2024-09-01 06:43:49

您在评论中提到您只是修改 LSB。我假设你指的是最低有效字节(而不是最低有效位),如果有这样的事情的话。

.Net 中的标准位图为每像素 32 位,R、G 和 B 分量各占 1 个字节,Alpha 通道占 1 个字节,通常将其解释为透明度在支持透明度的设备中。

您可能只是修改了 alpha 通道值,并且由于 Compact Framework 图片框不支持透明度(我认为),因此 Bitmap 看起来与原来的完全相同。

尝试修改一些不同的字节,您应该会看到差异。

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.

南渊 2024-09-01 06:43:49

首先,“最低有效位”实际上是正确的。最低有效位是每个 R、G、B 和可能的 A 通道中的最低有效位,每个通道在 32 位位图中包含一个字节。

其次,您发布了“保存”和“打开”代码 - 您可以发布实际更改位图数据的代码吗?如果您没有修改 pictureBox 对象中的位,那么您确实只是保存了原始图像,因为这是 open 方法放置数据的地方。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文