Example #1
0
        //获取尺寸
        private CssSize getPtoSizeInCss(Size sizeImg)
        {
            CssSize sizePto = new CssSize();

            switch (cboxUnit.Text)
            {
            case "rem":
                sizePto.Width  = ((double)sizeImg.Width / Convert.ToDouble(txtRemMultiple.Text)).ToString();
                sizePto.Height = ((double)sizeImg.Height / Convert.ToDouble(txtRemMultiple.Text)).ToString();
                break;

            case "px":
                sizePto.Width  = sizeImg.Width.ToString();
                sizePto.Height = sizeImg.Height.ToString();
                break;

            case "em":
                sizePto.Width  = sizeImg.Width.ToString();
                sizePto.Height = sizeImg.Height.ToString();
                break;

            case "%":
                sizePto.Width  = sizeImg.Width.ToString();
                sizePto.Height = sizeImg.Height.ToString();
                break;

            default:
                sizePto.Width  = sizeImg.Width.ToString();
                sizePto.Height = sizeImg.Height.ToString();
                break;
            }
            sizePto.Width  += cboxUnit.Text;
            sizePto.Height += cboxUnit.Text;
            return(sizePto);
        }
Example #2
0
        //生成组合css
        private string getMergeCss(Array urls)
        {
            System.Text.StringBuilder strCss = new System.Text.StringBuilder();
            int intMaxWidth  = 0,
                intMaxHeight = 0;
            string strTab    = "    ";

            string[] strNames = new string[urls.Length];
            Image    _tmpImg;
            CssSize  _tmpCSize = new CssSize();

            for (int i = 0; i < urls.Length; i++)
            {
                _tmpImg = Image.FromFile(urls.GetValue(i).ToString());
                if (_tmpImg.Width > intMaxWidth)
                {
                    intMaxWidth = _tmpImg.Width;
                }
                if (_tmpImg.Height > intMaxHeight)
                {
                    intMaxHeight = _tmpImg.Height;
                }
                _tmpImg.Dispose();
                strNames[i] = System.IO.Path.GetFileNameWithoutExtension(urls.GetValue(i).ToString());
            }
            _tmpCSize = getPtoSizeInCss(new Size(intMaxWidth, intMaxHeight));
            strCss.AppendLine("/* merge>" + gCtrl.MergeClassName + " */");
            strCss.AppendLine("." + gCtrl.MergeClassName + " {");
            strCss.AppendLine(strTab + "width: " + _tmpCSize.Width + ";");
            strCss.AppendLine(strTab + "height: " + _tmpCSize.Height + ";");
            strCss.AppendLine(strTab + "position: relative;");
            strCss.AppendLine("}");
            for (int i = 0; i < strNames.Length; i++)
            {
                strCss.Append("." + gCtrl.MergeClassName + " ." + strNames[i]);
                if (i < strNames.Length - 1)
                {
                    strCss.AppendLine(",");
                }
                else
                {
                    strCss.AppendLine("{");
                }
            }
            strCss.AppendLine(strTab + "position: absolute;");
            strCss.AppendLine("}");
            strCss.AppendLine();
            for (int i = 0; i < strNames.Length; i++)
            {
                strCss.AppendLine("." + gCtrl.MergeClassName + " ." + strNames[i] + "{");
                strCss.AppendLine(strTab + "left: 0;");
                strCss.AppendLine(strTab + "top: 0;");
                strCss.AppendLine("}");
                strCss.AppendLine();
            }
            return(strCss.ToString());
        }
Example #3
0
        //生成cimg css
        private string getCss(string url)
        {
            Image   imgPto = Image.FromFile(url);
            CssSize csPto  = getPtoSizeInCss(imgPto.Size);

            System.Text.StringBuilder strCss = new System.Text.StringBuilder();
            string strTab = "    ";

            imgPto.Dispose();
            strCss.AppendLine("/* " + txtGlobalClass.Text + ">" + System.IO.Path.GetFileNameWithoutExtension(url) + " */");
            strCss.AppendLine("." + txtGlobalClass.Text + "." + System.IO.Path.GetFileNameWithoutExtension(url) + " {");
            strCss.AppendLine(strTab + "background-image: url(\"../images/" + System.IO.Path.GetFileName(url) + "\");");
            strCss.AppendLine(strTab + "width: " + csPto.Width + ";");
            strCss.AppendLine(strTab + "height: " + csPto.Height + ";");
            strCss.AppendLine("}");
            return(strCss.ToString());
        }