简体   繁体   English

Magick ++ Blob到图像错误

[英]Magick++ Blob to Image Error

Good day, 美好的一天,

I have this problem regarding to Magick++ Blob converting it to Magick Image. 我有关于Magick ++ Blob将其转换为Magick Image的问题。 Here is the scenario: 这是场景:

In my C# project, it passes a byte data contains a pdf file, i used "string response = Encoding.ASCII.GetString(RESP);" 在我的C#项目中,它传递一个包含pdf文件的字节数据,我使用了“字符串响应= Encoding.ASCII.GetString(RESP);” to convert it to unsigned *char where my custom DLL is needed which is in C++. 将其转换为C ++中需要我的自定义DLL的无符号* char。

In my custom DLL, I converted again the unsigned char to const void which Magick Blob is needed then I created a Blob and all is fine. 在我的自定义DLL中,我再次将unsigned char转换为const void ,需要使用Magick Blob,然后创建了一个Blob,一切都很好。 But when I convert the blob to Magick Image, it returns an error but my C# only returns the error "External component has thrown an exception." 但是,当我将Blob转换为Magick Image时,它返回一个错误,但是我的C#仅返回错误“外部组件引发了异常”。 because its a DLL. 因为它是一个DLL。

Here is my Custom DLL Code: 这是我的自定义DLL代码:

#include <stdio.h>
#include <string>
#include <Windows.h>
#include <Magick++.h>
#include <zbar.h>
#include <fstream>
#include <opencv2\opencv.hpp>
extern "C"
{
    const void* convert(unsigned char arr[]);

    __declspec(dllexport) const char* ScammingQRCode(unsigned char *pdf){
               Magick::InitializeMagick("");

               size_t s = sizeof(pdf);
               const void* bl = convert(pdf);
               Magick::Blob blob(bl, s);

               Magick::Image image;
               image.depth(8);
               image.read(blob);
    }

    const void* convert(unsigned char arr[]){
          return arr;
    }
}

Note: I am using ImageMagick-7.0.6-Q16 注意:我正在使用ImageMagick-7.0.6-Q16

I found the answer to this problem. 我找到了这个问题的答案。 I changed the received data type to BYTE and in my C# I sent the byte itself. 我将接收到的数据类型更改为BYTE,并在C#中发送了字节本身。 I converted the BYTE to const void* and all things worked out. 我将BYTE转换为const void *,所有事情都解决了。 Then because I am testing on PDFs, I used the "readImages" method and it now perfectly working. 然后,因为我正在对PDF进行测试,所以我使用了“ readImages”方法,现在它可以完美地工作了。

Edit: Also silly of me, to get the length of the blob it should be "blob.length()" and not sizeof. 编辑:我也很愚蠢,要获取blob的长度,它应该是“ blob.length()”而不是sizeof。 Thanks to @emcconville for pointing it out. 感谢@emcconville指出这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM