9 lines
6.2 KiB
JavaScript
9 lines
6.2 KiB
JavaScript
import{_ as t}from"./plugin-vue_export-helper-DlAUqK2U.js";import{c as i,a,o as n}from"./app-DkPs9iUo.js";const s={};function p(r,e){return n(),i("div",null,[...e[0]||(e[0]=[a(`<h1 id="jpeg算法解密-五" tabindex="-1"><a class="header-anchor" href="#jpeg算法解密-五"><span>JPEG算法解密(五)</span></a></h1><p>最后,我提供给大家一个简易的jpeg压缩算法的代码,这份代码用C++编写,以开源方式提供,放在了github上,可以到下面这个网址下载<br><a href="http://github.com/thejinchao/jpeg_encoder" target="_blank" rel="noopener noreferrer">http://github.com/thejinchao/jpeg_encoder</a><br> 使用方法很简单,像下面这样就可以了</p><div class="language-cpp" data-highlighter="shiki" data-ext="cpp" style="--shiki-light:#383A42;--shiki-dark:#abb2bf;--shiki-light-bg:#FAFAFA;--shiki-dark-bg:#282c34;"><pre class="shiki shiki-themes one-light one-dark-pro vp-code"><code class="language-cpp"><span class="line"><span style="--shiki-light:#A626A4;--shiki-dark:#C678DD;">#include</span><span style="--shiki-light:#50A14F;--shiki-dark:#98C379;"> "jpeg_encoder.h"</span></span>
|
|
<span class="line"><span style="--shiki-light:#383A42;--shiki-dark:#ABB2BF;"> </span></span>
|
|
<span class="line"><span style="--shiki-light:#383A42;--shiki-dark:#ABB2BF;">JpegEncoder encoder;</span></span>
|
|
<span class="line"><span style="--shiki-light:#A0A1A7;--shiki-light-font-style:italic;--shiki-dark:#7F848E;--shiki-dark-font-style:italic;">//输入的文件必须是24bit的bmp文件,尺寸必须是8的倍数</span></span>
|
|
<span class="line"><span style="--shiki-light:#E45649;--shiki-dark:#E5C07B;">encoder</span><span style="--shiki-light:#383A42;--shiki-dark:#ABB2BF;">.</span><span style="--shiki-light:#4078F2;--shiki-dark:#61AFEF;">readFromBMP</span><span style="--shiki-light:#383A42;--shiki-dark:#ABB2BF;">(inputFileName);</span></span>
|
|
<span class="line"><span style="--shiki-light:#383A42;--shiki-dark:#ABB2BF;"> </span></span>
|
|
<span class="line"><span style="--shiki-light:#A0A1A7;--shiki-light-font-style:italic;--shiki-dark:#7F848E;--shiki-dark-font-style:italic;">//第二个参数在1~199之间,代表文件压缩程度,数字越大,压缩后的文件体积越小</span></span>
|
|
<span class="line"><span style="--shiki-light:#E45649;--shiki-dark:#E5C07B;">encoder</span><span style="--shiki-light:#383A42;--shiki-dark:#ABB2BF;">.</span><span style="--shiki-light:#4078F2;--shiki-dark:#61AFEF;">encodeToJPG</span><span style="--shiki-light:#383A42;--shiki-dark:#ABB2BF;">(outputFileName, </span><span style="--shiki-light:#986801;--shiki-dark:#D19A66;">50</span><span style="--shiki-light:#383A42;--shiki-dark:#ABB2BF;">);</span></span></code></pre></div><p>这份代码只是为了配合这个系列的文章,所以没有考虑优化,如果你想在实际工程中使用jpeg的压缩算法,还是使用被广泛应用的libjpeg或者OpenJpeg。</p><hr><p>参考资料:<br> 【1】<a href="http://www.impulseadventure.com/photo/jpeg-huffman-coding.html" target="_blank" rel="noopener noreferrer">http://www.impulseadventure.com/photo/jpeg-huffman-coding.html</a><br> 【2】<a href="http://www.mysanco.cn/index.php?class=wenku&action=wenku_item&id=96" target="_blank" rel="noopener noreferrer">http://www.mysanco.cn/index.php?class=wenku&action=wenku_item&id=96</a><br> 【3】<a href="http://www.codingnow.com/2000/download/jpeg.txt" target="_blank" rel="noopener noreferrer">http://www.codingnow.com/2000/download/jpeg.txt</a><br> 【4】<a href="http://jingyan.baidu.com/article/cbf0e500f1ce562eaa2893f4.html" target="_blank" rel="noopener noreferrer">http://jingyan.baidu.com/article/cbf0e500f1ce562eaa2893f4.html</a><br> 【5】<a href="http://www.codeproject.com/Articles/83225/A-Simple-JPEG-Encoder-in-C" target="_blank" rel="noopener noreferrer">http://www.codeproject.com/Articles/83225/A-Simple-JPEG-Encoder-in-C</a></p>`,6)])])}const l=t(s,[["render",p]]),c=JSON.parse('{"path":"/blog/2025/02/JPEG005.html","title":"JPEG算法解密(五)","lang":"zh-CN","frontmatter":{"title":"JPEG算法解密(五)","tags":"压缩 图像 程序 算法","prev":{"text":"JPEG算法解密(四)","link":"JPEG004.md"},"description":"JPEG算法解密(五) 最后,我提供给大家一个简易的jpeg压缩算法的代码,这份代码用C++编写,以开源方式提供,放在了github上,可以到下面这个网址下载 http://github.com/thejinchao/jpeg_encoder 使用方法很简单,像下面这样就可以了 这份代码只是为了配合这个系列的文章,所以没有考虑优化,如果你想在实际工程中...","head":[["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"JPEG算法解密(五)\\",\\"image\\":[\\"\\"],\\"dateModified\\":\\"2025-08-31T08:33:30.000Z\\",\\"author\\":[{\\"@type\\":\\"Person\\",\\"name\\":\\"JinChao\\",\\"url\\":\\"https://thecodeway.com\\"}]}"],["meta",{"property":"og:url","content":"https://thejinchao.github.io/blog/2025/02/JPEG005.html"}],["meta",{"property":"og:site_name","content":"我的博客和笔记"}],["meta",{"property":"og:title","content":"JPEG算法解密(五)"}],["meta",{"property":"og:description","content":"JPEG算法解密(五) 最后,我提供给大家一个简易的jpeg压缩算法的代码,这份代码用C++编写,以开源方式提供,放在了github上,可以到下面这个网址下载 http://github.com/thejinchao/jpeg_encoder 使用方法很简单,像下面这样就可以了 这份代码只是为了配合这个系列的文章,所以没有考虑优化,如果你想在实际工程中..."}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"zh-CN"}],["meta",{"property":"og:updated_time","content":"2025-08-31T08:33:30.000Z"}],["meta",{"property":"article:modified_time","content":"2025-08-31T08:33:30.000Z"}]]},"git":{"createdTime":1740225290000,"updatedTime":1756629210000,"contributors":[{"name":"thejinchao","username":"thejinchao","email":"thejinchao@gmail.com","commits":2,"url":"https://github.com/thejinchao"}]},"readingTime":{"minutes":0.95,"words":285},"filePathRelative":"blog/2025/02/JPEG005.md","autoDesc":true}');export{l as comp,c as data};
|