public static string GetImageResizeUrl(string path, int?width = null, int?height = null, ResizeMode resizeMode = ResizeMode.Undefined)
        {
            if (string.IsNullOrEmpty(path) || (!width.HasValue && !height.HasValue))
            {
                return(path);
            }

            var pathParts = path.Split('?');
            var query     = HttpUtility.ParseQueryString(pathParts.Length > 1 ? pathParts[1] : string.Empty);

            if (width.HasValue)
            {
                query["width"] = width.ToString();
            }

            if (height.HasValue)
            {
                query["height"] = height.ToString();
            }

            if (resizeMode != ResizeMode.Undefined)
            {
                query["rmode"] = resizeMode.ToString().ToLower();
            }

            return($"{pathParts[0]}?{query.ToString()}");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Convert this object to a raw proto.
        /// </summary>
        /// <param name="strName">Specifies the name of the proto.</param>
        /// <returns>The new proto is returned.</returns>
        public override RawProto ToProto(string strName)
        {
            RawProto           rpBase     = base.ToProto("option");
            RawProtoCollection rgChildren = new RawProtoCollection();

            rgChildren.Add(rpBase);
            rgChildren.Add(new RawProto("active", Active.ToString()));
            rgChildren.Add(new RawProto("prob", prob.ToString()));
            rgChildren.Add(new RawProto("resize_mode", m_mode.ToString()));
            rgChildren.Add(new RawProto("pad_mode", m_pad.ToString()));
            rgChildren.Add(new RawProto("height", m_nHeight.ToString()));
            rgChildren.Add(new RawProto("width", m_nWidth.ToString()));
            rgChildren.Add(new RawProto("height_scale", m_nHeightScale.ToString()));
            rgChildren.Add(new RawProto("width_scale", m_nWidthScale.ToString()));

            foreach (InterpMode interp in m_rgInterp)
            {
                rgChildren.Add(new RawProto("interp_mode", interp.ToString()));
            }

            foreach (float fPad in m_rgfPadValue)
            {
                rgChildren.Add(new RawProto("pad_value", fPad.ToString()));
            }

            return(new RawProto(strName, "", rgChildren));
        }
Ejemplo n.º 3
0
        public static string GetImageResizeUrl(string path, IDictionary <string, string> queryStringParams = null, int?width = null, int?height = null, ResizeMode resizeMode = ResizeMode.Undefined, int?quality = null, Format format = Format.Undefined, Anchor anchor = null, string bgcolor = null)
        {
            if (string.IsNullOrEmpty(path) || (!width.HasValue && !height.HasValue && queryStringParams == null))
            {
                return(path);
            }

            if (queryStringParams == null)
            {
                queryStringParams = new Dictionary <string, string>();
            }

            if (width.HasValue)
            {
                queryStringParams["width"] = width.ToString();
            }

            if (height.HasValue)
            {
                queryStringParams["height"] = height.ToString();
            }

            if (resizeMode != ResizeMode.Undefined)
            {
                queryStringParams["rmode"] = resizeMode.ToString().ToLower();
            }

            if (quality.HasValue)
            {
                queryStringParams["quality"] = quality.ToString();
            }

            if (format != Format.Undefined)
            {
                queryStringParams["format"] = format.ToString().ToLower();
            }

            if (anchor != null)
            {
                queryStringParams["rxy"] = anchor.X.ToString(CultureInfo.InvariantCulture) + ',' + anchor.Y.ToString(CultureInfo.InvariantCulture);
            }

            if (!String.IsNullOrEmpty(bgcolor))
            {
                queryStringParams["bgcolor"] = bgcolor;
            }

            return(QueryHelpers.AddQueryString(path, queryStringParams));
        }
Ejemplo n.º 4
0
    /// <summary>
    /// อัพโหลดภาพ พร้อมย่อขนาด
    /// </summary>
    /// <param name="fuPhoto"></param>
    /// <param name="pathShort"></param>
    /// <param name="photoName"></param>
    /// <param name="errorMessage"></param>
    /// <param name="outFileName"></param>
    /// <param name="maxSizeKB"></param>
    /// <param name="maxWidth"></param>
    /// <param name="maxHeight"></param>
    /// <param name="resizeAnchor"></param>
    /// <param name="resizeMode"></param>
    /// <param name="resizeFormat"></param>
    /// <returns></returns>
    /// <example>
    /// clsIO clsIO = new clsIO();
    /// string outErrorMessage;
    /// string outFileName;
    /// clsIO.UploadPhoto(fuPhoto, "/Upload/", "TestResize", out outErrorMessage, out outFileName);
    /// clsIO.UploadPhoto(fuPhoto, "/Upload/", "TestResize", out outErrorMessage, out outFileName,maxWidth:200,resizeFormat:clsIO.ResizeFormat.png);
    /// clsIO.UploadPhoto(fuPhoto, "/Upload/", "TestResize", out outErrorMessage, out outFileName,maxWidth:200,maxHeight:200,resizeFormat:clsIO.ResizeFormat.png);
    /// clsIO.UploadPhoto(fuPhoto, "/Upload/", "TestResize", out outErrorMessage, out outFileName,maxWidth:200,maxHeight:200,resizeMode:clsIO.ResizeMode.crop,resizeQuality:100);
    /// </example>
    public bool UploadPhoto(FileUpload fuPhoto, string pathShort, string photoName, out string errorMessage, out string outFileName, int maxSizeKB = 0, int maxWidth = 0, int maxHeight = 0, ResizeAnchor resizeAnchor = ResizeAnchor.middlecenter, ResizeMode resizeMode = ResizeMode.crop, ResizeFormat resizeFormat = ResizeFormat.original, int resizeQuality = 90)
    {
        bool rtnValue = true;

        errorMessage = "";
        outFileName  = "";

        if (fuPhoto.HasFile == true)
        {
            #region Error Checker
            if (FileTypeChecker(fuPhoto.FileName) != "IMG")
            {
                errorMessage = "โปรดเลือกเฉพาะไฟล์รูปภาพ";
                fuPhoto.Focus();
                return(false);
            }
            if (maxSizeKB > 0)
            {
                if (fuPhoto.PostedFile.ContentLength > maxSizeKB * 1000)
                {
                    errorMessage = "ขนาดไฟล์ใหญ่เกิน " + maxSizeKB + " KB";
                    fuPhoto.Focus();
                    return(false);
                }
            }
            #endregion

            #region Out FileName
            if (resizeFormat != ResizeFormat.original)
            {
                outFileName = photoName + "." + resizeFormat.ToString();
            }
            else
            {
                outFileName = photoName + System.IO.Path.GetExtension(fuPhoto.FileName).ToLower();
            }
            #endregion

            FileExist(pathShort + outFileName, true);

            #region Upload Photo
            try
            {
                fuPhoto.SaveAs(System.Web.HttpContext.Current.Server.MapPath(pathShort + outFileName));
            }
            catch (Exception ex)
            {
                errorMessage = "เกิดข้อผิดพลาด ขณะอัพโหลดไฟล์ไว้ที่ " + System.Web.HttpContext.Current.Server.MapPath(pathShort + outFileName + "<br/>" + ex.Message);
                fuPhoto.Focus();
                return(false);
            }
            #endregion

            #region Resize Photo
            try
            {
                #region Condition Builder
                string resizeSetting = "";
                if (maxWidth > 0)
                {
                    if (resizeSetting.Length > 0)
                    {
                        resizeSetting += "&";
                    }
                    resizeSetting += "width=" + maxWidth.ToString();
                }
                if (maxHeight > 0)
                {
                    if (resizeSetting.Length > 0)
                    {
                        resizeSetting += "&";
                    }
                    resizeSetting += "height=" + maxHeight.ToString();
                }
                if (resizeMode != ResizeMode.pad)
                {
                    if (resizeSetting.Length > 0)
                    {
                        resizeSetting += "&";
                    }
                    resizeSetting += "mode=" + resizeMode.ToString();
                }
                if (resizeAnchor != ResizeAnchor.middlecenter)
                {
                    if (resizeSetting.Length > 0)
                    {
                        resizeSetting += "&";
                    }
                    resizeSetting += "anchor=" + resizeAnchor.ToString();
                }
                if (resizeFormat != ResizeFormat.original)
                {
                    if (resizeSetting.Length > 0)
                    {
                        resizeSetting += "&";
                    }
                    resizeSetting += "format=" + resizeFormat.ToString();
                }
                if (resizeQuality != 90)
                {
                    if (resizeSetting.Length > 0)
                    {
                        resizeSetting += "&";
                    }
                    resizeSetting += "quality=" + resizeQuality.ToString();
                }
                #endregion

                if (resizeSetting.Length > 0)
                {
                    ResizeSettings imageResizerSetting = new ResizeSettings(resizeSetting);
                    ImageBuilder.Current.Build(
                        System.Web.HttpContext.Current.Server.MapPath(pathShort + outFileName),
                        System.Web.HttpContext.Current.Server.MapPath(pathShort + outFileName), imageResizerSetting);
                }
            }
            catch (Exception ex)
            {
                errorMessage = "เกิดข้อผิดพลาด ขณะย่อขนาดภาพ : " + ex.Message;
                fuPhoto.Focus();
                return(false);
            }
            #endregion
        }
        else
        {
            errorMessage = "ไม่พบไฟล์ที่ต้องการอัพโหลด";
            fuPhoto.Focus();
            return(false);
        }

        return(rtnValue);
    }
Ejemplo n.º 5
0
    /// <summary>
    /// อัพโหลดภาพ พร้อมย่อขนาด
    /// </summary>
    /// <param name="fuPhoto"></param>
    /// <param name="pathShort"></param>
    /// <param name="photoName"></param>
    /// <param name="errorMessage"></param>
    /// <param name="outFileName"></param>
    /// <param name="maxSizeKB"></param>
    /// <param name="maxWidth"></param>
    /// <param name="maxHeight"></param>
    /// <param name="resizeAnchor"></param>
    /// <param name="resizeMode"></param>
    /// <param name="resizeFormat"></param>
    /// <returns></returns>
    /// <example>
    /// clsIO clsIO = new clsIO();
    /// string outErrorMessage;
    /// string outFileName;
    /// clsIO.UploadPhoto(fuPhoto, "/Upload/", "TestResize", out outErrorMessage, out outFileName);
    /// clsIO.UploadPhoto(fuPhoto, "/Upload/", "TestResize", out outErrorMessage, out outFileName,maxWidth:200,resizeFormat:clsIO.ResizeFormat.png);
    /// clsIO.UploadPhoto(fuPhoto, "/Upload/", "TestResize", out outErrorMessage, out outFileName,maxWidth:200,maxHeight:200,resizeFormat:clsIO.ResizeFormat.png);
    /// clsIO.UploadPhoto(fuPhoto, "/Upload/", "TestResize", out outErrorMessage, out outFileName,maxWidth:200,maxHeight:200,resizeMode:clsIO.ResizeMode.crop,resizeQuality:100);
    /// </example>
    public bool UploadPhoto(FileUpload fuPhoto, string pathShort, string photoName, out string errorMessage, out string outFileName, int maxSizeKB = 0, int maxWidth = 0, int maxHeight = 0, ResizeAnchor resizeAnchor = ResizeAnchor.middlecenter, ResizeMode resizeMode = ResizeMode.crop, ResizeFormat resizeFormat = ResizeFormat.original, int resizeQuality = 90)
    {

        bool rtnValue = true;
        errorMessage = "";
        outFileName = "";

        if (fuPhoto.HasFile == true)
        {
            #region Error Checker
            if (FileTypeChecker(fuPhoto.FileName) != "IMG")
            {
                errorMessage = "โปรดเลือกเฉพาะไฟล์รูปภาพ";
                fuPhoto.Focus();
                return false;
            }
            if (maxSizeKB > 0)
            {
                if (fuPhoto.PostedFile.ContentLength > maxSizeKB * 1000)
                {
                    errorMessage = "ขนาดไฟล์ใหญ่เกิน " + maxSizeKB + " KB";
                    fuPhoto.Focus();
                    return false;
                }
            }
            #endregion

            #region Out FileName
            if (resizeFormat != ResizeFormat.original)
            {
                outFileName = photoName + "." + resizeFormat.ToString();
            }
            else
            {
                outFileName = photoName + System.IO.Path.GetExtension(fuPhoto.FileName).ToLower();
            }
            #endregion

            FileExist(pathShort + outFileName, true);

            #region Upload Photo
            try
            {
                fuPhoto.SaveAs(System.Web.HttpContext.Current.Server.MapPath(pathShort + outFileName));
            }
            catch (Exception ex)
            {
                errorMessage = "เกิดข้อผิดพลาด ขณะอัพโหลดไฟล์ไว้ที่ " + System.Web.HttpContext.Current.Server.MapPath(pathShort + outFileName + "<br/>" + ex.Message);
                fuPhoto.Focus();
                return false;
            }
            #endregion

            #region Resize Photo
            try
            {
                #region Condition Builder
                string resizeSetting = "";
                if (maxWidth > 0)
                {
                    if (resizeSetting.Length > 0) resizeSetting += "&";
                    resizeSetting += "width=" + maxWidth.ToString();
                }
                if (maxHeight > 0)
                {
                    if (resizeSetting.Length > 0) resizeSetting += "&";
                    resizeSetting += "height=" + maxHeight.ToString();
                }
                if (resizeMode != ResizeMode.pad)
                {
                    if (resizeSetting.Length > 0) resizeSetting += "&";
                    resizeSetting += "mode=" + resizeMode.ToString();
                }
                if (resizeAnchor != ResizeAnchor.middlecenter)
                {
                    if (resizeSetting.Length > 0) resizeSetting += "&";
                    resizeSetting += "anchor=" + resizeAnchor.ToString();
                }
                if (resizeFormat != ResizeFormat.original)
                {
                    if (resizeSetting.Length > 0) resizeSetting += "&";
                    resizeSetting += "format=" + resizeFormat.ToString();
                }
                if (resizeQuality != 90)
                {
                    if (resizeSetting.Length > 0) resizeSetting += "&";
                    resizeSetting += "quality=" + resizeQuality.ToString();
                }
                #endregion

                if (resizeSetting.Length > 0)
                {
                    ResizeSettings imageResizerSetting = new ResizeSettings(resizeSetting);
                    ImageBuilder.Current.Build(
                        System.Web.HttpContext.Current.Server.MapPath(pathShort + outFileName),
                        System.Web.HttpContext.Current.Server.MapPath(pathShort + outFileName), imageResizerSetting);
                }
            }
            catch (Exception ex)
            {
                errorMessage = "เกิดข้อผิดพลาด ขณะย่อขนาดภาพ : " + ex.Message;
                fuPhoto.Focus();
                return false;
            }
            #endregion
        }
        else
        {
            errorMessage = "ไม่พบไฟล์ที่ต้องการอัพโหลด";
            fuPhoto.Focus();
            return false;
        }

        return rtnValue;
    }
Ejemplo n.º 6
0
        void button_Click(object sender, RoutedEventArgs e)
        {
            Button      button = (Button)sender;
            WindowStyle style  = (WindowStyle)Enum.Parse(typeof(WindowStyle), (string)button.Content);
            ResizeMode  resize = (ResizeMode)Enum.Parse(typeof(ResizeMode), (string)resizeCombo.Text);

            Window window = new Window();

            window.Initialized += new EventHandler(window_Initialized);
            window.Unloaded    += new RoutedEventHandler(window_Unloaded);

            // do look 'n' feel
            //window.Background = Brushes.Yellow;
            window.WindowStyle = style;
            window.ResizeMode  = resize;
            //window.Owner = this;
            if (Properties.Settings.Default.ShowResizeMode)
            {
                window.Content = " WindowStyle." + style.ToString() + "\r\n ResizeMode." + resize.ToString() + "\r\n (" + Properties.Settings.Default.OsThemeLabel + ")";
            }
            else
            {
                window.Content = " WindowStyle." + style.ToString() + "\r\n\r\n (" + Properties.Settings.Default.OsThemeLabel + ")";
            }
            window.Width      = 220;
            window.Height     = 100;
            window.MouseDown += delegate(object sender2, MouseButtonEventArgs e2) { window.DragMove(); };
            window.Title      = "The Title";

            if (modalCheckBox.IsChecked == true)
            {
                window.ShowDialog();
            }
            else
            {
                window.Show();
            }
        }