locked
Create a image and place an exsisting image in it and create the correct position RRS feed

  • Question

  • User-1103495211 posted

    I use the code below to position a new exsisting image in a empty image.
    There is also 1 for the width, but that one works great!

    The image is not centered on the new image:

        public System.Drawing.Image resizeHighImage(System.Drawing.Image img, int newSizeY, int newSizeX, int x, int y)
        {
            System.Drawing.Image empty = new Bitmap(newSizeX, newSizeY);      
            Graphics g = Graphics.FromImage(empty);
            g.DrawImage(img, 0, 0 - ((y - newSizeY) / 2), x, y);// This row needs to center it with this: (y - newSizeY), normally it results in (img, 0,-100....  but the image is not -100 on the result).
            g.Save();

            return empty;
            g.Dispose();
        }

    Its basically the same as this code but this code works perfect... , and is for position the image horitzontal... :

         public System.Drawing.Image resizeWidthImage(System.Drawing.Image img, int newSizeY, int newSizeX, int x, int y)
        {
            System.Drawing.Image empty = new Bitmap(newSizeX, newSizeY);
            Graphics g = Graphics.FromImage(empty);
            g.DrawImage(img, 0 - ((x - newSizeX) / 2), 0, x, y);
            g.Save();

            return empty;
            g.Dispose();
        }

    Friday, November 28, 2008 9:25 AM

Answers

  • User-1103495211 posted

    It suddenly works...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, November 28, 2008 11:53 AM