Example #1
0
 // Start is called before the first frame update
 void Start()
 {
     FixedAspectRatio.Execute(fixedAspectCamera, _width, _height);
 }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        protected override void CreateChildControls()
        {
            //Add the jquery/jcrop includes
            AddFileReferences();

            System.Web.UI.WebControls.Image image =
                Parent.FindControl(this.Image) as System.Web.UI.WebControls.Image;


            string url         = image.ImageUrl;
            string resolvedUrl = url.StartsWith("~") ? ResolveUrl(url) : url;

            ViewState["ImageUrl"] = resolvedUrl;


            //image - '<img />' tag ID, DOM, or jquery reference
            //settings - object

            /*
             * settings = {keepAspectRatio:false,
             *          keepAspectRatioCheckbox: '#id' or reference,
             *          aspectRatio: null or value,
             *          minSize: [w,h],
             *          maxSize: [w,h],
             *          previewDiv: '#id' or reference or null,
             *          previewWidth: (previewDiv original width, or 100),
             *          previewHeight: (previewDiv original height, or 100),
             *          boxWidth: null or value,
             *          boxHeight: null or value,
             *          setSelect: [x1,y1,x2,y2],
             *          updateLinks: "#id1, #id2" or null,
             *          updateFields: "#id1, #id2" or null,
             *          updateImages: "#id1, #id2" or null
             */

            NameValueCollection s = new NameValueCollection();

            if (!string.IsNullOrEmpty(this.FixedAspectRatioCheckboxID))
            {
                Control c = Parent.FindControl(FixedAspectRatioCheckboxID);
                if (c != null)
                {
                    s["keepAspectRatioCheckbox"] = "'#" + c.ClientID + "'";
                }
            }
            s["keepAspectRatio"] = FixedAspectRatio.ToString().ToLower();

            if (!string.IsNullOrEmpty(this.Ratio))
            {
                s["aspectRatio"] = Ratio;
            }

            //If the image URL is a virtual path within the application, and ServerSideResize=true, then use URL resizing; otherwise, use boxWidth/boxHeight
            if (CanvasHeight > 0 | CanvasWidth > 0)
            {
                if (!url.StartsWith("http", StringComparison.OrdinalIgnoreCase) && this.ServerSizeResize)
                {
                    NameValueCollection max = new NameValueCollection();
                    if (CanvasHeight > 0)
                    {
                        max["maxheight"] = CanvasHeight.ToString();
                    }
                    if (CanvasWidth > 0)
                    {
                        max["maxwidth"] = CanvasWidth.ToString();
                    }
                    url            = ImageResizer.Util.PathUtils.MergeOverwriteQueryString(url, max);
                    image.ImageUrl = url;
                }
                else
                {
                    if (CanvasHeight > 0)
                    {
                        s["boxHeight"] = CanvasHeight.ToString();
                    }
                    if (CanvasWidth > 0)
                    {
                        s["boxWidth"] = CanvasWidth.ToString();
                    }
                }
            }


            //If there has been a crop rectangle specified, use it
            if (W > 0 || H > 0)
            {
                s["setSelect"] =
                    "[" + X.ToString() + "," +
                    Y.ToString() + "," +
                    X2.ToString() + ", " +
                    Y2.ToString() + "]";
            }



            if (!string.IsNullOrEmpty(this.MaxSize))
            {
                s["maxSize"] = "[" + this.MaxSize + "]";
            }

            if (!string.IsNullOrEmpty(this.MinSize))
            {
                s["minSize"] = "[" + this.MinSize + "]";
            }

            if (this.PreviewWidth > 0)
            {
                s["previewWidth"] = this.PreviewWidth.ToString();
            }

            if (this.PreviewHeight > 0)
            {
                s["previewHeight"] = this.PreviewHeight.ToString();
            }

            if (!string.IsNullOrEmpty(this.PreviewImageID))
            {
                Control c = Parent.FindControl(PreviewImageID);
                if (c != null)
                {
                    s["previewDiv"] = "'#" + c.ClientID + "'";
                }
            }

            s["updateFields"] = "'#" + HiddenFieldClientId + "'";



            StringBuilder sb = new StringBuilder();

            sb.AppendLine("<script>$(function(){ ");
            sb.AppendLine("webcropimage('#" + image.ClientID + "', {");
            foreach (string key in s)
            {
                sb.AppendLine(key + ": " + s[key] + ",");
            }
            sb.Append("});});");
            sb.Append(@"</script>");


            if (isInUpdatePanel)
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType()
                                                        , "cropInit" + this.ClientID
                                                        , sb.ToString(), false);
                ScriptManager.RegisterHiddenField(this, HiddenFieldClientId, resolvedUrl);
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType()
                                                            , "cropInit" + this.ClientID
                                                            , sb.ToString(), false);
                Page.ClientScript.RegisterHiddenField(HiddenFieldClientId, resolvedUrl);
            }

            base.CreateChildControls();
        }