Magick++ Blob 到图像错误

Magick++ Blob to Image Error

美好的一天,

我有关于将 Magick++ Blob 转换为 Magick Image 的问题。这是场景:

In my C# project, it passes a byte data contains a pdf file, i used "string response = Encoding.ASCII.GetString(RESP);" to convert it to unsigned *char where my custom DLL is needed which is in C++.

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. 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." because its a DLL.

这是我的自定义 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

我找到了这个问题的答案。我将接收到的数据类型更改为 BYTE,并在我的 C# 中发送了字节本身。我将 BYTE 转换为 const void* 并且所有事情都解决了。然后因为我在 PDF 上进行测试,所以我使用了 "readImages" 方法,现在它可以正常工作了。

编辑:我也很傻,要获得 blob 的长度,它应该是 "blob.length()" 而不是 sizeof。感谢@emcconville 指出。