Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
 public static extern HDErrorCode HDSDK_CreateProgram(out IntPtr node, ref HDProgramNodeAttr attr);