JPEG支持与IJG - 获得访问冲突 [英] JPEG support with ijg - getting access violation

查看:209
本文介绍了JPEG支持与IJG - 获得访问冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我试图更新我的比赛存储图形COM pressed格式(JPEG和PNG)。

虽然我最终解决在不同的图书馆,我最初的尝试是纳入 IJG 做JPEG DECOM pression。但是,我无法得到即使最简单的控制台应用程序来工作,我想知道如果任何人可以摆脱的原因一些轻为什么。

下面是我的code,这是链接到的 jpeg.lib 的即是IJG包的一部分:

 的#includestdafx.h中
#包括LT&;&stdio.h中GT;
#包括LT&;&ASSERT.H GT;
#包括LT&;&jpeglib.h GT;INT _tmain(INT ARGC,_TCHAR *的argv [])
{
    结构jpeg_decom press_struct CINFO;
    结构jpeg_error_mgr jerr;
    JSAMPARRAY缓冲;
    INT row_stride;    //初始化错误处理
    cinfo.err = jpeg_std_error(安培; jerr);    //初始化DECOM pression
    jpeg_create_decom preSS(安培; CINFO);    FILE * INFILE;
    errno_t ERR = fopen_s(安培; INFILE,.. \\\\ Sample.jpg,RB);
    断言(ERR == 0);    //指定输入
    jpeg_stdio_src(安培; CINFO,INFILE);    //读取头
    (无效)jpeg_read_header(安培; CINFO,TRUE);    返回0;
}

问题是,调用 jpeg_read_header()失败的访问冲突:


  

在0x7c91b1fa未处理的异常
  (NTDLL.DLL)在JPEGTest.exe:
  0000005:访问冲突写作
  位置0x00000010。


没有人有任何想法我可能是做错了?


解决方案

我刚刚遇到了同样的问题(虽然我一直想把EN code图像)。
显然,FILE *不是的DL​​L之间移植,所以你不能使用任何的libjpeg的API,需要一个FILE *作为参数。<​​/ P>

有几种解决方案,但他们都归结为不必重新生成库:


  • 构建库作为静态库,并将其链接到您的应用程序。这是我做的,它解决了我的问题。

  • 将源/目标处理程序的libjpeg出来,进入你的应用程序。然后,你可以建立的libjpeg无论是作为静态库或DLL,两者适合你。我不知道这是否会工作,但它是在与源$ C ​​$ C分发的install.doc文件建议的解决方案。

I was recently trying to update my game to store graphics in compressed formats (JPEG and PNG).

Whilst I ended up settling on a different library, my initial attempt was to incorporate ijg to do JPEG decompression. However, I was unable to get even the simplest console application to work and am wondering if anyone might be able to shed some light on the reasons why.

Here is my code, which is linked to the jpeg.lib that is part of the ijg packages:

#include "stdafx.h"
#include <stdio.h>
#include <assert.h>
#include <jpeglib.h>

int _tmain(int argc, _TCHAR* argv[])
{
    struct jpeg_decompress_struct cinfo;
    struct jpeg_error_mgr jerr;
    JSAMPARRAY buffer;
    int row_stride;

    //initialize error handling
    cinfo.err = jpeg_std_error(&jerr);

    //initialize the decompression
    jpeg_create_decompress(&cinfo);

    FILE* infile;
    errno_t err = fopen_s(&infile, "..\\Sample.jpg", "rb");
    assert(err == 0);

    //specify the input
    jpeg_stdio_src(&cinfo, infile);

    //read headers
    (void) jpeg_read_header(&cinfo, TRUE);

    return 0;
}

The problem is that the call to jpeg_read_header() fails with an access violation:

Unhandled exception at 0x7c91b1fa (ntdll.dll) in JPEGTest.exe: 0xC0000005: Access violation writing location 0x00000010.

Does anyone have any ideas what I might be doing wrong?

解决方案

I've just encountered the same problem (although I was trying to encode an image). Apparently, FILE* are not portable between DLLs so you can't use any libjpeg API that takes a FILE* as a parameter.

There are several solutions, but they all come down to having to rebuild the library:

  • Build the library as a static lib, and link it to your application. This is what I did, and it solved my problem.
  • Move the source/destination handlers out of libjpeg and into your application. Then you could build libjpeg as either a static lib or a DLL, whichever suits you. I'm not sure whether this would work, but it is the suggested solution in the "install.doc" file distributed with the source code.

这篇关于JPEG支持与IJG - 获得访问冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆