예제 #1
0
        private Point ResizeMaxWidth(Bitmap image, Photo_Setting myPhoto_Setting)
        {
            Point myPoint = new Point(myPhoto_Setting.Resize_Width, image.Height);

            if (image.Width > myPhoto_Setting.Resize_Width)
            {
                Single ratio = myPhoto_Setting.Resize_Width / Convert.ToSingle(image.Width);
                myPoint.X = Convert.ToInt32(image.Width * ratio);
                myPoint.Y = Convert.ToInt32(image.Height * ratio);
            }

            return(myPoint);
        }
예제 #2
0
        private Point ResizeMinHeightMinWidth(Bitmap image, Photo_Setting myPhoto_Setting)
        {
            Point myPoint = new Point(myPhoto_Setting.Resize_Width, myPhoto_Setting.Resize_Height);

            if (image.Height < myPhoto_Setting.Resize_Height)
            {
                Single ratio = myPhoto_Setting.Resize_Height / Convert.ToSingle(image.Height);
                myPoint.X = Convert.ToInt32(image.Width * ratio);
                myPoint.Y = Convert.ToInt32(image.Height * ratio);
            }

            if (myPoint.X < myPhoto_Setting.Resize_Width)
            {
                Single ratio = myPhoto_Setting.Resize_Width / Convert.ToSingle(myPoint.X);
                myPoint.X = Convert.ToInt32(myPoint.X * ratio);
                myPoint.Y = Convert.ToInt32(myPoint.Y * ratio);
            }

            return(myPoint);
        }
예제 #3
0
 private Point OverlayBottomRight(Bitmap image, Bitmap overlay_image, Photo_Setting myPhoto_Setting)
 {
     return(new Point(image.Size.Width - overlay_image.Size.Width - myPhoto_Setting.Overlay_PaddingX,
                      image.Size.Height - overlay_image.Height - myPhoto_Setting.Overlay_PaddingY));
 }
예제 #4
0
 private Point OverlayCenter(Bitmap image, Bitmap overlay_image, Photo_Setting myPhoto_Setting)
 {
     return(new Point(image.Size.Width / 2 - overlay_image.Size.Width / 2 + myPhoto_Setting.Overlay_PaddingX,
                      image.Size.Height / 2 - overlay_image.Size.Height / 2 + myPhoto_Setting.Overlay_PaddingY));
 }
예제 #5
0
 private Point OverlayTopLeft(Bitmap image, Bitmap overlay_image, Photo_Setting myPhoto_Setting)
 {
     return(new Point(myPhoto_Setting.Overlay_PaddingX, myPhoto_Setting.Overlay_PaddingY));
 }
예제 #6
0
 private Point ResizeFixed(Bitmap image, Photo_Setting myPhoto_Setting)
 {
     return(new Point(myPhoto_Setting.Resize_Width, myPhoto_Setting.Resize_Height));
 }
예제 #7
0
        public void InitImg(HttpContext context, string DisplayID, string PhotoID)
        {
            Photo         myPhoto         = Get_Photo(PhotoID);
            Photo_Setting myPhoto_Setting = Get_Photo_Setting(DisplayID);

            Bitmap bitMapImage;

            // 检测文件是否存在
            if (myPhoto.ImageURL_Type == ImageURL_Type.Internal)
            {
                // 本地文件
                if (File.Exists(context.Server.MapPath(myPhoto.ImageURL)))
                {
                    bitMapImage = new Bitmap(context.Server.MapPath(myPhoto.ImageURL));
                }
                else
                {
                    bitMapImage = new Bitmap(context.Server.MapPath(myPhoto_Setting.Image_BrokenURL));
                }
            }
            else
            {
                // 远程文件
                try
                {
                    bitMapImage = ImgLib.GetBitmapFromUri(myPhoto.ImageURL);
                }
                catch
                {
                    bitMapImage = new Bitmap(context.Server.MapPath(myPhoto_Setting.Image_BrokenURL));
                }
            }

            // Photo Setting
            if (myPhoto_Setting.IsResize)
            {
                Point resizePoint = new Point();

                switch (myPhoto_Setting.Resize_Type)
                {
                case Resize_Type.Fixed:
                    resizePoint = ResizeFixed(bitMapImage, myPhoto_Setting);
                    break;

                case Resize_Type.MinHeight:
                    resizePoint = ResizeMinHeight(bitMapImage, myPhoto_Setting);
                    break;

                case Resize_Type.MinWidth:
                    resizePoint = ResizeMinWidth(bitMapImage, myPhoto_Setting);
                    break;

                case Resize_Type.MinHeight_and_MinWidth:
                    resizePoint = ResizeMinHeightMinWidth(bitMapImage, myPhoto_Setting);
                    break;

                case Resize_Type.MaxHeight:
                    resizePoint = ResizeMaxHeight(bitMapImage, myPhoto_Setting);
                    break;

                case Resize_Type.MaxWidth:
                    resizePoint = ResizeMaxWidth(bitMapImage, myPhoto_Setting);
                    break;

                case Resize_Type.MaxHeight_and_MaxWidth:
                    resizePoint = ResizeMaxHeightMaxWidth(bitMapImage, myPhoto_Setting);
                    break;
                }

                bitMapImage = ImgLib.ResizeBitmap(bitMapImage, resizePoint.X, resizePoint.Y);
            }

            if (myPhoto_Setting.IsOverlay)
            {
                Bitmap overlayBitmap = new Bitmap(context.Server.MapPath(myPhoto_Setting.Overlay_ImageURL));
                Point  overlayPoint  = new Point();

                switch (myPhoto_Setting.Overlay_Position)
                {
                case Overlay_Position.TopLeft:
                    overlayPoint = OverlayTopLeft(bitMapImage, overlayBitmap, myPhoto_Setting);
                    break;

                case Overlay_Position.TopRight:
                    overlayPoint = OverlayTopRight(bitMapImage, overlayBitmap, myPhoto_Setting);
                    break;

                case Overlay_Position.Center:
                    overlayPoint = OverlayCenter(bitMapImage, overlayBitmap, myPhoto_Setting);
                    break;

                case Overlay_Position.BottomLeft:
                    overlayPoint = OverlayBottomLeft(bitMapImage, overlayBitmap, myPhoto_Setting);
                    break;

                case Overlay_Position.BottomRight:
                    overlayPoint = OverlayBottomRight(bitMapImage, overlayBitmap, myPhoto_Setting);
                    break;
                }

                bitMapImage = ImgLib.OverlayBitmap(bitMapImage, overlayBitmap, myPhoto_Setting.Overlay_Opacity, overlayPoint);
            }

            ShowImg(context, bitMapImage);
        }