コード例 #1
0
ファイル: HD_Base.cs プロジェクト: 2830499544/JXHW
        public static string GenerateMoveLiftRealtimeXml(HDFileList list, string guid)
        {
            string        configPath = "D:\\HDSDK1.1_DEMO\\Temp\\" + DateTime.Now.ToString("yyyy-MM-dd_hhmmss") + ".xml";
            XmlTextWriter xml        = new XmlTextWriter(configPath, Encoding.UTF8);

            xml.Formatting = System.Xml.Formatting.Indented;
            xml.WriteStartDocument();
            xml.WriteStartElement("config.boo");
            xml.WriteStartElement("content");
            xml.WriteAttributeString("realTime", "1");
            xml.WriteStartElement("materials");
            xml.WriteStartElement("text");
            xml.WriteAttributeString("action", "update");
            xml.WriteAttributeString("guid", guid);

            xml.WriteStartElement("singleMode");
            xml.WriteValue(1);
            xml.WriteEndElement();
            xml.WriteStartElement("pageCount");
            xml.WriteValue(list.FileList.Length);
            xml.WriteEndElement();

            // <continuousMove headCloseToTail="0" speed ="4" playType ="ByCount" byCount ="2000"/>
            xml.WriteStartElement("continuousMove");
            xml.WriteAttributeString("headCloseToTail", "0");
            xml.WriteAttributeString("speed", "4");
            xml.WriteAttributeString("playType", "ByCount");
            xml.WriteAttributeString("byCount", "2000");
            xml.WriteEndElement();

            foreach (HDFileListItem item in list.FileList)
            {
                FileStream file = new FileStream(item.path, FileMode.Open);
                System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
                byte[] retVal = md5.ComputeHash(file);

                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < retVal.Length; i++)
                {
                    sb.Append(retVal[i].ToString("x2"));
                }

                xml.WriteStartElement("file");
                xml.WriteAttributeString("size", file.Length.ToString());
                xml.WriteAttributeString("path", item.path);
                xml.WriteAttributeString("md5", sb.ToString());
                xml.WriteEndElement(); // end file
                file.Close();
            }

            xml.WriteEndElement(); // end image
            xml.WriteEndElement(); // end materials
            xml.WriteEndElement(); // end content
            xml.WriteEndElement(); // end config.boo
            xml.Close();
            return(configPath);
        }
コード例 #2
0
ファイル: HD_Base.cs プロジェクト: 2830499544/JXHW
        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);
        }
コード例 #3
0
ファイル: HD_Base.cs プロジェクト: 2830499544/JXHW
        public static void TextMaterialsMiddle(HDFileList list, Size areaSize)
        {
            foreach (var item in list.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);
            }
        }
コード例 #4
0
ファイル: HD_Base.cs プロジェクト: 2830499544/JXHW
        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);
        }