Problem with image offset

Magick.NET is an object-oriented C# interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick.NET
Post Reply
k0sm4s
Posts: 1
Joined: 2015-06-12T07:04:18-07:00
Authentication code: 6789

Problem with image offset

Post by k0sm4s »

Hello everybody,

I'm new in using imagemagick and I have a problem.
I'm trying to combine to images in one and everything works fine except the offset of my first image. I m tring to put a small image in the center of a second which is a frame but it doesnt move in anyway and keeps appearing in the top-left corner. Here's my code

Code: Select all

 using (MagickImageCollection images = new MagickImageCollection())
            {

                MagickImage first = new MagickImage(name);              
                first.Format = MagickFormat.Png;                   
                MagickGeometry size = new MagickGeometry(210,180,640, 442);
                size.IgnoreAspectRatio = true;
                first.AdaptiveResize(size);
                images.Add(first);
           
                MagickImage frame = new MagickImage("korniza.png");
                images.Add(frame);


                using (MagickImage result = images.Mosaic())
                {
                    result.Write("Mosaic.png");
                }
            }
I've also tried the size.X command and the first.Page.X but still nothing.

My guess is tha the image must be relative to something if it is to get an offset but I don't know hot to do that either.

Please give me a hand in this,
thank you in advance.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Problem with image offset

Post by dlemstra »

You might already solved this but it was probably not working because you did not realize that IamgeMagick.Page would return a new instance instead of the same object. You should write the code like this:

Code: Select all

using (MagickImageCollection collection = new MagickImageCollection())
{
  collection.Add(new MagickImage(new MagickColor("purple"), 1024,1024));
  MagickImage frame = new MagickImage("logo:");
  frame.Page = new MagickGeometry(300, 100, 0, 0);
  collection.Add(frame);

  using (MagickImage moscaic = collection.Mosaic())
  {
    moscaic.Write(@"C:\Mosaic.png");
  }
}
I will see if I can make this more clear in the API.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
Post Reply