Good day,
I have this problem regarding to Magick++ Blob converting it to 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);" 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.
Here is my Custom DLL Code:
#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
I found the answer to this problem. I changed the received data type to BYTE and in my C# I sent the byte itself. I converted the BYTE to const void* and all things worked out. Then because I am testing on PDFs, I used the "readImages" method and it now perfectly working.
Edit: Also silly of me, to get the length of the blob it should be "blob.length()" and not sizeof. Thanks to @emcconville for pointing it out.