Пример #1
0
        /// <summary>
        /// Инициализация фона стиля дефолтными значениями
        /// </summary>
        public StyleBackground()
        {
            //Прописываем дефолтные параметры заднего фона
            //цвет - белый
            color = Color.FromRgb(255, 255, 255);
            //Картинка - дефолтная
            image = new LayeredImage();
            //Режим заполнения - не задан
            size = sizeMode.unset;
            //Инициализируем дефолтные значения
            styleName = "newBackgroundStyle";

            /* вот тут будет получение уникального названия класса */
        }
Пример #2
0
 public Layers(LayeredImage image)
 {
     _image = image;
 }
Пример #3
0
        /// <summary>
        /// Creates a new image of the specified size from the source image
        /// </summary>
        /// <param name="src">Source image path</param>
        /// <param name="dest">Destination image path</param>
        /// <param name="imgCfg">The configuration of the image</param>
        /// <param name="forceUpdate">Update in every case</param>
        /// <param name="jpegQuality">The Quality for the JPEG File 0..100</param>
        public void CreateShadowedImage(string src, string dest, ImageBrowserConfig.ImageCfg imgCfg, bool forceUpdate, byte jpegQuality)
        {
            try
            {
                if (!forceUpdate && File.Exists(cfg.PictureRootDirectory + "/" + dest))
                {
                    return;
                }

                string path = Directory.GetParent(cfg.PictureRootDirectory + "/" + dest).FullName;

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }

                // Values for building Shadow.
                Int32   shadowwidth = imgCfg.ShadowWidth;
                Int32   borderwidth = imgCfg.BorderWidth;
                Int32   margin      = shadowwidth / 2;
                Int32   shadowdir   = 0;
                Double  shadowtrans = imgCfg.ShadowTransparency;
                Color   bkcolor     = Color.FromArgb(imgCfg.BackgroundColor);
                Color   shadowcolor = Color.FromArgb(imgCfg.ShadowColor);
                Color   bordercolor = Color.FromArgb(imgCfg.BorderColor);
                Boolean softshadow  = imgCfg.SoftShadow;

                Image thumb = CreateImageInternal(src, imgCfg.MaxSize);
                if (thumb != null)
                {
                    FastBitmap tmp = new FastBitmap(thumb);

                    FastBitmap bmp = new FastBitmap(tmp.Width + borderwidth * 2, tmp.Height + borderwidth * 2,
                                                    PixelFormat.Format32bppArgb);

                    // add border if necessary
                    if (borderwidth > 0)
                    {
                        using (SolidBrush br = new SolidBrush(bordercolor))
                            using (Graphics g = Graphics.FromImage(bmp._bitmap))
                            {
                                g.FillRectangle(br, 0, 0, borderwidth * 2 + tmp.Width, borderwidth * 2 + tmp.Height);
                            }
                    }

                    tmp.CopyTo(bmp, borderwidth, borderwidth, 0, 0, tmp.Width, tmp.Height);
                    tmp.Dispose();

                    // create image

                    Int32        width  = bmp.Width + shadowwidth + margin * 2;
                    Int32        height = bmp.Height + shadowwidth + margin * 2;
                    LayeredImage image  = new LayeredImage(width, height);

                    Int32 shadowx = 0, shadowy = 0, imgx = 0, imgy = 0;

                    if (softshadow)
                    {
                        switch (shadowdir)
                        {
                        case 0:
                            shadowx = margin - shadowwidth / 2;
                            shadowy = margin - shadowwidth / 2;
                            imgx    = margin;
                            imgy    = margin;
                            break;

                        case 1:
                            shadowx = margin + shadowwidth - 3 * (shadowwidth / 2);
                            shadowy = margin - shadowwidth / 2;
                            imgx    = margin + shadowwidth;
                            imgy    = margin;
                            break;

                        case 2:
                            shadowx = margin + shadowwidth - 3 * (shadowwidth / 2);
                            shadowy = margin + shadowwidth - 3 * (shadowwidth / 2);
                            imgx    = margin + shadowwidth;
                            imgy    = margin + shadowwidth;
                            break;

                        case 3:
                            shadowx = margin - shadowwidth / 2;
                            shadowy = margin + shadowwidth - 3 * (shadowwidth / 2);
                            imgx    = margin;
                            imgy    = margin + shadowwidth;
                            break;
                        }
                    }
                    else
                    {
                        switch (shadowdir)
                        {
                        case 0:
                            shadowx = margin;
                            shadowy = margin;
                            imgx    = margin;
                            imgy    = margin;
                            break;

                        case 1:
                            shadowx = margin - shadowwidth;
                            shadowy = margin;
                            imgx    = margin + shadowwidth;
                            imgy    = margin;
                            break;

                        case 2:
                            shadowx = margin - shadowwidth;
                            shadowy = margin - shadowwidth;
                            imgx    = margin + shadowwidth;
                            imgy    = margin + shadowwidth;
                            break;

                        case 3:
                            shadowx = margin;
                            shadowy = margin - shadowwidth;
                            imgx    = margin;
                            imgy    = margin + shadowwidth;
                            break;
                        }
                    }

                    // background
                    Layer bg = image.Layers.Add();
                    bg.Clear(bkcolor);

                    // shadow -- layer must be larger because of blur
                    Layer      shadow = image.Layers.Add(width + shadowwidth, height + shadowwidth);
                    SolidBrush brush  = new SolidBrush(shadowcolor);
                    shadow.FillRectangle(shadowwidth, shadowwidth, bmp.Width, bmp.Height, brush);
                    if (softshadow)
                    {
                        shadow.Blur(shadowwidth, shadowwidth);
                    }
                    brush.Dispose();
                    shadow.OffsetX = shadowx;
                    shadow.OffsetY = shadowy;
                    shadow.Opacity = 1.0 - shadowtrans;

                    // image
                    Layer img = image.Layers.Add(bmp);
                    img.OffsetX = imgx;
                    img.OffsetY = imgy;

                    // result
                    FastBitmap result = image.Flatten();

                    EncoderParameters encParams = new EncoderParameters(1);
                    encParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)jpegQuality);
                    result.Save(cfg.PictureRootDirectory + "/" + dest, GetEncoder(ImageFormat.Jpeg), encParams);
                    result.Dispose();
                }
            }
            catch (Exception) {}
        }
Пример #4
0
        /// <summary>
        /// Creates the files to build a shadow arround a picture.
        /// </summary>
        /// <param name="imgCfg">the shadow configuration of the picture</param>
        /// <param name="path">the directory where the files should be located</param>
        public void CreateShadowParts(ImageBrowserConfig.ImageCfg imgCfg, String path)
        {
            // Values for building Shadow.
            Int32 shadowwidth = imgCfg.ShadowWidth;
            Int32 margin      = shadowwidth / 2;

            // background
            LayeredImage image = new LayeredImage(shadowwidth * 2 + margin + 1, shadowwidth * 2 + margin + 1);
            Layer        bg    = image.Layers.Add();

            bg.Clear(Color.FromArgb(imgCfg.BackgroundColor));

            // shadow -- layer must be larger because of blur
            Layer      shadow = image.Layers.Add(shadowwidth * 2 + margin, shadowwidth * 2 + margin);
            SolidBrush brush  = new SolidBrush(Color.FromArgb(imgCfg.ShadowColor));

            shadow.FillRectangle(margin, margin, shadowwidth + margin + 1, shadowwidth + margin + 1, brush);
            if (imgCfg.SoftShadow)
            {
                shadow.Blur(margin * 2, margin * 2);
            }
            brush.Dispose();
            shadow.Opacity = 1.0 - imgCfg.ShadowTransparency;

            // Result with all the parts.
            FastBitmap totalResult = image.Flatten();

            // Create Directory if necessary.
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            // Save Shadow into splittet files.
            // Top-right.
            FastBitmap imgTR = new FastBitmap(shadowwidth, shadowwidth, PixelFormat.Format32bppArgb);

            totalResult.CopyTo(imgTR, 0, 0, margin + shadowwidth + 1, 0, shadowwidth, shadowwidth);
            imgTR.Save(path + "/tr.jpg", ImageFormat.Jpeg);

            // Right.
            FastBitmap imgR = new FastBitmap(shadowwidth, 1, PixelFormat.Format32bppArgb);

            totalResult.CopyTo(imgR, 0, 0, margin + shadowwidth + 1, margin + shadowwidth, shadowwidth, 1);
            imgR.Save(path + "/r.jpg", ImageFormat.Jpeg);

            // Bottom-right.
            FastBitmap imgBR = new FastBitmap(shadowwidth, shadowwidth, PixelFormat.Format32bppArgb);

            totalResult.CopyTo(imgBR, 0, 0, margin + shadowwidth + 1, margin + shadowwidth + 1, shadowwidth, shadowwidth);
            imgBR.Save(path + "/br.jpg", ImageFormat.Jpeg);

            // Bottom.
            FastBitmap imgB = new FastBitmap(1, shadowwidth, PixelFormat.Format32bppArgb);

            totalResult.CopyTo(imgB, 0, 0, margin + shadowwidth, margin + shadowwidth + 1, 1, shadowwidth);
            imgB.Save(path + "/b.jpg", ImageFormat.Jpeg);


            // Bottom-left.
            FastBitmap imgBL = new FastBitmap(shadowwidth, shadowwidth, PixelFormat.Format32bppArgb);

            totalResult.CopyTo(imgBL, 0, 0, 0, margin + shadowwidth + 1, shadowwidth, shadowwidth);
            imgBL.Save(path + "/bl.jpg", ImageFormat.Jpeg);
        }
Пример #5
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            font = Content.Load<SpriteFont>("Arial");
            gridCursor = Content.Load<Texture2D>("cursor");
            highlightSquare = Content.Load<Texture2D>("highlightSquare");
            gameOverTexture = Content.Load<Texture2D>("gameover");
            gameWonTexture = Content.Load<Texture2D>("gamewon");
            upgradeTexture = Content.Load<Texture2D>("upgrade");
            levelDoneTexture = Content.Load<Texture2D>("level_pip_done");
            levelOpenTexture = Content.Load<Texture2D>("level_pip_open");
            levelHoverTexture = Content.Load<Texture2D>("level_pip_hover");
            levelStarDoneTexture = Content.Load<Texture2D>("level_star_done");
            levelStarOpenTexture = Content.Load<Texture2D>("level_star_open");
            levelStarHoverTexture = Content.Load<Texture2D>("level_star_hover");
            selectionCircleTexture = Content.Load<Texture2D>("selection_circle");

            StreamReader configReader = new StreamReader(File.OpenRead("Content/config.json"));
            JSONTable config = JSONTable.parse(configReader.ReadToEnd());

            tooltipBG = new LayeredImage(config.getJSON("tooltipBG"), Content);
            activeCardBG = new LayeredImage(config.getJSON("activeCardBG"), Content);

            ResourceType.load(config.getJSON("resources"), Content);
            MinionType.load(config.getJSON("minions"), Content);
            LevelType.load(config.getJSON("levelTypes"), Content);

            spellBooks = new Dictionary<string, List<Card>>();
            JSONTable spellsTemplate = config.getJSON("spells");
            foreach (string key in spellsTemplate.Keys)
            {
                spellBooks.Add(key, Card.load(spellsTemplate.getArray(key), Content));
            }

            wizardCatalog = new CardCatalog(new Rectangle(0, 5, 128, 600), spellBooks["main"], spellUpgrades);
            dynamicCatalog = new CardCatalog(new Rectangle(800 - 128, 5, 128, 600), spellBooks["rhs"], spellUpgrades);
            catalogs = new CardCatalog[]{ wizardCatalog, dynamicCatalog };

            levelScreen = new LevelScreen(config.getArray("chapters"));

            basicButtonStyle = new UIButtonStyleSet
            (
                new UIButtonStyle(font, Color.Black, new LayeredImage(config.getJSON("button3d"), Content), Color.White),
                new UIButtonStyle(font, Color.Yellow, new LayeredImage(config.getJSON("button3d_hover"), Content), Color.White),
                new UIButtonStyle(font, Color.Yellow, new LayeredImage(config.getJSON("button3d_pressed"), Content), Color.White)
            );
            gameScreenButtons = new List<UIButton>()
            {
                new UIButton("Back To Map", new Rectangle(GraphicsDevice.Viewport.Width - 240, 10, 100, 35), basicButtonStyle, OnPress_BackToMap),
                new UIButton("Cheat: Win", new Rectangle(GraphicsDevice.Viewport.Width - 240, GraphicsDevice.Viewport.Height - 100, 100, 35), basicButtonStyle, OnPress_CheatWin)
            };
            winScreenButtons = new List<UIButton>()
            {
                new UIButton("Next Level", new Rectangle(GraphicsDevice.Viewport.Width/2 - 120, GraphicsDevice.Viewport.Height/2 + 100, 100, 35), basicButtonStyle, OnPress_NextLevel),
                new UIButton("View Map", new Rectangle(GraphicsDevice.Viewport.Width/2 + 20, GraphicsDevice.Viewport.Height/2 + 100, 100, 35), basicButtonStyle, OnPress_BackToMap)
            };
            mapScreenButtons = new List<UIButton>()
            {
                new UIButton("Cheat: All spells", new Rectangle(GraphicsDevice.Viewport.Width - 160, GraphicsDevice.Viewport.Height - 100, 150, 35), basicButtonStyle, OnPress_CheatAllSpells),
                new UIButton("Cheat: All basic", new Rectangle(GraphicsDevice.Viewport.Width - 160, GraphicsDevice.Viewport.Height - 150, 150, 35), basicButtonStyle, OnPress_CheatAllBasic),
                new UIButton("Cheat: Restart", new Rectangle(GraphicsDevice.Viewport.Width - 160, GraphicsDevice.Viewport.Height - 200, 150, 35), basicButtonStyle, OnPress_CheatRestart),
            };
        }
Пример #6
0
    public Bitmap TextRenderHQ(int _size, string _font, string _color, int _offset, string _str, bool _shadow)
    {
        privateFonts = new PrivateFontCollection();
        privateFonts.AddFontFile(_font);
        font = new Font(privateFonts.Families[0], _size);

        String s = _str;

        String[] rgbs   = _color.Split(new Char[] { ' ', ',', ';', ':' });
        Color[]  colors = new Color[rgbs.Length];
        for (Int32 i = 0; i < rgbs.Length; i++)
        {
            colors[i] = HexColorToColor(rgbs[i]);
        }

        Bitmap     bmp     = new Bitmap(10, 10, PixelFormat.Format24bppRgb);
        Graphics   g       = Graphics.FromImage(bmp);
        IntPtr     hdc     = g.GetHdc();
        IntPtr     oldfont = Gdi.SelectObject(hdc, font.ToHfont());
        TEXTMETRIC tm      = new TEXTMETRIC();

        Gdi.GetTextMetrics(hdc, ref tm);
        Int32 totalwidth = 0;

        Int32[] width  = new Int32[1];
        Int32[] widths = new Int32[s.Length];

        Graphics gs = Graphics.FromImage(new Bitmap(1, 1));

        for (Int32 i = 0; i < s.Length; i++)
        {
            Gdi.GetCharWidth(hdc, s[i], s[i], width);

            SizeF sizeW = gs.MeasureString(s[i].ToString(), new Font(_font, _size));
            if (s[i] >= 0x4e00 && s[i] <= 0x9fbb)
            {
                widths[i] = (int)sizeW.Width - _offset;
            }
            else
            {
                widths[i] = width[0];
            }
        }

        SizeF sizeF = gs.MeasureString(s, font);

        totalwidth = (int)sizeF.Width;

        Gdi.SelectObject(hdc, oldfont);
        g.ReleaseHdc(hdc);
        g.Dispose();
        bmp.Dispose();
        LayeredImage image = new LayeredImage(totalwidth + 4, tm.tmHeight + 4 + 4);
        Layer        bg    = image.Layers.Add();

        bg.Clear(Color.Black);
        bg.DrawText(0, 0, s, font, new SolidBrush(Color.White));
        Layer copybg = image.Layers.Copy(bg);

        copybg.Blur(4, 4);
        Layer white = image.Layers.Add();

        white.Clear(Color.White);

        if (_shadow)
        {
            Layer shadow = image.Layers.Copy(copybg);
            shadow.Invert();
            shadow.Opacity  = 0.5;
            shadow.OffsetX += 4;
            shadow.OffsetY += 4;
        }

        Int32 offsetx    = 0;
        Int32 colorindex = 0;
        Layer final      = image.Layers.Add();

        for (Int32 i = 0; i < s.Length; i++)
        {
            Color c = colors[colorindex];
            colorindex++;
            if (colorindex >= colors.Length)
            {
                colorindex = 0;
            }
            SolidBrush brush = new SolidBrush(c);
            final.FillRectangle(offsetx, 0, widths[i], tm.tmHeight, brush);
            offsetx += widths[i];
        }
        final.BumpMap(copybg, 135, 45, 3, false);
        final.Mask = (FastBitmap)bg.Bitmap.Clone();
        FastBitmap result = image.Flatten();

        result._bitmap.MakeTransparent();
        return(result._bitmap);
    }
Пример #7
0
    static void Main(String[] args)
    {
        if (args.Length == 0)
        {
            PrintUsage();
            return;
        }

        Int32   shadowwidth = 8;
        Int32   borderwidth = 0;
        Int32   margin      = shadowwidth;
        Int32   shadowdir   = 0;
        Double  shadowtrans = 0.0;
        Color   bkcolor     = Color.FromArgb(255, 255, 255);
        Color   shadowcolor = Color.FromArgb(0, 0, 0);
        Color   bordercolor = Color.FromArgb(0, 0, 0);
        Boolean softshadow  = true;
        String  inputfile   = "";
        String  outputfile  = "";

        for (Int32 i = 0; i < args.Length; i++)
        {
            if (args[i].Length == 0)
            {
                PrintUsage();
                return;
            }
            if (args[i][0] == '-')
            {
                Boolean b;
                switch (args[i][1])
                {
                case 's':
                    b = GetArgParam(args[i], out shadowwidth);
                    if (!b || (shadowwidth < 0 || shadowwidth > 99))
                    {
                        Console.WriteLine("Error: Incorrect command line option: -s");
                        return;
                    }
                    break;

                case 'b':
                    b = GetArgParam(args[i], out borderwidth);
                    if (!b || (borderwidth < 0 || borderwidth > 99))
                    {
                        Console.WriteLine("Error: Incorrect command line option: -b");
                        return;
                    }
                    break;

                case 'm':
                    b = GetArgParam(args[i], out margin);
                    if (!b || (margin < 0 || margin > 99))
                    {
                        Console.WriteLine("Error: Incorrect command line option: -b");
                        return;
                    }
                    break;

                case 'r':
                    b = GetArgParam(args[i], out shadowdir);
                    if (!b || (shadowdir < 0 || shadowdir > 3))
                    {
                        Console.WriteLine("Error: Incorrect command line option: -r");
                        return;
                    }
                    break;

                case 't':
                    b = GetArgParam(args[i], out shadowtrans);
                    if (!b || (shadowtrans < 0.0 || shadowtrans > 1.0))
                    {
                        Console.WriteLine("Error: Incorrect command line option: -t");
                        return;
                    }
                    break;

                case 'a':
                    b = GetArgParam(args[i], out bkcolor);
                    if (!b)
                    {
                        Console.WriteLine("Error: Incorrect command line option: -a");
                        return;
                    }
                    break;

                case 'c':
                    b = GetArgParam(args[i], out shadowcolor);
                    if (!b)
                    {
                        Console.WriteLine("Error: Incorrect command line option: -c");
                        return;
                    }
                    break;

                case 'd':
                    b = GetArgParam(args[i], out bordercolor);
                    if (!b)
                    {
                        Console.WriteLine("Error: Incorrect command line option: -d");
                        return;
                    }
                    break;

                case 'n':
                    softshadow = false;
                    break;

                default:
                    Console.WriteLine("Fatal: Illegal option: {0}", args[i]);
                    return;
                }
            }
            else
            {
                // must be a file name
                if (inputfile == "")
                {
                    inputfile = args[i];
                }
                else if (outputfile == "")
                {
                    outputfile = args[i];
                }
                // ignore other file names
            }
        }

        if (inputfile == "")
        {
            Console.WriteLine("Error: No file names given");
            return;
        }

        FastBitmap tmp, bmp;

        // try-catch doesn't work like it should
        if (File.Exists(inputfile))
        {
            tmp = new FastBitmap(inputfile);
        }
        else
        {
            Console.WriteLine("Error: Could not find file '{0}'", inputfile);
            return;
        }

        bmp = new FastBitmap(tmp.Width + borderwidth * 2, tmp.Height + borderwidth * 2,
                             PixelFormat.Format32bppArgb);

        // add border if necessary
        if (borderwidth > 0)
        {
            SolidBrush br = new SolidBrush(bordercolor);
            Graphics   g  = Graphics.FromImage(bmp._bitmap);
            g.FillRectangle(br, 0, 0, borderwidth * 2 + tmp.Width, borderwidth * 2 + tmp.Height);
            g.Dispose();
            br.Dispose();
        }

        tmp.CopyTo(bmp, borderwidth, borderwidth, 0, 0, tmp.Width, tmp.Height);
        tmp.Dispose();

        // create image

        Int32        width  = bmp.Width + shadowwidth + margin * 2;
        Int32        height = bmp.Height + shadowwidth + margin * 2;
        LayeredImage image  = new LayeredImage(width, height);

        Int32 shadowx = 0, shadowy = 0, imgx = 0, imgy = 0;

        if (softshadow)
        {
            switch (shadowdir)
            {
            case 0:
                shadowx = margin - shadowwidth / 2;
                shadowy = margin - shadowwidth / 2;
                imgx    = margin;
                imgy    = margin;
                break;

            case 1:
                shadowx = margin + shadowwidth - 3 * (shadowwidth / 2);
                shadowy = margin - shadowwidth / 2;
                imgx    = margin + shadowwidth;
                imgy    = margin;
                break;

            case 2:
                shadowx = margin + shadowwidth - 3 * (shadowwidth / 2);
                shadowy = margin + shadowwidth - 3 * (shadowwidth / 2);
                imgx    = margin + shadowwidth;
                imgy    = margin + shadowwidth;
                break;

            case 3:
                shadowx = margin - shadowwidth / 2;
                shadowy = margin + shadowwidth - 3 * (shadowwidth / 2);
                imgx    = margin;
                imgy    = margin + shadowwidth;
                break;
            }
        }
        else
        {
            switch (shadowdir)
            {
            case 0:
                shadowx = margin;
                shadowy = margin;
                imgx    = margin;
                imgy    = margin;
                break;

            case 1:
                shadowx = margin - shadowwidth;
                shadowy = margin;
                imgx    = margin + shadowwidth;
                imgy    = margin;
                break;

            case 2:
                shadowx = margin - shadowwidth;
                shadowy = margin - shadowwidth;
                imgx    = margin + shadowwidth;
                imgy    = margin + shadowwidth;
                break;

            case 3:
                shadowx = margin;
                shadowy = margin - shadowwidth;
                imgx    = margin;
                imgy    = margin + shadowwidth;
                break;
            }
        }

        // background
        Layer bg = image.Layers.Add();

        bg.Clear(bkcolor);

        // shadow -- layer must be larger because of blur
        Layer      shadow = image.Layers.Add(width + shadowwidth, height + shadowwidth);
        SolidBrush brush  = new SolidBrush(shadowcolor);

        shadow.FillRectangle(shadowwidth, shadowwidth, bmp.Width, bmp.Height, brush);
        if (softshadow)
        {
            shadow.Blur(shadowwidth, shadowwidth);
        }
        brush.Dispose();
        shadow.OffsetX = shadowx;
        shadow.OffsetY = shadowy;
        shadow.Opacity = 1.0 - shadowtrans;

        // image
        Layer img = image.Layers.Add(bmp);

        img.OffsetX = imgx;
        img.OffsetY = imgy;

        // result
        FastBitmap result = image.Flatten();

        // save
        String filename = outputfile != "" ? outputfile : inputfile;
        String ext      = Path.GetExtension(filename);

        if (ext == "")
        {
            ext = ".bmp";
        }
        ext = ext.ToLower();
        ImageFormat imgf = ImageFormat.Bmp;

        switch (ext)
        {
        case ".bmp":
            ext  = ".bmp";
            imgf = ImageFormat.Bmp;
            break;

        case ".jpg":
            ext  = ".jpg";
            imgf = ImageFormat.Jpeg;
            break;

        case ".jpeg":
            ext  = ".jpeg";
            imgf = ImageFormat.Jpeg;
            break;

        case ".png":
            ext  = ".png";
            imgf = ImageFormat.Png;
            break;

        case ".gif":
            ext  = ".gif";
            imgf = ImageFormat.Gif;
            break;

        default:
            ext  = ".bmp";
            imgf = ImageFormat.Bmp;
            break;
        }
        filename = Path.GetFileNameWithoutExtension(filename);
        result.Save(filename + ext, imgf);
    }
Пример #8
0
    static void Main(String[] args)
    {
        if (args.Length == 0) {
            PrintUsage();
            return;
        }

        Int32 shadowwidth = 8;
        Int32 borderwidth = 0;
        Int32 margin = shadowwidth;
        Int32 shadowdir = 0;
        Double shadowtrans = 0.0;
        Color bkcolor = Color.FromArgb(255,255,255);
        Color shadowcolor = Color.FromArgb(0,0,0);
        Color bordercolor = Color.FromArgb(0,0,0);
        Boolean softshadow = true;
        String inputfile = "";
        String outputfile = "";

        for (Int32 i = 0; i < args.Length; i++) {
            if (args[i].Length == 0) {
                PrintUsage();
                return;
            }
            if (args[i][0] == '-') {
                Boolean b;
                switch (args[i][1]) {
                    case 's':
                        b = GetArgParam(args[i], out shadowwidth);
                        if (!b || (shadowwidth < 0 || shadowwidth > 99)) {
                            Console.WriteLine("Error: Incorrect command line option: -s");
                            return;
                        }
                        break;
                    case 'b':
                        b = GetArgParam(args[i], out borderwidth);
                        if (!b || (borderwidth < 0 || borderwidth > 99)) {
                            Console.WriteLine("Error: Incorrect command line option: -b");
                            return;
                        }
                        break;
                    case 'm':
                        b = GetArgParam(args[i], out margin);
                        if (!b || (margin < 0 || margin > 99)) {
                            Console.WriteLine("Error: Incorrect command line option: -b");
                            return;
                        }
                        break;
                    case 'r':
                        b = GetArgParam(args[i], out shadowdir);
                        if (!b || (shadowdir < 0 || shadowdir > 3)) {
                            Console.WriteLine("Error: Incorrect command line option: -r");
                            return;
                        }
                        break;
                    case 't':
                        b = GetArgParam(args[i], out shadowtrans);
                        if (!b || (shadowtrans < 0.0 || shadowtrans > 1.0)) {
                            Console.WriteLine("Error: Incorrect command line option: -t");
                            return;
                        }
                        break;
                    case 'a':
                        b = GetArgParam(args[i], out bkcolor);
                        if (!b) {
                            Console.WriteLine("Error: Incorrect command line option: -a");
                            return;
                        }
                        break;
                    case 'c':
                        b = GetArgParam(args[i], out shadowcolor);
                        if (!b) {
                            Console.WriteLine("Error: Incorrect command line option: -c");
                            return;
                        }
                        break;
                    case 'd':
                        b = GetArgParam(args[i], out bordercolor);
                        if (!b) {
                            Console.WriteLine("Error: Incorrect command line option: -d");
                            return;
                        }
                        break;
                    case 'n':
                        softshadow = false;
                        break;
                    default:
                        Console.WriteLine("Fatal: Illegal option: {0}", args[i]);
                        return;
                }
            } else {
                // must be a file name
                if (inputfile == "")
                    inputfile = args[i];
                else if (outputfile == "")
                    outputfile = args[i];
                // ignore other file names
            }
        }

        if (inputfile == "") {
            Console.WriteLine("Error: No file names given");
            return;
        }

        FastBitmap tmp, bmp;

        // try-catch doesn't work like it should
        if (File.Exists(inputfile)) {
            tmp = new FastBitmap(inputfile);
        } else {
            Console.WriteLine("Error: Could not find file '{0}'", inputfile);
            return;
        }

        bmp = new FastBitmap(tmp.Width + borderwidth * 2, tmp.Height + borderwidth * 2,
            PixelFormat.Format32bppArgb);

        // add border if necessary
        if (borderwidth > 0) {
            SolidBrush br = new SolidBrush(bordercolor);
            Graphics g = Graphics.FromImage(bmp._bitmap);
            g.FillRectangle(br, 0, 0, borderwidth * 2 + tmp.Width, borderwidth * 2 + tmp.Height);
            g.Dispose();
            br.Dispose();
        }

        tmp.CopyTo(bmp, borderwidth, borderwidth, 0, 0, tmp.Width, tmp.Height);
        tmp.Dispose();

        // create image

        Int32 width = bmp.Width + shadowwidth + margin * 2;
        Int32 height = bmp.Height + shadowwidth + margin * 2;
        LayeredImage image = new LayeredImage(width, height);

        Int32 shadowx = 0, shadowy = 0, imgx = 0, imgy = 0;

        if (softshadow) {
            switch (shadowdir) {
                case 0:
                    shadowx = margin - shadowwidth / 2;
                    shadowy = margin - shadowwidth / 2;
                    imgx = margin;
                    imgy = margin;
                    break;
                case 1:
                    shadowx = margin + shadowwidth - 3 * (shadowwidth / 2);
                    shadowy = margin - shadowwidth / 2;
                    imgx = margin + shadowwidth;
                    imgy = margin;
                    break;
                case 2:
                    shadowx = margin + shadowwidth - 3 * (shadowwidth / 2);
                    shadowy = margin + shadowwidth - 3 * (shadowwidth / 2);
                    imgx = margin + shadowwidth;
                    imgy = margin + shadowwidth;
                    break;
                case 3:
                    shadowx = margin - shadowwidth / 2;
                    shadowy = margin + shadowwidth - 3 * (shadowwidth / 2);
                    imgx = margin;
                    imgy = margin + shadowwidth;
                    break;
            }
        } else {
            switch (shadowdir) {
                case 0:
                    shadowx = margin;
                    shadowy = margin;
                    imgx = margin;
                    imgy = margin;
                    break;
                case 1:
                    shadowx = margin - shadowwidth;
                    shadowy = margin;
                    imgx = margin + shadowwidth;
                    imgy = margin;
                    break;
                case 2:
                    shadowx = margin - shadowwidth;
                    shadowy = margin - shadowwidth;
                    imgx = margin + shadowwidth;
                    imgy = margin + shadowwidth;
                    break;
                case 3:
                    shadowx = margin;
                    shadowy = margin - shadowwidth;
                    imgx = margin;
                    imgy = margin + shadowwidth;
                    break;
            }
        }

        // background
        Layer bg = image.Layers.Add();
        bg.Clear(bkcolor);

        // shadow -- layer must be larger because of blur
        Layer shadow = image.Layers.Add(width + shadowwidth, height + shadowwidth);
        SolidBrush brush = new SolidBrush(shadowcolor);
        shadow.FillRectangle(shadowwidth, shadowwidth, bmp.Width, bmp.Height, brush);
        if (softshadow)
            shadow.Blur(shadowwidth, shadowwidth);
        brush.Dispose();
        shadow.OffsetX = shadowx;
        shadow.OffsetY = shadowy;
        shadow.Opacity = 1.0 - shadowtrans;

        // image
        Layer img = image.Layers.Add(bmp);
        img.OffsetX = imgx;
        img.OffsetY = imgy;

        // result
        FastBitmap result = image.Flatten();

        // save
        String filename = outputfile != "" ? outputfile : inputfile;
        String ext = Path.GetExtension(filename);
        if (ext == "")
            ext = ".bmp";
        ext = ext.ToLower();
        ImageFormat imgf = ImageFormat.Bmp;
        switch (ext) {
            case ".bmp":
                ext = ".bmp";
                imgf = ImageFormat.Bmp;
                break;
            case ".jpg":
                ext = ".jpg";
                imgf = ImageFormat.Jpeg;
                break;
            case ".jpeg":
                ext = ".jpeg";
                imgf = ImageFormat.Jpeg;
                break;
            case ".png":
                ext = ".png";
                imgf = ImageFormat.Png;
                break;
            case ".gif":
                ext = ".gif";
                imgf = ImageFormat.Gif;
                break;
            default:
                ext = ".bmp";
                imgf = ImageFormat.Bmp;
                break;
        }
        filename = Path.GetFileNameWithoutExtension(filename);
        result.Save(filename + ext, imgf);
    }
Пример #9
0
 public Layers(LayeredImage image)
 {
     _image = image;
 }
Пример #10
0
 public UIButtonStyle(SpriteFont font, Color textColor, LayeredImage image, Color fillColor)
 {
     this.font = font;
     this.textColor = textColor;
     this.image = image;
 }
Пример #11
0
 public UIButtonStyle(SpriteFont font, Color textColor, LayeredImage image, Color fillColor, Vector2 textOffset)
 {
     this.font = font;
     this.textColor = textColor;
     this.image = image;
     this.textOffset = textOffset;
 }