所以我有这个问题.我有一个IplImage,我想压缩为JPEG并用它做一些事情.我用libjpeg.我找到了很多答案"通过示例和文档阅读"等等并且做到了.并成功地为此编写了一个功能.
FILE* convert2jpeg(IplImage* frame)
{
FILE* outstream = NULL;
outstream=malloc(frame->imageSize*frame->nChannels*sizeof(char))
unsigned char *outdata = (uchar *) frame->imageData;
struct jpeg_error_mgr jerr;
struct jpeg_compress_struct cinfo;
int row_stride;
JSAMPROW row_ptr[1];
jpeg_create_compress(&cinfo);
jpeg_stdio_dest(&cinfo, outstream);
cinfo.image_width = frame->width;
cinfo.image_height = frame->height;
cinfo.input_components = frame->nChannels;
cinfo.in_color_space = JCS_RGB;
jpeg_set_defaults(&cinfo);
jpeg_start_compress(&cinfo, TRUE);
row_stride = frame->width * frame->nChannels;
while (cinfo.next_scanline < cinfo.image_height) {
row_ptr[0] = &outdata[cinfo.next_scanline * row_stride];
jpeg_write_scanlines(&cinfo, row_ptr, 1);
}
jpeg_finish_compress(&cinfo);
jpeg_destroy_compress(&cinfo);
return outstream;
}
Run Code Online (Sandbox Code Playgroud)
现在这个函数直接来自示例(除了分配内存的部分,但我需要它,因为我不是写入文件),但它仍然不起作用.它死于jpeg_start_compress(&cinfo,TRUE); 部分?
有人可以帮忙吗?
我正在使用Libjpeg版本6b.在版本8中,他们有一个很好的功能来从内存中读取数据jpeg_mem_src(...),不幸的是ver.6b没有此功能.
我可以用什么来直接从内存中读取压缩数据?我只看到jpeg_stdio_src从硬盘读取的内容.
我正在处理图片裁剪器,我的表单验证有问题.上传GIF图片时验证表单,但我尝试的任何其他格式都会引发以下异常:
Upload a valid image. The file you uploaded was either not an image or a corrupted image.
Run Code Online (Sandbox Code Playgroud)
形成
<form enctype="multipart/form-data" method="post" action="/pic/">{% csrf_token %}
{{ form.as_p }}
<p><input type="submit" value="View uploaded image"></p>
<input type="hidden" name="stage" value="crop">
</form>
Run Code Online (Sandbox Code Playgroud)
视图
if request.method == 'POST':
form = ProfilePicForm(request.POST, request.FILES)
if form.is_valid():
*do stuff*
else:
logger.debug('Form errors == [%s]' % form.errors)
Run Code Online (Sandbox Code Playgroud)
我在安装PIL之前安装了libjpeg-dev(使用apt-get)(使用easy_install).起初,我认为这可能是由于libjpeg-dev或PIL的安装不正确,但png等其他格式问题是否仍然存在?事实上,对于png图像也会出现此问题.我没有得到一个jpeg解码器问题,所以我认为不是那个,但我不确定.另外,我正在使用django开发服务器.
我决定尝试重新安装PIL.我删除了我的PIL安装文件夹
/usr/local/lib/python2.7/dist-packages/PIL
和我的PIL.pth文件(在相同的dist-packages文件夹中).我使用了运行setup.py脚本sudo python setup.py install.然后我运行了selftest.py脚本,它在第一次测试时失败了:
--------------------------------------------------------------------
PIL 1.1.7 TEST …Run Code Online (Sandbox Code Playgroud) 如果需要的话,这是关于编译libjpeg v6b的。
我运行./configure --prefix = / c / tmp / jpeg-6b-build --enable-shared --enable-static就像安装文档说的那样,但是libtool没有它。
checking dynamic linker characteristics... no
checking if libtool supports shared libraries... no
checking whether to build shared libraries... no
checking whether to build static libraries... yes
Run Code Online (Sandbox Code Playgroud)
我想我需要这个共享库来编译一些功能。libjpeg本身可以正常编译,而.exe可以生成工作,但是我需要将源代码用于其他用途。v6b出于某种原因不会生成.DLL,而v9会生成。
./configure命令的完整输出:
ild
checking for gcc... gcc
checking whether the C compiler (gcc ) works... yes
checking whether the C compiler (gcc ) is a cross-compiler... no
checking whether we are using GNU C... yes
checking how to run the C …Run Code Online (Sandbox Code Playgroud) 你怎么能(在C/C++中)使用libjpeg将文本添加到jpeg文件中?
我不是指编辑像素,而是通过向元数据添加文本(如png文件的png_set_text()libpng库).
我想在我的应用程序中使用libjpeg.使项目在.libs文件夹中生成libjpeg.a.我想要做的是在链接阶段使用此文件.我尝试了以下内容:我将libjpeg.a复制到我的C代码所在的文件夹中.试图链接
gcc libjpeg.a mycode.c -o executable_name
Run Code Online (Sandbox Code Playgroud)
失败.如果我执行gcc -ljpeg mycode.c,当我将标题更改为指向而不是"libjpeg.h"时,编译成功,但这显然链接到库的系统范围动态版本.
尝试链接相对路径或绝对路径也会失败:
gcc ./libjpeg.a mycode.c -o executable_name
Run Code Online (Sandbox Code Playgroud)
我也尝试过静态选项:
gcc -static libjpeg.a mycode.c -o executable_name
Run Code Online (Sandbox Code Playgroud)
链接器错误如下:
Linking...
gcc -std=c99 -Wall -Wextra -g -pedantic ./libjpeg.a ./libjpeg.a -lm obj/read_jpeg.o obj/utils.o -o test_jpeg
obj/read_jpeg.o: In function `read_JPEG_file':
/home/ustun/Downloads/jpeg_test/read_jpeg.c:37: undefined reference to `jpeg_std_error'
/home/ustun/Downloads/jpeg_test/read_jpeg.c:45: undefined reference to `jpeg_CreateDecompress'
/home/ustun/Downloads/jpeg_test/read_jpeg.c:46: undefined reference to `jpeg_stdio_src'
/home/ustun/Downloads/jpeg_test/read_jpeg.c:47: undefined reference to `jpeg_read_header'
/home/ustun/Downloads/jpeg_test/read_jpeg.c:48: undefined reference to `jpeg_start_decompress'
/home/ustun/Downloads/jpeg_test/read_jpeg.c:62: undefined reference to `jpeg_read_scanlines'
/home/ustun/Downloads/jpeg_test/read_jpeg.c:74: undefined reference to `jpeg_finish_decompress'
/home/ustun/Downloads/jpeg_test/read_jpeg.c:75: undefined …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用mingw-w64编译libjpeg(版本8d).我发布的用于构建它的命令是:
在第三步,我得到这个错误:
$ make
D:/Builder/bin/make all-am
make[1]: Entering directory `d:/8d'
CC jaricom.lo
CC jcapimin.lo
jcapimin.c:127:1: error: conflicting types for 'jpeg_suppress_tables'
jcapimin.c:128:1: note: an argument type that has a default promotion can't match an empty parameter name list declaration
In file included from jcapimin.c:22:0:
jpeglib.h:982:14: note: previous declaration of 'jpeg_suppress_tables' was here
make[1]: *** [jcapimin.lo] Error 1
make[1]: Leaving directory `d:/8d'
make: *** [all] Error 2
Run Code Online (Sandbox Code Playgroud)
有人知道如何解决它吗?
我下载了libjpeg-8d源代码.我想把它编译成libjpeg.so,可以在android ndk中使用.因为ndk使用arm架构,但我的PC的gcc是x86架构.所以当我使用gcc编译出libjpeg.so并将其放入jni文件夹时.它显示使用ndk-build时无法重新调整文件格式.那么如何为ndk构建正确的libjpeg.so呢?
我正在尝试构建一个上传程序,它分两步上传渐进文件:
我想这样做可以提前获得缩略图,而无需上传单独的缩略图.拍摄一张图像(3426398 Byte),它是jpegtran -copy all -progressive -outfile progressive.jpg original.jpg用dd if=progressive.jpg of=thumb.jpg bs=1 count=350000我创建的,然后拍摄前350000个字节,我得到了一个有效的缩略图.
有没有办法找出我需要传输多少字节才能获得所有行都可用的图像?这样只会失去图像质量?
我试过遵循另一个答案,但似乎无法做到这一点。我有大约 8MiB 的 RBGX 位图可以使用 libjpeg-turbo 在内存中转换为 jpeg。如果我使用jpeg_stdio_dest我可以将整个内容写入文件,然后再读回文件,就可以了。然而,尝试使用jpeg_mem_dest一直是一个难题。我的设置与 完全相同jpeg_stdio_dest,但使用mem似乎只分配了 4KiB 的一个空间,然后再也不分配任何空间。
我找不到有关如何使用 的进一步说明的文档jpeg_mem_dest,并且确实可以使用一些指导。
void compress(std::vector<unsigned char>& input) {
jpeg_compress_struct cinfo{};
jpeg_error_mgr err{};
cinfo.err = jpeg_std_error(&err);
jpeg_create_compress(&cinfo);
#if 0 // using this with an open FILE* out works
jpeg_stdio_dest(&cinfo, out);
#endif
cinfo.image_width = kWidth; // constants defined somewhere
cinfo.image_height = kHeight;
cinfo.input_components = 4;
cinfo.in_color_space = JCS_EXT_RGBX;
// what's wrong with this?
unsigned char* buf{};
unsigned long buf_sz{};
jpeg_mem_dest(&cinfo, …Run Code Online (Sandbox Code Playgroud) libjpeg ×10
c++ ×4
jpeg ×3
android ×1
android-ndk ×1
c ×1
compression ×1
django ×1
dll ×1
gcc ×1
linker ×1
opencv ×1
progressive ×1
python ×1
text ×1