public static HDFileList GetTextMaterials(Size areaSize, HDFont font, string s, bool consecutive, bool alignCenter = false, bool colorKey = false) { FontStyle fontStyle = FontStyle.Regular; if (font.Bold == 1) { fontStyle |= FontStyle.Bold; } if (font.Italic == 1) { fontStyle |= FontStyle.Italic; } if (font.Underline == 1) { fontStyle |= FontStyle.Underline; } Font drawFont = new Font(font.FontName, (float)(font.FontSize), fontStyle, GraphicsUnit.Pixel); SolidBrush drawBrush = new SolidBrush(Color.Red); StringFormat drawFormat = StringFormat.GenericTypographic; drawFormat.Alignment = alignCenter ? StringAlignment.Center : StringAlignment.Near; if (consecutive) { Graphics g = Graphics.FromHwnd(IntPtr.Zero); SizeF size = g.MeasureString(s, drawFont, new PointF(0, 0), drawFormat); areaSize.Width = (int)Math.Ceiling(size.Width); } List <HDFileListItem> list = new List <HDFileListItem>(); string pathPrefix = Environment.CurrentDirectory + "\\temp\\" + GetTimeStamp(); if (!Directory.Exists(Environment.CurrentDirectory + "\\temp\\")) { Directory.CreateDirectory(Environment.CurrentDirectory + "\\temp\\"); } while (s != string.Empty) { HDFileListItem item = new HDFileListItem(); item.path = pathPrefix + "-" + list.Count.ToString() + ".png"; s = DrawPage(drawFont, drawBrush, areaSize, drawFormat, s, item.path, consecutive, colorKey); list.Add(item); } HDFileList fileList = new HDFileList(); fileList.FileList = list.ToArray(); return(fileList); }
public static byte[] GenerateSinglelineTextXml(Size areaSize, string text, HDFont font) { MemoryStream stream = new MemoryStream(); XmlTextWriter xml = new XmlTextWriter(stream, Encoding.UTF8); xml.Formatting = System.Xml.Formatting.Indented; xml.WriteStartDocument(); xml.WriteStartElement("config.boo"); xml.WriteStartElement("content"); xml.WriteStartElement("channel"); xml.WriteAttributeString("setSize", "0"); xml.WriteEndElement(); xml.WriteStartElement("channel"); xml.WriteAttributeString("action", "add"); xml.WriteStartElement("area"); xml.WriteAttributeString("action", "add"); xml.WriteStartElement("rectangle"); xml.WriteAttributeString("x", "0"); xml.WriteAttributeString("y", "0"); xml.WriteAttributeString("width", areaSize.Width.ToString()); xml.WriteAttributeString("height", areaSize.Height.ToString()); xml.WriteEndElement(); // rectangle xml.WriteStartElement("materials"); HDRealtimeItem item = new HDRealtimeItem(); item.FileList = GetTextMaterials(areaSize, font, text, true); item.Guid = "abc"; item.type = HDRealtimeItemType.kContinuousText; WriteContinousTextItem(xml, item, true); xml.WriteEndElement(); // materials xml.WriteEndElement(); // area xml.WriteEndElement(); // channel xml.WriteEndElement(); // end content xml.WriteEndElement(); // end config.boo xml.Close(); //FileStream s = File.Create("D:\\t.xml"); //s.Write(stream.ToArray(), 0, stream.ToArray().Count()); //s.Close(); return(stream.ToArray()); }
public static HDFileList GetTextMaterials(string deviceType, Size areaSize, HDFont font, string s, bool consecutive, bool alignCenter = false) { HD_Init(); if (consecutive) { alignCenter = false; } if (alignCenter) { consecutive = true; } HDScreenNodeAttr screenNodeAttr = new HDScreenNodeAttr(); screenNodeAttr.Width = 128; screenNodeAttr.Height = 64; screenNodeAttr.DeviceType = new char[20]; for (int i = 0; i < deviceType.Length; i++) { screenNodeAttr.DeviceType[i] = deviceType[i]; } //IntPtr screen = Marshal.AllocHGlobal(4); IntPtr screen; HDErrorCode code = HD_Base.HDSDK_CreateScreen(out screen, ref screenNodeAttr); IntPtr program;// = Marshal.AllocHGlobal(4); HDProgramNodeAttr ProgramNodeAttr = new HDProgramNodeAttr(); ProgramNodeAttr.Parent = screen; code = HD_Base.HDSDK_CreateProgram(out program, ref ProgramNodeAttr); IntPtr area;// = Marshal.AllocHGlobal(4); HDAreaNodeAttr AreaNodeAttr = new HDAreaNodeAttr(); AreaNodeAttr.Parent = program; AreaNodeAttr.Alpha = 0xFF; AreaNodeAttr.Rect.X = 0; AreaNodeAttr.Rect.Y = 0; AreaNodeAttr.Rect.Width = areaSize.Width; AreaNodeAttr.Rect.Height = areaSize.Height; code = HD_Base.HDSDK_CreateArea(out area, ref AreaNodeAttr); IntPtr text;// = Marshal.AllocHGlobal(4); HDTextNodeAttr PlainTextStringTextNodeAttr1 = new HDTextNodeAttr(); PlainTextStringTextNodeAttr1.Parent = area; PlainTextStringTextNodeAttr1.TextType = HDTextType.kPlainTextString; //PlainTextStringTextNodeAttr1.BackgroundColor = 0x00000000; PlainTextStringTextNodeAttr1.Alignment = 1;//0、1、2对齐方式 PlainTextStringTextNodeAttr1.Multiline = consecutive ? 0 : 1; PlainTextStringTextNodeAttr1.font = font; PlainTextStringTextNodeAttr1.text = s; PlainTextStringTextNodeAttr1.Effect.DispEffect = consecutive ? HDEffectType.kHT_LEFT_SERIES_MOVE : HDEffectType.kLEFT_TOP_COVER; PlainTextStringTextNodeAttr1.Effect.DispSpeed = 1; PlainTextStringTextNodeAttr1.Effect.HoldTime = 50; PlainTextStringTextNodeAttr1.Effect.ClearEffect = consecutive ? HDEffectType.kNOT_CLEAR_AREA : HDEffectType.kLEFT_TOP_COVER; PlainTextStringTextNodeAttr1.Effect.ClearSpeed = 1; code = HD_Base.HDSDK_CreateText(out text, ref PlainTextStringTextNodeAttr1); IntPtr init = Marshal.AllocHGlobal(4); code = HD_Base.HDSDK_GetNodeFileList(text, out init); HD_Base.HDSDK_FreeNode(screen); string json = Marshal.PtrToStringAnsi(init); HD_Base.HDSDK_FreePtr(init); JsonSerializer serializer = new JsonSerializer(); StringReader sr = new StringReader(json); object o = serializer.Deserialize(new JsonTextReader(sr), typeof(HDFileList)); HDFileList t = o as HDFileList; if (alignCenter) { foreach (var item in t.FileList) { Bitmap b = new Bitmap(item.path); Bitmap a = new Bitmap(areaSize.Width, areaSize.Height); Graphics g = Graphics.FromImage(a); g.DrawImage(b, (areaSize.Width - b.Width) / 2, 0); g.Save(); b.Dispose(); a.Save(item.path); } } return(null); }