当前位置: 首页>>代码示例>>C#>>正文


C# MakeBitmapParameter类代码示例

本文整理汇总了C#中MakeBitmapParameter的典型用法代码示例。如果您正苦于以下问题:C# MakeBitmapParameter类的具体用法?C# MakeBitmapParameter怎么用?C# MakeBitmapParameter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MakeBitmapParameter类属于命名空间,在下文中一共展示了MakeBitmapParameter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenerateImageFromTextWithStyleInner

        /// <summary>
        /// The generate image from text with style inner.
        /// </summary>
        /// <param name="parameter">
        /// The parameter.
        /// </param>
        /// <returns>
        /// The <see cref="Bitmap"/>.
        /// </returns>
        private static Bitmap GenerateImageFromTextWithStyleInner(MakeBitmapParameter parameter)
        {
            string text = parameter.P.Text;

            text = RemoveSubStationAlphaFormatting(text);

            text = text.Replace("<I>", "<i>");
            text = text.Replace("</I>", "</i>");
            text = HtmlUtil.FixInvalidItalicTags(text);

            text = text.Replace("<B>", "<b>");
            text = text.Replace("</B>", "</b>");

            // no support for underline
            text = HtmlUtil.RemoveOpenCloseTags(text, HtmlUtil.TagUnderline);

            Font font = null;
            Bitmap bmp = null;
            try
            {
                font = SetFont(parameter, parameter.SubtitleFontSize);
                var lineHeight = parameter.LineHeight; // (textSize.Height * 0.64f);

                SizeF textSize;
                using (var bmpTemp = new Bitmap(1, 1))
                using (var g = Graphics.FromImage(bmpTemp))
                {
                    textSize = g.MeasureString(HtmlUtil.RemoveHtmlTags(text), font);
                }

                int sizeX = (int)(textSize.Width * 1.8) + 150;
                int sizeY = (int)(textSize.Height * 0.9) + 50;
                if (sizeX < 1)
                {
                    sizeX = 1;
                }

                if (sizeY < 1)
                {
                    sizeY = 1;
                }

                if (parameter.BackgroundColor != Color.Transparent)
                {
                    var nbmpTemp = new NikseBitmap(sizeX, sizeY);
                    nbmpTemp.Fill(parameter.BackgroundColor);
                    bmp = nbmpTemp.GetBitmap();
                }
                else
                {
                    bmp = new Bitmap(sizeX, sizeY);
                }

                // align lines with gjpqy, a bit lower
                var lines = text.SplitToLines();
                int baseLinePadding = 13;
                if (parameter.SubtitleFontSize < 30)
                {
                    baseLinePadding = 12;
                }

                if (parameter.SubtitleFontSize < 25)
                {
                    baseLinePadding = 9;
                }

                if (lines.Length > 0)
                {
                    var lastLine = lines[lines.Length - 1];
                    if (lastLine.Contains(new[] { 'g', 'j', 'p', 'q', 'y', ',', 'ý', 'ę', 'ç', 'Ç' }))
                    {
                        var textNoBelow = lastLine.Replace('g', 'a').Replace('j', 'a').Replace('p', 'a').Replace('q', 'a').Replace('y', 'a').Replace(',', 'a').Replace('ý', 'a').Replace('ę', 'a').Replace('ç', 'a').Replace('Ç', 'a');
                        baseLinePadding -= (int)Math.Round(TextDraw.MeasureTextHeight(font, lastLine, parameter.SubtitleFontBold) - TextDraw.MeasureTextHeight(font, textNoBelow, parameter.SubtitleFontBold));
                    }
                    else
                    {
                        baseLinePadding += 1;
                    }

                    if (baseLinePadding < 0)
                    {
                        baseLinePadding = 0;
                    }
                }

                // TODO: Better baseline - test http://bobpowell.net/formattingtext.aspx
                // float baselineOffset=font.SizeInPoints/font.FontFamily.GetEmHeight(font.Style)*font.FontFamily.GetCellAscent(font.Style);
                // float baselineOffsetPixels = g.DpiY/72f*baselineOffset;
                // baseLinePadding = (int)Math.Round(baselineOffsetPixels);
                var lefts = new List<float>();
                if (text.Contains("<font", StringComparison.OrdinalIgnoreCase) || text.Contains("<i>", StringComparison.OrdinalIgnoreCase))
//.........这里部分代码省略.........
开发者ID:KatyaMarincheva,项目名称:SubtitleEditOriginal,代码行数:101,代码来源:ExportPngXml.cs

示例2: CalcWidthViaDraw

        /// <summary>
        /// The calc width via draw.
        /// </summary>
        /// <param name="text">
        /// The text.
        /// </param>
        /// <param name="parameter">
        /// The parameter.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        private static int CalcWidthViaDraw(string text, MakeBitmapParameter parameter)
        {
            // text = HtmlUtil.RemoveHtmlTags(text, true).Trim();
            text = text.Trim();
            var path = new GraphicsPath();
            var sb = new StringBuilder();
            int i = 0;
            bool isItalic = false;
            bool isBold = parameter.SubtitleFontBold;
            const float top = 5f;
            bool newLine = false;
            float left = 1.0f;
            float leftMargin = left;
            int newLinePathPoint = -1;
            Color c = parameter.SubtitleColor;
            var colorStack = new Stack<Color>();
            var lastText = new StringBuilder();
            var sf = new StringFormat { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Near };
            var bmp = new Bitmap(parameter.ScreenWidth, 200);
            var g = Graphics.FromImage(bmp);

            g.CompositingQuality = CompositingQuality.HighSpeed;
            g.SmoothingMode = SmoothingMode.HighSpeed;
            g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

            Font font = SetFont(parameter, parameter.SubtitleFontSize);
            while (i < text.Length)
            {
                if (text.Substring(i).StartsWith("<font ", StringComparison.OrdinalIgnoreCase))
                {
                    float addLeft = 0;
                    int oldPathPointIndex = path.PointCount;
                    if (oldPathPointIndex < 0)
                    {
                        oldPathPointIndex = 0;
                    }

                    if (sb.Length > 0)
                    {
                        lastText.Append(sb);
                        TextDraw.DrawText(font, sf, path, sb, isItalic, parameter.SubtitleFontBold, false, left, top, ref newLine, leftMargin, ref newLinePathPoint);
                    }

                    if (path.PointCount > 0)
                    {
                        var list = (PointF[])path.PathPoints.Clone(); // avoid using very slow path.PathPoints indexer!!!
                        for (int k = oldPathPointIndex; k < list.Length; k++)
                        {
                            if (list[k].X > addLeft)
                            {
                                addLeft = list[k].X;
                            }
                        }
                    }

                    if (path.PointCount == 0)
                    {
                        addLeft = left;
                    }
                    else if (addLeft < 0.01)
                    {
                        addLeft = left + 2;
                    }

                    left = addLeft;

                    DrawShadowAndPath(parameter, g, path);
                    var p2 = new SolidBrush(c);
                    g.FillPath(p2, path);
                    p2.Dispose();
                    path.Reset();
                    path = new GraphicsPath();
                    sb = new StringBuilder();

                    int endIndex = text.Substring(i).IndexOf('>');
                    if (endIndex < 0)
                    {
                        i += 9999;
                    }
                    else
                    {
                        string fontContent = text.Substring(i, endIndex);
                        if (fontContent.Contains(" color="))
                        {
                            string[] arr = fontContent.Substring(fontContent.IndexOf(" color=", StringComparison.Ordinal) + 7).Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                            if (arr.Length > 0)
                            {
                                string fontColor = arr[0].Trim('\'').Trim('"').Trim('\'');
//.........这里部分代码省略.........
开发者ID:KatyaMarincheva,项目名称:SubtitleEditOriginal,代码行数:101,代码来源:ExportPngXml.cs

示例3: GenerateImageFromTextWithStyle

        /// <summary>
        /// The generate image from text with style.
        /// </summary>
        /// <param name="parameter">
        /// The parameter.
        /// </param>
        /// <returns>
        /// The <see cref="Bitmap"/>.
        /// </returns>
        private static Bitmap GenerateImageFromTextWithStyle(MakeBitmapParameter parameter)
        {
            Bitmap bmp = null;
            if (!parameter.SimpleRendering && parameter.P.Text.Contains(Environment.NewLine) && (parameter.BoxSingleLine || parameter.P.Text.Contains(BoxSingleLineText)))
            {
                string old = parameter.P.Text;
                int oldType3D = parameter.Type3D;
                if (parameter.Type3D == 2)
                {
                    // Half-Top/Bottom 3D
                    parameter.Type3D = 0; // fix later
                }

                Color oldBackgroundColor = parameter.BackgroundColor;
                if (parameter.P.Text.Contains(BoxSingleLineText))
                {
                    parameter.P.Text = parameter.P.Text.Replace("<" + BoxSingleLineText + ">", string.Empty).Replace("</" + BoxSingleLineText + ">", string.Empty);
                    parameter.BackgroundColor = parameter.BorderColor;
                }

                bool italicOn = false;
                string fontTag = string.Empty;
                foreach (string line in parameter.P.Text.Replace(Environment.NewLine, "\n").Split('\n'))
                {
                    parameter.P.Text = line;
                    if (italicOn)
                    {
                        parameter.P.Text = "<i>" + parameter.P.Text;
                    }

                    italicOn = parameter.P.Text.Contains("<i>") && !parameter.P.Text.Contains("</i>");

                    parameter.P.Text = fontTag + parameter.P.Text;
                    if (parameter.P.Text.Contains("<font ") && !parameter.P.Text.Contains("</font>"))
                    {
                        int start = parameter.P.Text.LastIndexOf("<font ", StringComparison.Ordinal);
                        int end = parameter.P.Text.IndexOf('>', start);
                        fontTag = parameter.P.Text.Substring(start, end - start + 1);
                    }

                    var lineImage = GenerateImageFromTextWithStyleInner(parameter);
                    if (bmp == null)
                    {
                        bmp = lineImage;
                    }
                    else
                    {
                        int w = Math.Max(bmp.Width, lineImage.Width);
                        int h = bmp.Height + lineImage.Height;

                        int l1;
                        if (parameter.AlignLeft)
                        {
                            l1 = 0;
                        }
                        else if (parameter.AlignRight)
                        {
                            l1 = w - bmp.Width;
                        }
                        else
                        {
                            l1 = (int)Math.Round((w - bmp.Width) / 2.0);
                        }

                        int l2;
                        if (parameter.AlignLeft)
                        {
                            l2 = 0;
                        }
                        else if (parameter.AlignRight)
                        {
                            l2 = w - lineImage.Width;
                        }
                        else
                        {
                            l2 = (int)Math.Round((w - lineImage.Width) / 2.0);
                        }

                        if (parameter.LineHeight > lineImage.Height)
                        {
                            h += parameter.LineHeight - lineImage.Height;
                            var largeImage = new Bitmap(w, h);
                            var g = Graphics.FromImage(largeImage);
                            g.DrawImageUnscaled(bmp, new Point(l1, 0));
                            g.DrawImageUnscaled(lineImage, new Point(l2, bmp.Height + parameter.LineHeight - lineImage.Height));
                            bmp.Dispose();
                            bmp = largeImage;
                            g.Dispose();
                        }
                        else
                        {
//.........这里部分代码省略.........
开发者ID:KatyaMarincheva,项目名称:SubtitleEditOriginal,代码行数:101,代码来源:ExportPngXml.cs

示例4: CalcWidthViaDraw

 private static int CalcWidthViaDraw(string text, MakeBitmapParameter parameter)
 {
     var nbmp = GenereateBitmapForCalc(text, parameter);
     nbmp.CropTransparentSidesAndBottom(0, true);
     return nbmp.Width;
 }
开发者ID:LeonCheung,项目名称:subtitleedit,代码行数:6,代码来源:ExportPngXml.cs

示例5: DrawShadowAndPath

        /// <summary>
        /// The draw shadow and path.
        /// </summary>
        /// <param name="parameter">
        /// The parameter.
        /// </param>
        /// <param name="g">
        /// The g.
        /// </param>
        /// <param name="path">
        /// The path.
        /// </param>
        private static void DrawShadowAndPath(MakeBitmapParameter parameter, Graphics g, GraphicsPath path)
        {
            if (parameter.ShadowWidth > 0)
            {
                var shadowPath = (GraphicsPath)path.Clone();
                for (int k = 0; k < parameter.ShadowWidth; k++)
                {
                    var translateMatrix = new Matrix();
                    translateMatrix.Translate(1, 1);
                    shadowPath.Transform(translateMatrix);

                    var p1 = new Pen(Color.FromArgb(parameter.ShadowAlpha, parameter.ShadowColor), parameter.BorderWidth);
                    SetLineJoin(parameter.LineJoin, p1);
                    g.DrawPath(p1, shadowPath);
                    p1.Dispose();
                }
            }

            if (parameter.BorderWidth > 0)
            {
                var p1 = new Pen(parameter.BorderColor, parameter.BorderWidth);
                SetLineJoin(parameter.LineJoin, p1);
                g.DrawPath(p1, path);
                p1.Dispose();
            }
        }
开发者ID:KatyaMarincheva,项目名称:SubtitleEditOriginal,代码行数:38,代码来源:ExportPngXml.cs

示例6: comboBoxSubtitleFont_SelectedIndexChanged

        /// <summary>
        /// The combo box subtitle font_ selected index changed.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void comboBoxSubtitleFont_SelectedIndexChanged(object sender, EventArgs e)
        {
            var bmp = new Bitmap(100, 100);
            using (var g = Graphics.FromImage(bmp))
            {
                var mbp = new MakeBitmapParameter { SubtitleFontName = this._subtitleFontName, SubtitleFontSize = float.Parse(this.comboBoxSubtitleFontSize.SelectedItem.ToString()), SubtitleFontBold = this._subtitleFontBold };
                var fontSize = g.DpiY * mbp.SubtitleFontSize / 72;
                Font font = SetFont(mbp, fontSize);

                SizeF textSize = g.MeasureString("Hj!", font);
                int lineHeight = (int)Math.Round(textSize.Height * 0.64f);
                if (lineHeight >= this.numericUpDownLineSpacing.Minimum && lineHeight <= this.numericUpDownLineSpacing.Maximum && lineHeight != this.numericUpDownLineSpacing.Value)
                {
                    this.numericUpDownLineSpacing.Value = lineHeight;
                }
            }

            bmp.Dispose();
            this.subtitleListView1_SelectedIndexChanged(null, null);
        }
开发者ID:KatyaMarincheva,项目名称:SubtitleEditOriginal,代码行数:29,代码来源:ExportPngXml.cs

示例7: UpdateLineSpacing

        private void UpdateLineSpacing()
        {
            Bitmap bmp = new Bitmap(100, 100);
            using (Graphics g = Graphics.FromImage(bmp))
            {
                var mbp = new MakeBitmapParameter();
                mbp.SubtitleFontName = _subtitleFontName;
                mbp.SubtitleFontSize = float.Parse(comboBoxSubtitleFontSize.SelectedItem.ToString());
                mbp.SubtitleFontBold = _subtitleFontBold;
                var fontSize = g.DpiY * mbp.SubtitleFontSize / 72;
                Font font = SetFont(mbp, fontSize);

                SizeF textSize = g.MeasureString("Hj!", font);
                int lineHeight = (int)Math.Round(textSize.Height * 0.64f);

                var style = string.Empty;
                if (subtitleListView1.SelectedIndices.Count > 0)
                    style = GetStyleName(_subtitle.Paragraphs[subtitleListView1.SelectedItems[0].Index]);
                if (_lineHeights.ContainsKey(style))
                    numericUpDownLineSpacing.Value = _lineHeights[style];
                else if (lineHeight >= numericUpDownLineSpacing.Minimum && lineHeight <= numericUpDownLineSpacing.Maximum && lineHeight != numericUpDownLineSpacing.Value)
                    numericUpDownLineSpacing.Value = lineHeight;
                else if (lineHeight > numericUpDownLineSpacing.Maximum)
                    numericUpDownLineSpacing.Value = numericUpDownLineSpacing.Maximum;
            }
        }
开发者ID:mgziminsky,项目名称:subtitleedit,代码行数:26,代码来源:ExportPngXml.cs

示例8: comboBoxSubtitleFontSize_SelectedIndexChanged

        private void comboBoxSubtitleFontSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            Bitmap bmp = new Bitmap(100, 100);
            using (Graphics g = Graphics.FromImage(bmp))
            {
                var mbp = new MakeBitmapParameter();
                mbp.SubtitleFontName = _subtitleFontName;
                mbp.SubtitleFontSize = float.Parse(comboBoxSubtitleFontSize.SelectedItem.ToString());
                mbp.SubtitleFontBold = _subtitleFontBold;
                var fontSize = g.DpiY * mbp.SubtitleFontSize / 72;
                Font font = SetFont(mbp, fontSize);

                SizeF textSize = g.MeasureString("Hj!", font);
                int lineHeight = (int)Math.Round(textSize.Height * 0.64f);
                if (lineHeight >= numericUpDownLineSpacing.Minimum && lineHeight <= numericUpDownLineSpacing.Maximum && lineHeight != numericUpDownLineSpacing.Value)
                    numericUpDownLineSpacing.Value = lineHeight;
                else if (lineHeight > numericUpDownLineSpacing.Maximum)
                    numericUpDownLineSpacing.Value = numericUpDownLineSpacing.Maximum;
            }
            subtitleListView1_SelectedIndexChanged(null, null);
        }
开发者ID:Elheym,项目名称:subtitleedit,代码行数:21,代码来源:ExportPngXml.cs

示例9: GenerateImageFromTextWithStyle

        private static Bitmap GenerateImageFromTextWithStyle(MakeBitmapParameter parameter)
        {
            string text = parameter.P.Text;

            text = RemoveSubStationAlphaFormatting(text);

            text = text.Replace("<I>", "<i>");
            text = text.Replace("</I>", "</i>");
            text = Utilities.FixInvalidItalicTags(text);

            text = text.Replace("<B>", "<b>");
            text = text.Replace("</B>", "</b>");

            // no support for underline
            text = text.Replace("<u>", string.Empty);
            text = text.Replace("</u>", string.Empty);
            text = text.Replace("<U>", string.Empty);
            text = text.Replace("</U>", string.Empty);

            var bmp = new Bitmap(1, 1);
            var g = Graphics.FromImage(bmp);
            var fontSize = g.DpiY * parameter.SubtitleFontSize / 72;
            Font font = SetFont(parameter, parameter.SubtitleFontSize);
            var lineHeight = parameter.LineHeight; // (textSize.Height * 0.64f);

            var textSize = g.MeasureString(Utilities.RemoveHtmlTags(text), font);
            g.Dispose();
            bmp.Dispose();
            int sizeX = (int)(textSize.Width * 1.8) + 150;
            int sizeY = (int)(textSize.Height * 0.9) + 50;
            if (sizeX < 1)
                sizeX = 1;
            if (sizeY < 1)
                sizeY = 1;
            bmp = new Bitmap(sizeX, sizeY);
            g = Graphics.FromImage(bmp);
            if (parameter.BackgroundColor != Color.Transparent)
                g.FillRectangle(new SolidBrush(parameter.BackgroundColor), 0, 0, bmp.Width, bmp.Height);

            // align lines with gjpqy, a bit lower
            var lines = text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            int baseLinePadding = 13;
            if (parameter.SubtitleFontSize < 30)
                baseLinePadding = 12;
            if (parameter.SubtitleFontSize < 25)
                baseLinePadding = 9;
            if (lines.Length > 0)
            {
                if (lines[lines.Length - 1].Contains("g") || lines[lines.Length - 1].Contains("j") || lines[lines.Length - 1].Contains("p") || lines[lines.Length - 1].Contains("q") || lines[lines.Length - 1].Contains("y") || lines[lines.Length - 1].Contains(","))
                {
                    string textNoBelow = lines[lines.Length - 1].Replace("g", "a").Replace("j", "a").Replace("p", "a").Replace("q", "a").Replace("y", "a").Replace(",", "a");
                    baseLinePadding -= (int)Math.Round((TextDraw.MeasureTextHeight(font, lines[lines.Length - 1], parameter.SubtitleFontBold) - TextDraw.MeasureTextHeight(font, textNoBelow, parameter.SubtitleFontBold)));
                }
                else
                {
                    baseLinePadding += 1;
                }
                if (baseLinePadding < 0)
                    baseLinePadding = 0;
            }

            //TODO: Better baseline - test http://bobpowell.net/formattingtext.aspx
            //float baselineOffset=font.SizeInPoints/font.FontFamily.GetEmHeight(font.Style)*font.FontFamily.GetCellAscent(font.Style);
            //float baselineOffsetPixels = g.DpiY/72f*baselineOffset;
            //baseLinePadding = (int)Math.Round(baselineOffsetPixels);

            var lefts = new List<float>();
            if (text.ToLower().Contains("<font") || text.ToLower().Contains("<i>"))
            {
                foreach (string line in text.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
                {
                    string lineNoHtml = Utilities.RemoveHtmlFontTag(line.Replace("<i>", string.Empty).Replace("</i>", string.Empty));
                    if (parameter.AlignLeft)
                        lefts.Add(5);
                    else if (parameter.AlignRight)
                        lefts.Add(bmp.Width - CalcWidthViaDraw(lineNoHtml, parameter) + 15); // calculate via drawing+crop
                    else
                        lefts.Add((bmp.Width - CalcWidthViaDraw(lineNoHtml, parameter) + 15) / 2); // calculate via drawing+crop
                }
            }
            else
            {
                foreach (string line in Utilities.RemoveHtmlFontTag(text.Replace("<i>", string.Empty).Replace("</i>", string.Empty)).Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
                {
                    if (parameter.AlignLeft)
                        lefts.Add(5);
                    else if (parameter.AlignRight)
                        lefts.Add(bmp.Width - (TextDraw.MeasureTextWidth(font, line, parameter.SubtitleFontBold) + 15));
                    else
                        lefts.Add((bmp.Width - TextDraw.MeasureTextWidth(font, line, parameter.SubtitleFontBold) + 15) / 2);
                }
            }

            g.CompositingQuality = CompositingQuality.HighQuality;
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.SmoothingMode = SmoothingMode.HighQuality;
            g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

            var sf = new StringFormat();
            sf.Alignment = StringAlignment.Near;
//.........这里部分代码省略.........
开发者ID:rebawest,项目名称:subtitleedit,代码行数:101,代码来源:ExportPngXml.cs

示例10: FormatFabTime

 private string FormatFabTime(TimeCode time, MakeBitmapParameter param)
 {
     if (param.Bitmap.Width == 720 && param.Bitmap.Width == 480) // NTSC
         return string.Format("{0:00};{1:00};{2:00};{3:00}", time.Hours, time.Minutes, time.Seconds, SubtitleFormat.MillisecondsToFramesMaxFrameRate(time.Milliseconds));
     return string.Format("{0:00}:{1:00}:{2:00}:{3:00}", time.Hours, time.Minutes, time.Seconds, SubtitleFormat.MillisecondsToFramesMaxFrameRate(time.Milliseconds));
 }
开发者ID:nguansak,项目名称:subtitleedit,代码行数:6,代码来源:ExportPngXml.cs

示例11: WriteParagraph

        private int WriteParagraph(int width, StringBuilder sb, int border, int height, int imagesSavedCount,
            VobSubWriter vobSubWriter, FileStream binarySubtitleFile, MakeBitmapParameter param, int i)
        {
            if (param.Bitmap != null)
            {
                if (_exportType == "BLURAYSUP")
                {
                    if (!param.Saved)
                        binarySubtitleFile.Write(param.Buffer, 0, param.Buffer.Length);
                    param.Saved = true;
                }
                else if (_exportType == "VOBSUB")
                {
                    if (!param.Saved)
                        vobSubWriter.WriteParagraph(param.P, param.Bitmap, param.Alignment);
                    param.Saved = true;
                }
                else if (_exportType == "FAB")
                {
                    if (!param.Saved)
                    {
                        string numberString = string.Format("IMAGE{0:000}", i);
                        string fileName = Path.Combine(folderBrowserDialog1.SelectedPath, numberString + "." + comboBoxImageFormat.Text.ToLower());
                        param.Bitmap.Save(fileName, ImageFormat);
                        imagesSavedCount++;

                        //RACE001.TIF 00;00;02;02 00;00;03;15 000 000 720 480
                        //RACE002.TIF 00;00;05;18 00;00;09;20 000 000 720 480
                        int top = param.ScreenHeight - (param.Bitmap.Height + param.BottomMargin);
                        int left = (param.ScreenWidth - param.Bitmap.Width) / 2;

                        if (param.Alignment == ContentAlignment.BottomLeft || param.Alignment == ContentAlignment.MiddleLeft || param.Alignment == ContentAlignment.TopLeft)
                            left = param.BottomMargin;
                        else if (param.Alignment == ContentAlignment.BottomRight || param.Alignment == ContentAlignment.MiddleRight || param.Alignment == ContentAlignment.TopRight)
                            left = param.ScreenWidth - param.Bitmap.Width - param.BottomMargin;
                        if (param.Alignment == ContentAlignment.TopLeft || param.Alignment == ContentAlignment.TopCenter || param.Alignment == ContentAlignment.TopRight)
                            top = param.BottomMargin;
                        if (param.Alignment == ContentAlignment.MiddleLeft || param.Alignment == ContentAlignment.MiddleCenter || param.Alignment == ContentAlignment.MiddleRight)
                            top = param.ScreenHeight - (param.Bitmap.Height / 2);

                        sb.AppendLine(string.Format("{0} {1} {2} {3} {4} {5} {6}", Path.GetFileName(fileName), FormatFabTime(param.P.StartTime, param), FormatFabTime(param.P.EndTime, param), left, top, left + param.Bitmap.Width, top + param.Bitmap.Height));
                        param.Saved = true;
                    }
                }
                else if (_exportType == "STL")
                {
                    if (!param.Saved)
                    {
                        string numberString = string.Format("IMAGE{0:000}", i);
                        string fileName = Path.Combine(folderBrowserDialog1.SelectedPath, numberString + "." + comboBoxImageFormat.Text.ToLower());
                        param.Bitmap.Save(fileName, ImageFormat);
                        imagesSavedCount++;

                        const string paragraphWriteFormat = "{0} , {1} , {2}\r\n";
                        const string timeFormat = "{0:00}:{1:00}:{2:00}:{3:00}";

                        double factor = (1000.0 / Configuration.Settings.General.CurrentFrameRate);
                        string startTime = string.Format(timeFormat, param.P.StartTime.Hours, param.P.StartTime.Minutes, param.P.StartTime.Seconds, (int)Math.Round(param.P.StartTime.Milliseconds / factor));
                        string endTime = string.Format(timeFormat, param.P.EndTime.Hours, param.P.EndTime.Minutes, param.P.EndTime.Seconds, (int)Math.Round(param.P.EndTime.Milliseconds / factor));
                        sb.Append(string.Format(paragraphWriteFormat, startTime, endTime, fileName));

                        param.Saved = true;
                    }
                }
                else if (_exportType == "SPUMUX")
                {
                    if (!param.Saved)
                    {
                        string numberString = string.Format("IMAGE{0:000}", i);
                        string fileName = Path.Combine(folderBrowserDialog1.SelectedPath, numberString + "." + comboBoxImageFormat.Text.ToLower());

                        foreach (var encoder in ImageCodecInfo.GetImageEncoders())
                        {
                            if (encoder.FormatID == ImageFormat.Png.Guid)
                            {
                                var parameters = new EncoderParameters();
                                parameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.ColorDepth, 8);

                                var nbmp = new NikseBitmap(param.Bitmap);
                                var b = nbmp.ConverTo8BitsPerPixel();
                                b.Save(fileName, encoder, parameters);
                                b.Dispose();

                                break;
                            }
                        }
                        imagesSavedCount++;

                        const string paragraphWriteFormat = "\t\t<spu start=\"{0}\" end=\"{1}\" image=\"{2}\"  />";
                        const string timeFormat = "{0:00}:{1:00}:{2:00}:{3:00}";

                        double factor = (1000.0 / Configuration.Settings.General.CurrentFrameRate);
                        string startTime = string.Format(timeFormat, param.P.StartTime.Hours, param.P.StartTime.Minutes, param.P.StartTime.Seconds, (int)Math.Round(param.P.StartTime.Milliseconds / factor));
                        string endTime = string.Format(timeFormat, param.P.EndTime.Hours, param.P.EndTime.Minutes, param.P.EndTime.Seconds, (int)Math.Round(param.P.EndTime.Milliseconds / factor));
                        sb.AppendLine(string.Format(paragraphWriteFormat, startTime, endTime, fileName));

                        param.Saved = true;
                    }
                }
                else if (_exportType == "FCP")
//.........这里部分代码省略.........
开发者ID:rebawest,项目名称:subtitleedit,代码行数:101,代码来源:ExportPngXml.cs

示例12: MakeMakeBitmapParameter

        private MakeBitmapParameter MakeMakeBitmapParameter(int index, int screenWidth,int screenHeight)
        {
            var parameter = new MakeBitmapParameter
                                {
                                    Type = _exportType,
                                    SubtitleColor = _subtitleColor,
                                    SubtitleFontName = _subtitleFontName,
                                    SubtitleFontSize = _subtitleFontSize,
                                    SubtitleFontBold = _subtitleFontBold,
                                    BorderColor = _borderColor,
                                    BorderWidth = _borderWidth,
                                    SimpleRendering = checkBoxSimpleRender.Checked,
                                    AlignLeft = comboBoxHAlign.SelectedIndex == 0,
                                    AlignRight = comboBoxHAlign.SelectedIndex == 2,
                                    ScreenWidth = screenWidth,
                                    ScreenHeight = screenHeight,
                                    Bitmap = null,
                                    FramesPerSeconds = FrameRate,
                                    BottomMargin =  comboBoxBottomMargin.SelectedIndex,
                                    Saved = false,
                                    Alignment = ContentAlignment.BottomCenter,
                                    Type3D = comboBox3D.SelectedIndex,
                                    Depth3D = (int)numericUpDownDepth3D.Value,
                                    BackgroundColor = Color.Transparent,
                                    SavDialogFileName = saveFileDialog1.FileName,
                                    ShadowColor = panelShadowColor.BackColor,
                                    ShadowWidth = (int)comboBoxShadowWidth.SelectedIndex,
                                    ShadowAlpha = (int)numericUpDownShadowTransparency.Value,
                                    LineHeight = (int)numericUpDownLineSpacing.Value,
                                };
            if (index < _subtitle.Paragraphs.Count)
            {
                parameter.P = _subtitle.Paragraphs[index];
                parameter.Alignment = GetAlignmentFromParagraph(parameter.P,_format, _subtitle);

                if (_format.HasStyleSupport && !string.IsNullOrEmpty(parameter.P.Extra))
                {
                    if (_format.GetType() == typeof(SubStationAlpha))
                    {
                        var style = AdvancedSubStationAlpha.GetSsaStyle(parameter.P.Extra, _subtitle.Header);
                        parameter.SubtitleColor = style.Primary;
                        parameter.SubtitleFontBold = style.Bold;
                        parameter.SubtitleFontSize = style.FontSize;
                        if (style.BorderStyle == "3")
                        {
                            parameter.BackgroundColor = style.Background;
                        }
                    }
                    else if (_format.GetType() == typeof(AdvancedSubStationAlpha))
                    {
                        var style = AdvancedSubStationAlpha.GetSsaStyle(parameter.P.Extra, _subtitle.Header);
                        parameter.SubtitleColor = style.Primary;
                        parameter.SubtitleFontBold = style.Bold;
                        parameter.SubtitleFontSize = style.FontSize;
                        if (style.BorderStyle == "3")
                        {
                            parameter.BackgroundColor = style.Outline;
                        }
                    }
                }
            }
            else
            {
                parameter.P = null;
            }
            return parameter;
        }
开发者ID:rebawest,项目名称:subtitleedit,代码行数:67,代码来源:ExportPngXml.cs

示例13: GetAlignmentFromParagraph

        /// <summary>
        /// The get alignment from paragraph.
        /// </summary>
        /// <param name="p">
        /// The p.
        /// </param>
        /// <param name="format">
        /// The format.
        /// </param>
        /// <param name="subtitle">
        /// The subtitle.
        /// </param>
        /// <returns>
        /// The <see cref="ContentAlignment"/>.
        /// </returns>
        private static ContentAlignment GetAlignmentFromParagraph(MakeBitmapParameter p, SubtitleFormat format, Subtitle subtitle)
        {
            var alignment = ContentAlignment.BottomCenter;
            if (p.AlignLeft)
            {
                alignment = ContentAlignment.BottomLeft;
            }
            else if (p.AlignRight)
            {
                alignment = ContentAlignment.BottomRight;
            }

            if (format.HasStyleSupport && !string.IsNullOrEmpty(p.P.Extra))
            {
                if (format.GetType() == typeof(SubStationAlpha))
                {
                    var style = AdvancedSubStationAlpha.GetSsaStyle(p.P.Extra, subtitle.Header);
                    alignment = GetSsaAlignment("{\\a" + style.Alignment + "}", alignment);
                }
                else if (format.GetType() == typeof(AdvancedSubStationAlpha))
                {
                    var style = AdvancedSubStationAlpha.GetSsaStyle(p.P.Extra, subtitle.Header);
                    alignment = GetAssAlignment("{\\an" + style.Alignment + "}", alignment);
                }
            }

            string text = p.P.Text;
            if (format.GetType() == typeof(SubStationAlpha) && text.Length > 5)
            {
                text = p.P.Text.Substring(0, 6);
                alignment = GetSsaAlignment(text, alignment);
            }
            else if (text.Length > 6)
            {
                text = p.P.Text.Substring(0, 6);
                alignment = GetAssAlignment(text, alignment);
            }

            return alignment;
        }
开发者ID:KatyaMarincheva,项目名称:SubtitleEditOriginal,代码行数:55,代码来源:ExportPngXml.cs

示例14: WriteParagraph

        /// <summary>
        /// The write paragraph.
        /// </summary>
        /// <param name="width">
        /// The width.
        /// </param>
        /// <param name="sb">
        /// The sb.
        /// </param>
        /// <param name="border">
        /// The border.
        /// </param>
        /// <param name="height">
        /// The height.
        /// </param>
        /// <param name="imagesSavedCount">
        /// The images saved count.
        /// </param>
        /// <param name="vobSubWriter">
        /// The vob sub writer.
        /// </param>
        /// <param name="binarySubtitleFile">
        /// The binary subtitle file.
        /// </param>
        /// <param name="param">
        /// The param.
        /// </param>
        /// <param name="i">
        /// The i.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        private int WriteParagraph(int width, StringBuilder sb, int border, int height, int imagesSavedCount, VobSubWriter vobSubWriter, FileStream binarySubtitleFile, MakeBitmapParameter param, int i)
        {
            if (param.Bitmap != null)
            {
                if (this._exportType == "BLURAYSUP")
                {
                    if (!param.Saved)
                    {
                        binarySubtitleFile.Write(param.Buffer, 0, param.Buffer.Length);
                    }

                    param.Saved = true;
                }
                else if (this._exportType == "VOBSUB")
                {
                    if (!param.Saved)
                    {
                        vobSubWriter.WriteParagraph(param.P, param.Bitmap, param.Alignment);
                    }

                    param.Saved = true;
                }
                else if (this._exportType == "FAB")
                {
                    if (!param.Saved)
                    {
                        string numberString = string.Format("IMAGE{0:000}", i);
                        string fileName = Path.Combine(this.folderBrowserDialog1.SelectedPath, numberString + "." + this.comboBoxImageFormat.Text.ToLower());

                        if (this.checkBoxFullFrameImage.Visible && this.checkBoxFullFrameImage.Checked)
                        {
                            var nbmp = new NikseBitmap(param.Bitmap);
                            nbmp.ReplaceTransparentWith(this.panelFullFrameBackground.BackColor);
                            using (var bmp = nbmp.GetBitmap())
                            {
                                // param.Bitmap.Save(fileName, ImageFormat);
                                imagesSavedCount++;

                                // RACE001.TIF 00;00;02;02 00;00;03;15 000 000 720 480
                                // RACE002.TIF 00;00;05;18 00;00;09;20 000 000 720 480
                                int top = param.ScreenHeight - (param.Bitmap.Height + param.BottomMargin);
                                int left = (param.ScreenWidth - param.Bitmap.Width) / 2;

                                var b = new NikseBitmap(param.ScreenWidth, param.ScreenHeight);
                                {
                                    b.Fill(this.panelFullFrameBackground.BackColor);
                                    using (var fullSize = b.GetBitmap())
                                    {
                                        if (param.Alignment == ContentAlignment.BottomLeft || param.Alignment == ContentAlignment.MiddleLeft || param.Alignment == ContentAlignment.TopLeft)
                                        {
                                            left = param.LeftRightMargin;
                                        }
                                        else if (param.Alignment == ContentAlignment.BottomRight || param.Alignment == ContentAlignment.MiddleRight || param.Alignment == ContentAlignment.TopRight)
                                        {
                                            left = param.ScreenWidth - param.Bitmap.Width - param.LeftRightMargin;
                                        }

                                        if (param.Alignment == ContentAlignment.TopLeft || param.Alignment == ContentAlignment.TopCenter || param.Alignment == ContentAlignment.TopRight)
                                        {
                                            top = param.BottomMargin;
                                        }

                                        if (param.Alignment == ContentAlignment.MiddleLeft || param.Alignment == ContentAlignment.MiddleCenter || param.Alignment == ContentAlignment.MiddleRight)
                                        {
                                            top = param.ScreenHeight - (param.Bitmap.Height / 2);
                                        }

//.........这里部分代码省略.........
开发者ID:KatyaMarincheva,项目名称:SubtitleEditOriginal,代码行数:101,代码来源:ExportPngXml.cs

示例15: Make3DTopBottom

        /// <summary>
        /// The make 3 d top bottom.
        /// </summary>
        /// <param name="parameter">
        /// The parameter.
        /// </param>
        /// <param name="nbmp">
        /// The nbmp.
        /// </param>
        /// <returns>
        /// The <see cref="NikseBitmap"/>.
        /// </returns>
        private static NikseBitmap Make3DTopBottom(MakeBitmapParameter parameter, NikseBitmap nbmp)
        {
            Bitmap singleBmp = nbmp.GetBitmap();
            Bitmap singleHalfBmp = ScaleToHalfHeight(singleBmp);
            singleBmp.Dispose();
            var topBottomBmp = new Bitmap(parameter.ScreenWidth, parameter.ScreenHeight - parameter.BottomMargin);
            int singleHeight = parameter.ScreenHeight / 2;
            int leftM = (parameter.ScreenWidth / 2) - (singleHalfBmp.Width / 2);

            using (Graphics gTopBottom = Graphics.FromImage(topBottomBmp))
            {
                gTopBottom.DrawImage(singleHalfBmp, leftM + parameter.Depth3D, singleHeight - singleHalfBmp.Height - parameter.BottomMargin);
                gTopBottom.DrawImage(singleHalfBmp, leftM - parameter.Depth3D, parameter.ScreenHeight - parameter.BottomMargin - singleHalfBmp.Height);
            }

            nbmp = new NikseBitmap(topBottomBmp);
            if (parameter.BackgroundColor == Color.Transparent)
            {
                nbmp.CropTop(2, Color.Transparent);
                nbmp.CropTransparentSidesAndBottom(2, false);
            }
            else
            {
                nbmp.CropTop(4, parameter.BackgroundColor);
                nbmp.CropSidesAndBottom(4, parameter.BackgroundColor, false);
            }

            return nbmp;
        }
开发者ID:KatyaMarincheva,项目名称:SubtitleEditOriginal,代码行数:41,代码来源:ExportPngXml.cs


注:本文中的MakeBitmapParameter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。