Answer the question
In order to leave comments, you need to log in
How to convert an image (imagick --> System.Drawing.Image) or alternatives to this?
Good day.
I created a "windows forms application", it has a pictureBox (a window in which the picture is displayed), you need to blur this picture before showing it in the pictureBox.
The sequence is: file loading, blur somewhere in memory, display. I want to use ImageMagick for blurring, but the question is: how can I then transfer this imagick's image to the Microsoft Image class? I looked - it seems that you can set a bitmap image pixel by pixel, but it seems to me that this is extra work.
Are there any ways to do this, or alternatives?
Answer the question
In order to leave comments, you need to log in
I solved this issue in this way:
// load image from file
System::Drawing::Bitmap^ imageCLI_RGB = gcnew System::Drawing::Bitmap^(L"Lena.jpg");
// resize image for change RGB to RGBA values
System::Drawing::Bitmap^ imageCLI_RGBA = gcnew System::Drawing::Bitmap(imageCLI_RGB, 640, 480);
// lock the bitmap's bits.
System::Drawing::Rectangle rect = System::Drawing::Rectangle(0, 0, imageCLI_RGBA->Width, imageCLI_RGBA->Height);
System::Drawing::Imaging::BitmapData^ bmpData = imageCLI_RGBA->LockBits(rect, System::Drawing::Imaging::ImageLockMode::ReadWrite, imageCLI_RGBA->PixelFormat);
// get the address of the first line.
System::IntPtr ptr = bmpData->Scan0;
// declare an array to hold the bytes of the bitmap.
// this code is specific to a bitmap with 24 bits per pixels.
int bytes = System::Math::Abs(bmpData->Stride) * imageCLI_RGBA->Height;
array<System::Byte>^ rgbValues = gcnew array<System::Byte>(bytes);
// copy the RGBA values into the array.
System::Runtime::InteropServices::Marshal::Copy(ptr, rgbValues, 0, bytes);
/***** ALL MAGICK HERE *****/
// RGBA contains CLI char array to simple char array
pin_ptr<unsigned char> p = &rgbValues[0];
unsigned char* rgbaTable = p;
// add RGBA values to ImageMagick image
Magick::Image* imageIM = new Magick::Image(imageCLI_RGBA->Width, imageCLI_RGBA->Height, "RGBA", Magick::CharPixel, rgbaTable);
// blur image
imageIM->gaussianBlur(3, 2);
// copy values back to the RGBA array
imageIM->write(0, 0, imageCLI_RGBA->Width, imageCLI_RGBA->Height, "RGBA", Magick::CharPixel, rgbaTable);
delete imageIM;
/***** END MAGICK *****/
// copy array to image
System::Runtime::InteropServices::Marshal::Copy(rgbValues, 0, ptr, bytes);
// unlock the bits.
imageCLI_RGBA->UnlockBits(bmpData);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question