ImageMagick接口有
Image::read(const string& filename);
以及
Blob my_blob; // create a blob
Image my_image("my_image.gif"); // create an image form a GIF image file
my_image.magick("JPEG"); // set JPEG output format
my_image.write(&my_blob); // encode 'my_image' in JPEG format,
// and store the encoded image in my_blob
Image image_from_blob(my_blob); // create an image from the JPEG blob
// (use the Blob-based Image constructor)
image_from_blob.magick("BMP"); // set the image format to bitmap
image_from_blob.write("image_from_blob.bmp"); // save the image on disk in BMP format
但是如果有内存数据 byte[] 存储 如 RGB,则无法通过上述接口进行转换,
以OPencv为例,
opencv TO image
Image Ipl2Magick(IplImage* iplImage)
{
Image mgk(iplImage->width, iplImage->height, "BGR", CharPixel, (char *)iplImage->imageData);
return mgk;
}
image TO opencv
void Magick2Ipl(Image magicImage, IplImage* cvImage)
{
int width= magicImage.size().width();
int height = magicImage.size().height();
byte* blob= new byte[cvImage->imageSize];
magicImage.write(0,0, width, height, "BGRA", MagickCore::CharPixel, blob);
memcpy(cvImage->imageData, blob, cvImage->imageSize);
delete [] blob;
}
切记,4通道~
IplImage* cvimg = cvCreateImage(cvSize(...,...), IPL_DEPTH_8U, 4);
REFERENCE