예제 #1
0
        public static Image GetImageFromImageInfos(ImageInfos ImgInfos, bool DoCrop)
        {
            if (ImgInfos.Path == null)
            {
                return(null);
            }
            Image imgRes = Image.FromFile(ImgInfos.Path);

            imgRes = Flip(imgRes, ImgInfos.Flip);
            imgRes = Rotate(imgRes, ImgInfos.Rotate);
            if (DoCrop)
            {
                if (ImgInfos.Crop.Left != -1)
                {
                    imgRes = Crop(imgRes, ImgInfos.Crop);
                }
                else
                {
                    ImgInfos.Crop = GetDefaultCropFromImageInfos(ImgInfos, imgRes.Size);
                    imgRes        = Crop(imgRes, ImgInfos.Crop);
                }
            }

            return(imgRes);
        }
예제 #2
0
        public static Rectangle GetDefaultCropFromImageInfos(ImageInfos ImgInfos, Size ImageSize)
        {
            float srcRatio  = ((float)ImageSize.Width) / ((float)ImageSize.Height);
            float destRatio = ((float)ImgInfos.Region.Width) / ((float)ImgInfos.Region.Height);
            float left      = 0;
            float top       = 0;
            float width     = (float)ImageSize.Width;
            float height    = (float)ImageSize.Height;

            if (srcRatio > destRatio)            //larger
            {
                width = height * destRatio;
                left  = ((float)ImageSize.Width - width) / 2F;
            }
            else                //taller
            {
                height = width / destRatio;
                top    = ((float)ImageSize.Height - height) / 2F;
            }
            return(new Rectangle((int)left, (int)top, (int)width, (int)height));
        }
        private static List<ImageInfos> getEmptyGridTemplate(Size PhotoSize, Padding PhotoMargin, Size PageSize, Padding PageMargin)
        {
            // TODO add template creation
            // TODO replace List<ImageInfos> with a real template class or struct
            int ncols = (int)((float)(PageSize.Width - PageMargin.Left - PageMargin.Right)/(float)PhotoSize.Width);
            int nrows = (int)((float)(PageSize.Height - PageMargin.Top - PageMargin.Bottom)/(float)PhotoSize.Height);

            List<PhotoPatchworkLibs.ImageInfos> Template = new List<PhotoPatchworkLibs.ImageInfos>();

            for (int col=0; col<ncols; col++) {
                for (int row=0; row<nrows; row++) {
                    ImageInfos ii = new ImageInfos();
                    // TODO use isEmpty instead of -1 detection
                    ii.Crop = new Rectangle(-1, -1, -1, -1);
                    ii.Region = new Rectangle((PhotoSize.Width + PhotoMargin.Left + PhotoMargin.Right) * col - PhotoMargin.Right,
                                              (PhotoSize.Height + PhotoMargin.Top + PhotoMargin.Bottom) * row - PhotoMargin.Bottom,
                                              PhotoSize.Width,
                                              PhotoSize.Height);
                    Template.Add(ii);
                }
            }

            return Template;
        }
예제 #4
0
 public static Image GetImageFromImageInfos(ImageInfos ImgInfos)
 {
     return(GetImageFromImageInfos(ImgInfos, true));
 }
        public static Image GetImageFromImageInfos(ImageInfos ImgInfos, bool DoCrop)
        {
            if (ImgInfos.Path == null) {
                return null;
            }
            Image imgRes = Image.FromFile(ImgInfos.Path);

            imgRes = Flip(imgRes, ImgInfos.Flip);
            imgRes = Rotate(imgRes, ImgInfos.Rotate);
            if (DoCrop) {
                if (ImgInfos.Crop.Left != -1) {
                    imgRes = Crop(imgRes, ImgInfos.Crop);
                } else {
                    ImgInfos.Crop = GetDefaultCropFromImageInfos(ImgInfos, imgRes.Size);
                    imgRes = Crop(imgRes, ImgInfos.Crop);
                }
            }

            return imgRes;
        }
 public static Image GetImageFromImageInfos(ImageInfos ImgInfos)
 {
     return GetImageFromImageInfos (ImgInfos, true);
 }
 public static Rectangle GetDefaultCropFromImageInfos(ImageInfos ImgInfos, Size ImageSize)
 {
     float srcRatio = ((float)ImageSize.Width)/((float)ImageSize.Height);
     float destRatio = ((float)ImgInfos.Region.Width)/((float)ImgInfos.Region.Height);
     float left = 0;
     float top = 0;
     float width = (float)ImageSize.Width;
     float height = (float)ImageSize.Height;
     if (srcRatio>destRatio) {//larger
         width = height*destRatio;
         left = ((float)ImageSize.Width-width)/2F;
     } else {//taller
         height = width/destRatio;
         top = ((float)ImageSize.Height-height)/2F;
     }
     return new Rectangle((int)left, (int)top, (int)width, (int)height);
 }