Page 1 of 1

clone a magickimage to a bigger one

Posted: 2016-12-27T22:02:46-07:00
by pablobhz
ello everyone.
I've searched a bit around the discussions\forums, but i couldn't find much information about how to achieve what i'm trying.
Also, i don't see much Magick.NET documentation - where i could obtain it :)

What i'm trying to do is:
I have an very large MagickImage object (9920 width , 7085 height). Its an tiff file i loaded and rotated.

I would like to create a new MagickImage object, larger (10594 width , 7387 height) and place the smaller MagickImage object in the middle of it. I'll be placing also into the upleft position, upright...but thats my next step. For now i just want to place it in the middle of the larger Magickimage , and add some borders. Also, i need this new MagickImage object(the larger one) to have transparent background.

What i tried , but couldn't get any further was:

Code: Select all

agickReadSettings Settings = new MagickReadSettings();
            Settings.Width = Convert.ToInt32(zoneAreaWidth_Pixels);
            Settings.Height = Convert.ToInt32(zoneAreaHeight_Pixels);
            using (MagickImage inkZoneImage = new MagickImage(loadedImage))
            {
                //How to use settings here ?
                //How to position the loadedImage in the middle of inkZoneImage ?

                inkZoneImage.Write(@"C:\DI_PLOT\whatever.png");
            }
And , this is my question. Any help will be greatly appreciated.
Thanks in advance.

Best Regards,
Pablo Costa.

Re: clone a magickimage to a bigger one

Posted: 2017-05-09T21:39:50-07:00
by pablobhz

Code: Select all

 private static void imageComposition(MagickImage newPngImage, int imagePositionCount,List<string> IZInfo)
        {    
            string imageDensity = newPngImage.Density.ToString();
            int removalPos = imageDensity.IndexOf("x");
            imageDensity = imageDensity.Remove(removalPos, imageDensity.Length - removalPos);
            double DPI = Double.Parse(imageDensity);
            double zoneAreaWidth_Pixels = unitConversion.mmToPixel(Double.Parse(IZInfo.ElementAt(4)), DPI); //Width and height for the larger image are in mm , converted them to pixel
            double zoneAreaHeight_Pixels = unitConversion.mmToPixel(Double.Parse(IZInfo.ElementAt(5)), DPI);//Formula (is: mm * imageDPI) / 25.4
            using (MagickImage inkZoneImage = new MagickImage(Color.White, Convert.ToInt32(zoneAreaWidth_Pixels), Convert.ToInt32(zoneAreaHeight_Pixels)))
            {
                using (MagickImage original = newPngImage.Clone())
                {
                    switch (imagePositionCount)
                    {
                        case 0:
                            inkZoneImage.Composite(newPngImage, Gravity.Center);
                            break;
                        case 1:
                            inkZoneImage.Composite(newPngImage, Gravity.Northwest);
                            break;
                        case 2:
                            inkZoneImage.Composite(newPngImage, Gravity.North);
                            break;
                        case 3:
                            inkZoneImage.Composite(newPngImage, Gravity.Northeast);
                            break;
                        case 4:
                            inkZoneImage.Composite(newPngImage, Gravity.West);
                            break;
                        case 5:
                            inkZoneImage.Composite(newPngImage, Gravity.Center);
                            break;
                        case 6:
                            inkZoneImage.Composite(newPngImage, Gravity.East);
                            break;
                        case 7:
                            inkZoneImage.Composite(newPngImage, Gravity.Southwest);
                            break;
                        case 8:
                            inkZoneImage.Composite(newPngImage, Gravity.South);
                            break;
                        case 9:
                            inkZoneImage.Composite(newPngImage, Gravity.Southeast);
                            break;
                    }
                   
                }
How i basically did it.
hope it helps