首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何利用可视化C#和LibJpeg.Net从Jpeg中提取DCT-系数

如何利用可视化C#和LibJpeg.Net从Jpeg中提取DCT-系数
EN

Stack Overflow用户
提问于 2015-02-10 19:13:25
回答 2查看 1.8K关注 0票数 0

为了进一步改变比特(隐写),我需要在量化后得到DCT-系数阵列.我的问题是:让我们说,我在picturebox或其他什么地方都有jpeg图像。我怎么能得到dct系数。使用C#和库(如LibJpeg.Net )的图片?需要一个密码。在整个网络上找不到任何完整和简单的东西。而且,无法看到任何关于LibJpeg.Net的教程。

在这一步骤之后:

代码语言:javascript
复制
    BitMiracle.LibJpeg.Classic.jpeg_decompress_struct oJpegDecompress = new BitMiracle.LibJpeg.Classic.jpeg_decompress_struct();
     System.IO.FileStream oFileStreamImage = new System.IO.FileStream(strImagePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
       oJpegDecompress.jpeg_stdio_src(oFileStreamImage);
        oJpegDecompress.jpeg_read_header(true);            
        BitMiracle.LibJpeg.Classic.jvirt_array<BitMiracle.LibJpeg.Classic.JBLOCK>[] JBlock = oJpegDecompress.jpeg_read_coefficients();

我现在该怎么做,来编辑dct coeff?用.Access()?我该怎么用这个?有什么例子吗?

以下是:

代码语言:javascript
复制
short[] block = JBlock[c].Access(x, y);

给出这样一个错误:“无法隐式地将'BitMiracle.LibJpeg.Classic.JBLOCK‘转换为'short[]'”

此外,在使用类似的内容时,它会给出一个关于将"BitMiracle.LibJpeg.Classic.JBLOCK“转换为键入"System.IConvertible”的错误。

或者有人知道另一个解决我问题的简单方法?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-02-22 14:54:28

好吧,我想出办法了。至少它回答了我的主要问题。

代码语言:javascript
复制
private void button1_Click(object sender, EventArgs e)
        {
            string path = @"D:\067.jpg";
            var img = new Bitmap(path);
            var jo = img.Width; 
            var joj = img.Height;
            BitMiracle.LibJpeg.Classic.jpeg_decompress_struct oJpegDecompress = new BitMiracle.LibJpeg.Classic.jpeg_decompress_struct();
            System.IO.FileStream oFileStreamImage = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read);
            oJpegDecompress.jpeg_stdio_src(oFileStreamImage);
            oJpegDecompress.jpeg_read_header(true);
            BitMiracle.LibJpeg.Classic.jvirt_array<BitMiracle.LibJpeg.Classic.JBLOCK>[] JBlock = oJpegDecompress.jpeg_read_coefficients();
            var ll = JBlock[0].Access(0, 1); // accessing the element
            var oo = 5; // its gonna be new value for coefficient
            for (int i = 0; i < 64; i++) // some cycle
            {
                ll[0][i][0] = Convert.ToInt16(oo); // changes
            }
            oJpegDecompress.jpeg_finish_decompress(); 
            oFileStreamImage.Close();
            /////
            System.IO.FileStream objFileStreamMegaMap = System.IO.File.Create(@"D:\068.jpg");
            BitMiracle.LibJpeg.Classic.jpeg_compress_struct oJpegCompress = new BitMiracle.LibJpeg.Classic.jpeg_compress_struct();
            oJpegCompress.jpeg_stdio_dest(objFileStreamMegaMap);
            oJpegDecompress.jpeg_copy_critical_parameters(oJpegCompress);
            oJpegCompress.Image_height = joj;
            oJpegCompress.Image_width = jo;
            oJpegCompress.jpeg_write_coefficients(JBlock);          
            oJpegCompress.jpeg_finish_compress();
            objFileStreamMegaMap.Close();
            oJpegDecompress.jpeg_abort_decompress();
            oFileStreamImage.Close();
        }

有点草率,但还是,只是考试.使用了here的一些代码

就像您在控制台中看到的那样,输出映像中0->m_buffer->0->i下的第0元素将等于5。

向我致敬。

票数 2
EN

Stack Overflow用户

发布于 2015-02-11 02:23:14

我是在编写JPEG库以验证其正确性时这样做的。您只需将源代码获取到LIBJPEG;确定它在何处执行感兴趣的函数,int (由于代码复杂而有些困难);设置断点或返回。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28439916

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档