コード例 #1
0
    IEnumerator DownloadHander()
    {
        WWW www = new WWW(gif);

        yield return(www);

        File.WriteAllBytes(Application.temporaryCachePath + "/" + gif.GetHashCode(), www.bytes);
        ImgType type = Util.sington.GetTypeByBytes(www.bytes);

        print("type1:" + type);

        www = new WWW(png);
        yield return(www);

        File.WriteAllBytes(Application.temporaryCachePath + "/" + png.GetHashCode(), www.bytes);
        type = Util.sington.GetTypeByBytes(www.bytes);
        print("type2:" + type);

        www = new WWW(jpg);
        yield return(www);

        File.WriteAllBytes(Application.temporaryCachePath + "/" + jpg.GetHashCode(), www.bytes);
        type = Util.sington.GetTypeByBytes(www.bytes);
        print("type3:" + type);
        www.Dispose();
    }
コード例 #2
0
ファイル: RelistImgWin.cs プロジェクト: eglrp/Excercise
        //开始重排序图片
        private void btn_Relist_Click(object sender, EventArgs e)
        {
            new Thread(run).Start();
            picRunning.Visible = true;

            //保存本次设置
            OperateIni.WriteIniData(IniSection, "sourcePath", txtSourcePath.Text);
            OperateIni.WriteIniData(IniSection, "targetPath", txtTargetPath.Text);
            OperateIni.WriteIniData(IniSection, "excludeFloder", txtExcludeFloder.Text);
            ImgType type = new ImgType();

            switch (cmbImgType.Text)
            {
            case "横图":
                type = ImgType.Horizon;
                break;

            case "竖图":
                type = ImgType.Vertical;
                break;

            default:
                break;
            }
            OperateIni.WriteIniData(IniSection, "imgType", (int)type);
            OperateIni.WriteIniData(IniSection, "minImgWidth", txtMinImgWidth.Text);
            OperateIni.WriteIniData(IniSection, "startAt", dtpStart.Value);
            OperateIni.WriteIniData(IniSection, "checkTime", checkTime.Checked);
            OperateIni.WriteIniData(IniSection, "checkCopy", checkCopy.Checked);
            OperateIni.WriteIniData(IniSection, "checkDeep", checkDeep.Checked);
            OperateIni.WriteIniData(IniSection, "limitNum", txtLimitNum.Text);
            OperateIni.WriteIniData(IniSection, "txtSortReg", txtSortReg.Text);
        }
コード例 #3
0
        //生成中文二维码-支持中文(自定义大小)
        //暂时未完善 只定义了背景大小
        static void Generate(string url, string filename, string savapath, ImgType type = ImgType.Png, int?width = null, int?high = null)
        {
            QrEncoder qrEncoder = new QrEncoder();
            var       qrCode    = qrEncoder.Encode(url);
            //保存成png文件
            //string filename = @"H:\桌面\截图\cn.png";
            string suffix = ImgSuffix.Getsuffix(type);; //后缀

            filename = $"{savapath}{filename}{suffix}";
            GraphicsRenderer render = new GraphicsRenderer(new FixedModuleSize(5, QuietZoneModules.Two), Brushes.Black, Brushes.White);
            int w = 500;
            int h = 500;

            if (width != null)
            {
                w = (int)width;
            }
            if (high != null)
            {
                h = (int)high;
            }
            Bitmap   map = new Bitmap(w, h);
            Graphics g   = Graphics.FromImage(map);

            g.FillRectangle(Brushes.White, 0, 0, w, h);
            render.Draw(g, qrCode.Matrix, new Point(20, 20));
            map.Save(filename, ImageFormat.Png);
        }
コード例 #4
0
ファイル: ImgTypeDal.cs プロジェクト: liuyim93/yohome
        /// <summary>
        /// 添加图片类型
        /// </summary>
        /// <param name="imgType"></param>
        /// <returns></returns>
        public static int AddImgType(ImgType imgType)
        {
            string sql = "insert into ImgType (TypeName,Remark)values(@TypeName,@Remark)";

            return(SqlHelper.ExecuteNonQuery(CommandType.Text, sql, new OleDbParameter("@TypeName", imgType.TypeName),
                                             new OleDbParameter("@Remark", imgType.Remark)));
        }
コード例 #5
0
        //开始复制图片
        private void btn_Start_Click(object sender, EventArgs e)
        {
            //判断目标文件夹是否存在,不存在则创建文件
            if (!Directory.Exists(txtTargetPath.Text))
            {
                Directory.CreateDirectory(txtTargetPath.Text);
            }
            new Thread(run).Start();
            picRunning.Visible = true;

            //保存本次信息
            OperateIni.WriteIniData(IniSection, "sourcePath", txtSourcePath.Text);
            OperateIni.WriteIniData(IniSection, "targetPath", txtTargetPath.Text);
            OperateIni.WriteIniData(IniSection, "excludeFloder", txtExcludeFloder.Text);
            ImgType type = new ImgType();

            switch (cmbImgType.Text)
            {
            case "横图":
                type = ImgType.Horizon;
                break;

            case "竖图":
                type = ImgType.Vertical;
                break;

            default:
                break;
            }
            OperateIni.WriteIniData(IniSection, "imgType", (int)type);
            OperateIni.WriteIniData(IniSection, "minImgWidth", txtMinImgWidth.Text);
            OperateIni.WriteIniData(IniSection, "startAt", DateTime.Now);
            OperateIni.WriteIniData(IniSection, "checkTime", checkTime.Checked);
        }
コード例 #6
0
        public void SideBar()
        {
            Rectangle sideBar = new Rectangle()
            {
                Width  = 200,
                Height = 600,
            };

            // Grey sidebar background
            sideBar.Fill = new SolidColorBrush(new Color(255, 50, 50, 50));
            Canvas.SetLeft(sideBar, 600);
            Canvas.SetTop(sideBar, 0);
            Canvas.Children.Add(sideBar);
            if (!SidebarImagesLoaded)
            {
                ImgType[] sidebarTiles = new ImgType[] { ImgType.FirstAid, ImgType.Armour, ImgType.Weapon };
                for (int i = 0; i < sidebarTiles.Length; i++)
                {
                    LoadSidebarImages(sidebarTiles[i]);
                    Canvas.SetLeft(sidebarImages[sidebarTiles[i].ToString()], 610);
                    Canvas.SetTop(sidebarImages[sidebarTiles[i].ToString()], 50 + i * 50);
                }
                SidebarImagesLoaded = true;
            }
        }
コード例 #7
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         int hashCode = 41;
         if (Id != null)
         {
             hashCode = hashCode * 59 + Id.GetHashCode();
         }
         if (Name != null)
         {
             hashCode = hashCode * 59 + Name.GetHashCode();
         }
         if (Category != null)
         {
             hashCode = hashCode * 59 + Category.GetHashCode();
         }
         if (ImgBase64 != null)
         {
             hashCode = hashCode * 59 + ImgBase64.GetHashCode();
         }
         if (ImgType != null)
         {
             hashCode = hashCode * 59 + ImgType.GetHashCode();
         }
         if (Hotspots != null)
         {
             hashCode = hashCode * 59 + Hotspots.GetHashCode();
         }
         return(hashCode);
     }
 }
コード例 #8
0
 public ImgNode(string name, Rect rect, string font, int fontSize, string text, Color color) : this(rect)
 {
     this.type     = ImgType.Label;
     this.Name     = name;
     this.font     = null; /*Debug.Log(font);*/
     this.fontSize = fontSize;
     this.text     = text;
     this.color    = color;
 }
コード例 #9
0
 public LvEntity(string Name, string Link, string Description, string Id, bool Favorite, ImgType t)
 {
     this.Name        = Name;
     this.Link        = Link;
     this.Description = this.Description;
     this.Id          = Id;
     this.Favorite    = Favorite;
     this.type        = t;
 }
コード例 #10
0
        public void LoadSidebarImages(ImgType name)
        {
            Image image = new Image();

            image.Source = resources[name];
            image.Width  = 45;
            image.Height = 45;
            sidebarImages.Add(name.ToString(), image);
            Canvas.Children.Add(image);
        }
コード例 #11
0
 public void MoveImage(Character ch, ImgType type)
 {
     if (Images.ContainsKey(ch.Id))
     {
         Image image = Images[ch.Id];
         image.Source = resources[type];
         Canvas.SetLeft(image, left + ch.Position.X * PicSize);
         Canvas.SetTop(image, top + ch.Position.Y * PicSize);
     }
 }
コード例 #12
0
ファイル: ImgType.cs プロジェクト: x5942008/BigBeer.Framework
        public static string Getsuffix(ImgType type)
        {
            var suffix = ".png";

            switch (type)
            {
            case ImgType.MemoryBmp:
                suffix = ".memoryBmp";
                break;

            case ImgType.Bmp:
                suffix = ".bmp";
                break;

            case ImgType.Emf:
                suffix = ".emf";
                break;

            case ImgType.Wmf:
                suffix = ".wmf";
                break;

            case ImgType.Gif:
                suffix = ".gif";
                break;

            case ImgType.Jpeg:
                suffix = ".jpeg";
                break;

            case ImgType.Png:
                suffix = ".png";
                break;

            case ImgType.Tiff:
                suffix = ".tiff";
                break;

            case ImgType.Exif:
                suffix = ".exif";
                break;

            case ImgType.Icon:
                suffix = ".icon";
                break;

            default:
                suffix = ".png";
                break;
            }
            return(suffix);
        }
コード例 #13
0
ファイル: RuleObject.cs プロジェクト: yeonhong/unity-psd-ugui
        public string AnalySisImgName(string name, out ImgSource source, out ImgType type)
        {
            string clampName = name;

            if (name.Contains(sepraterCharimg.ToString()))
            {
                var index = name.IndexOf(sepraterCharimg);
                clampName = name.Remove(index);

                name = name.ToUpper();
                if (name.Contains((sepraterCharimg + asGoubleMark).ToUpper()))
                {
                    source = ImgSource.Globle;
                }
                else if (name.Contains((sepraterCharimg + asNoRepetMark).ToUpper()))
                {
                    source = ImgSource.Normal;
                }
                else if (name.Contains((sepraterCharimg + asCustomMark).ToUpper()))
                {
                    source = ImgSource.Custom;
                }
                else
                {
                    source = defultImgSource;
                }

                if (name.Contains((sepraterCharimg + asSingleMark).ToUpper()))
                {
                    type = ImgType.Image;
                }
                else if (name.Contains((sepraterCharimg + asTextureMark).ToUpper()))
                {
                    type = ImgType.Texture;
                }
                else if (name.Contains((sepraterCharimg + asAtalsMark).ToUpper()))
                {
                    type = ImgType.AtlasImage;
                }
                else
                {
                    type = createAtlas ? ImgType.AtlasImage : ImgType.Image;
                }
            }
            else
            {
                clampName = name;
                type      = createAtlas ? ImgType.AtlasImage : ImgType.Image;
                source    = defultImgSource;
            }
            return(clampName);
        }
コード例 #14
0
        public void DrawImage(string imageName, ImgType type, Position pos)
        {
            var image = new Image();

            if (imageName != null)
            {
                Images.Add(imageName, image);
            }
            image.Source = resources[type];
            Canvas.SetLeft(image, left + pos.X * PicSize);
            Canvas.SetTop(image, top + pos.Y * PicSize);
            Canvas.Children.Add(image);
        }
コード例 #15
0
 private BitmapImage GetBitmapImg(ImgType imgType)
 {
     Uri uri = null;
     switch (imgType)
     {
         case ImgType.Error: uri = new Uri("/Nova.SmartLCT.UI.CommonUI;component/images/MessageBox/Error.png", UriKind.RelativeOrAbsolute); break;
         case ImgType.Question: uri = new Uri("/Nova.SmartLCT.UI.CommonUI;component/images/MessageBox/Question.png", UriKind.RelativeOrAbsolute); break;
         case ImgType.Information:
         default: uri = new Uri("/Nova.SmartLCT.UI.CommonUI;component/images/MessageBox/Alert.png", UriKind.RelativeOrAbsolute); break;
     }
     BitmapImage bmpImg = new BitmapImage(uri);
     bmpImg.CacheOption = BitmapCacheOption.OnLoad;
     return bmpImg;
 }
コード例 #16
0
        public SelectImgPanel()
        {
            InitializeComponent();
            Control.CheckForIllegalCrossThreadCalls = false;
            rtxtPicList.Text = "";

            txtMinImgWidth.KeyPress += new KeyPressEventHandler(ControlEvent.NumLimit);

            //加载上一次目录信息
            txtSourcePath.Text    = OperateIni.ReadIniData(IniSection, "sourcePath");
            txtTargetPath.Text    = OperateIni.ReadIniData(IniSection, "targetPath");
            txtExcludeFloder.Text = OperateIni.ReadIniData(IniSection, "excludeFloder");
            //加载图片条件
            string strType = OperateIni.ReadIniData(IniSection, "imgType");

            if (!string.IsNullOrEmpty(strType))
            {
                ImgType type = (ImgType)Convert.ToInt32(strType);
                switch (type)
                {
                case ImgType.Horizon:
                    cmbImgType.Text = "横图";
                    break;

                case ImgType.Vertical:
                    cmbImgType.Text = "竖图";
                    break;

                default:
                    break;
                }
            }

            txtMinImgWidth.Text = OperateIni.ReadIniData(IniSection, "minImgWidth");
            string strStartAt = OperateIni.ReadIniData(IniSection, "startAt");

            if (!string.IsNullOrEmpty(strStartAt))
            {
                DateTime startAt = new DateTime();
                DateTime.TryParse(strStartAt, out startAt);
                dtpStart.Value = startAt;
            }
            string strCheckTime = OperateIni.ReadIniData(IniSection, "checkTime");

            if (!string.IsNullOrEmpty(strCheckTime))
            {
                checkTime.Checked = Convert.ToBoolean(strCheckTime);
            }
        }
コード例 #17
0
        public static string GetTheFirstImgOfOneType(IList <SerieImgURL> item, ImgType imgtype)
        {
            var list = (from x in item
                        where x.ImgType == imgtype
                        select x.ImgURL);

            //string imgUrlstring = "";
            if (list.Count() != 0)
            {
                return(list.First());
            }
            else
            {
                return("");
            }
        }
コード例 #18
0
        /// <summary>
        /// 获取合并图路径(默认jpg格式)
        /// </summary>
        /// <param name="bizType"></param>
        /// <returns></returns>
        public static string[] GetUploadPath(string bizType, string bizId)
        {
            //图片访问路径
            StringBuilder visitPath = new StringBuilder();

            //日期文件夹
            string data_path = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString("D2") + DateTime.Now.Day.ToString("D2");

            //业务类型文件夹
            if (!ImgType.exist(bizType))
            {
                bizType = ImgType.Default;
            }

            visitPath.Append("/Content/Upload/Image/").Append(bizType).Append("/").Append(bizId).Append("/").Append(data_path).Append("/");

            return(new string[] { visitPath.ToString(), System.Guid.NewGuid().ToString("N") + ".jpg" });
        }
コード例 #19
0
        public static ISaveable GetInstance(ImgType imgT)
        {
            ISaveable obj = null;

            switch (imgT)
            {
            case ImgType.PNG:
            {
                obj = new ImagePNG();
                break;
            }

            case ImgType.BMP:
            {
                obj = new ImageBMP();
                break;
            }

            case ImgType.JPEG:
            {
                obj = new ImageJPEG();
                break;
            }

            case ImgType.GIF:
            {
                obj = new ImageGIF();
                break;
            }

            case ImgType.EMF:
            {
                obj = new ImageEMF();
                break;
            }

            case ImgType.TIFF:
            {
                obj = new ImageTIFF();
                break;
            }
            }
            return(obj);
        }
コード例 #20
0
        /// <summary>
        /// 切换图片类型
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cmbImgType_SelectedIndexChanged(object sender, EventArgs e)
        {
            // 改变图片类型
            this.imgType = (ImgType)this.cmbImgType.SelectedIndex;

            // 改变表示文字
            string imgTypeName = Enum.GetName(typeof(ImgType), this.imgType);

            this.Text = "{0}图片汉化专用工具".Replace("{0}", imgTypeName);
            this.chkCheckOther.Text = "是否分析非{0}后缀的文件".Replace("{0}", imgTypeName);

            // 特殊处理Adt压缩图片类型
            if (this.imgType == ImgType.Adt)
            {
                this.chkCheckOther.Checked = false;
                this.chkCheckOther.Visible = false;
            }
            else
            {
                this.chkCheckOther.Visible = true;
            }

            // Tim格式需要显示调色板下拉框
            if (this.imgType == ImgType.Tim)
            {
                this.lblPalette.Visible    = true;
                this.cmbTimPalette.Visible = true;
            }
            else
            {
                this.lblPalette.Visible    = false;
                this.cmbTimPalette.Visible = false;
            }

            // 改变图片编辑器
            this.currentImgEditor = this.GetImgEditor();

            // 清空各种缓存
            this.lstImg.Items.Clear();
            this.ImgFiles.Clear();
            this.ImgFileNames.Clear();
            this.imgGrid.Rows.Clear();
        }
コード例 #21
0
        /// <summary>
        /// 二维码生成
        /// </summary>
        /// <param name="url">二维码网站地址或者数据</param>
        /// <param name="filename">文件名</param>
        /// <param name="savapath">保存地址</param>
        /// <param name="type">图片格式</param>
        public static void Generate(string url, string filename, string savapath, ImgType type = ImgType.Png)
        {
            QrEncoder qrEncoder = new QrEncoder();
            var       qrCode    = qrEncoder.Encode(url);
            //保存成png文件
            //string filename = @"H:\桌面\截图\url.png";
            string suffix = ImgSuffix.Getsuffix(type);; //后缀

            if (!Directory.Exists(savapath))
            {
                Directory.CreateDirectory(savapath);
            }
            filename = $"{savapath}{filename}{suffix}";
            GraphicsRenderer render = new GraphicsRenderer(new FixedModuleSize(5, QuietZoneModules.Two), Brushes.Black, Brushes.White);

            using (FileStream stream = new FileStream(filename, FileMode.Create))
            {
                render.WriteToStream(qrCode.Matrix, ImageFormat.Png, stream);
            }
        }
コード例 #22
0
        /// <summary>
        /// 获取文件访问路径
        /// 和文件名
        /// </summary>
        /// <param name="bizType"></param>
        /// <param name="bizId"></param>
        /// <param name="up_filename"></param>
        /// <returns></returns>
        public static string[] GetUploadPath(string bizType, long bizId, string up_filename)
        {
            //图片访问路径
            StringBuilder visitPath = new StringBuilder();

            //日期文件夹
            string data_path = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString("D2") + DateTime.Now.Day.ToString("D2");

            //文件扩展名
            string extension = Path.GetExtension(up_filename);

            //业务类型文件夹
            if (!ImgType.exist(bizType))
            {
                bizType = ImgType.Default;
            }

            visitPath.Append("/Upload/").Append("Image/").Append(bizType).Append("/").Append(data_path).Append("/").Append(bizId).Append("/");
            return(new string[] { visitPath.ToString(), System.Guid.NewGuid().ToString("N") + extension });
        }
コード例 #23
0
        /// <summary>
        /// 将图片分别保存到本地
        /// </summary>
        /// <param name="imgType"></param>
        /// <param name="textureArray"></param>
        /// <param name="pictureInfo"></param>
        public static void SaveToTextures(ImgType imgType, Texture2D[] textureArray, PictureExportInfo pictureInfo)
        {
            foreach (var texture in textureArray)
            {
                byte[] buf       = texture.EncodeToPNG();
                var    atlaspath = pictureInfo.exportPath + "/" + string.Format(pictureInfo.picNameTemp, texture.name);
                File.WriteAllBytes(Path.GetFullPath(atlaspath), buf);
                AssetDatabase.Refresh();

                // Get our texture that we loaded
                TextureImporter textureImporter = AssetImporter.GetAtPath(atlaspath) as TextureImporter;

                // Make sure the size is the same as our atlas then create the spritesheet
                textureImporter.maxTextureSize = pictureInfo.atlassize;

                switch (imgType)
                {
                case ImgType.Image:
                    textureImporter.textureType         = TextureImporterType.Sprite;
                    textureImporter.spriteImportMode    = SpriteImportMode.Single;
                    textureImporter.spritePivot         = new Vector2(0.5f, 0.5f);
                    textureImporter.spritePixelsPerUnit = pictureInfo.pixelsToUnitSize;
                    break;

                case ImgType.Texture:
                    textureImporter.textureType = TextureImporterType.Image;
                    break;

                default:
                    break;
                }

                AssetDatabase.ImportAsset(atlaspath, ImportAssetOptions.ForceUpdate);
            }


            foreach (Texture2D tex in textureArray)
            {
                UnityEngine.Object.DestroyImmediate(tex);
            }
        }
コード例 #24
0
ファイル: ImgTypeDal.cs プロジェクト: liuyim93/yohome
        /// <summary>
        /// 查询图片类型
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static List <ImgType> GetImgType(string sql)
        {
            List <ImgType> list = new List <ImgType>();
            DataSet        ds   = SqlHelper.GetDs(sql);

            if (ds.Tables.Count > 0)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow row in ds.Tables[0].Rows)
                    {
                        ImgType imgType = new ImgType();
                        imgType.ImgTypeId = Convert.ToInt32(row["ImgTypeId"]);
                        imgType.TypeName  = row["TypeName"].ToString();
                        imgType.Remark    = row["Remark"].ToString();
                        list.Add(imgType);
                    }
                }
            }
            return(list);
        }
コード例 #25
0
        /// <summary>
        /// Returns true if FloorplanConfigBean instances are equal
        /// </summary>
        /// <param name="input">Instance of FloorplanConfigBean to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(FloorplanConfigBean input)
        {
            if (input == null)
            {
                return(false);
            }

            return
                ((
                     Id == input.Id ||
                     (Id != null &&
                      Id.Equals(input.Id))
                     ) &&
                 (
                     Name == input.Name ||
                     (Name != null &&
                      Name.Equals(input.Name))
                 ) &&
                 (
                     Category == input.Category ||
                     (Category != null &&
                      Category.Equals(input.Category))
                 ) &&
                 (
                     ImgBase64 == input.ImgBase64 ||
                     (ImgBase64 != null &&
                      ImgBase64.Equals(input.ImgBase64))
                 ) &&
                 (
                     ImgType == input.ImgType ||
                     (ImgType != null &&
                      ImgType.Equals(input.ImgType))
                 ) &&
                 (
                     Hotspots == input.Hotspots ||
                     Hotspots != null &&
                     Hotspots.SequenceEqual(input.Hotspots)
                 ));
        }
コード例 #26
0
        /// <summary>
        /// Get the img list with the xpath 
        /// </summary>
        /// <param name="url"></param>
        /// <param name="imgtype"></param>
        /// <returns></returns>
        public List<ImgInfo> GetListByXpath(string url, ImgType imgtype)
        {
            HtmlWeb web = new HtmlWeb();
            List<ImgInfo> list = new List<ImgInfo>();
            list = web.Load(url)
                .DocumentNode
                .SelectNodes("//a[@class='photolst_photo']/img")
                .Select(p => new ImgInfo { ImgName = DoPath(p.Attributes["src"].Value), Downloadurl = p.Attributes["src"].Value })
                .ToList<ImgInfo>();
            if (imgtype == ImgType.Medium)
            {
                list.ForEach(x =>
                {
                    if (x.Downloadurl.Contains("thumb"))
                    {
                        x.Downloadurl = x.Downloadurl.Replace("thumb", "photo");
                    }
                });
            }

            return list;
        }
コード例 #27
0
ファイル: Util.cs プロジェクト: mengtest/game_sdk
    public ImgType GetTypeByBytes(byte[] bytes)
    {
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < 4; i++)
        {
            sb.Append(bytes[i].ToString("x2"));
        }
        string str = sb.ToString().ToUpper();

        ImgType type = ImgType.None;

        if (str.Equals("47494638"))
        {
            type = ImgType.GIF;
        }
        else if (str.Equals("89504E47"))
        {
            type = ImgType.PNG;
        }
        else if (str.Equals("00000200") || str.Equals("00001000"))
        {
            type = ImgType.TGA;
        }
        else if (str.StartsWith("ffd8"))
        {
            type = ImgType.JPG;
        }
        else if (str.StartsWith("424D"))
        {
            type = ImgType.BMP;
        }
        else if (str.Equals("00000100"))
        {
            type = ImgType.ICO;
        }
        return(type);
    }
コード例 #28
0
        /// </summary>
        /// 文本内容
        /// <param name="text">只支持数字 只支持偶数个 最大长度80</param>
        /// <param name="serverPth">存储路径 @"H:\桌面\截图\"</param>
        /// <param name="filename">文件名不带后缀</param>
        /// <param name="type">文件格式</param>
        /// <param name="width">宽度比例3</param>
        /// <param name="hight">高度比例1</param>
        public static void Generate2(string text, string serverPth, string filename, ImgType type, /*ImageFormat imgFrt,*/ int?width = null, int?hight = null)
        {
            BarcodeWriter writer = new BarcodeWriter();

            //使用ITF 格式,不能被现在常用的支付宝、微信扫出来
            //如果想生成可识别的可以使用 CODE_128 格式
            //writer.Format = BarcodeFormat.ITF;
            writer.Format = BarcodeFormat.CODE_128;
            int w = 150;
            int h = 50;

            if (width != null)
            {
                w = (int)width;
            }
            if (hight != null)
            {
                h = (int)hight;
            }
            EncodingOptions options = new EncodingOptions()
            {
                Width  = w,
                Height = h,
                Margin = 2
            };

            writer.Options = options;
            Bitmap map    = writer.Write(text);
            string suffix = ImgSuffix.Getsuffix(type);; //后缀

            if (!Directory.Exists(serverPth))
            {
                Directory.CreateDirectory(serverPth);
            }
            filename = $"{serverPth}{filename}{suffix}";//请注意 保存格式和文件扩展名一致性
            map.Save(filename);
        }
コード例 #29
0
        /// <summary>
        /// 生成带Logo的二维码
        /// </summary>
        /// <param name="text">文本内容</param>
        public static void Generate(string text, string LogoPth, string serverPth, string filename, ImgType type, /* ImageFormat imgFrt,*/ int?width = null, int?hight = null)
        {
            try
            {
                //Logo 图片
                Bitmap logo = new Bitmap(LogoPth);
                //构造二维码写码器
                MultiFormatWriter writer = new MultiFormatWriter();
                Dictionary <EncodeHintType, object> hint = new Dictionary <EncodeHintType, object>();
                hint.Add(EncodeHintType.CHARACTER_SET, "UTF-8");
                hint.Add(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);

                int w = 300;
                int h = 300;
                if (width != null)
                {
                    w = (int)width;
                }
                if (hight != null)
                {
                    h = (int)hight;
                }
                //生成二维码
                ZXing.Common.BitMatrix bm            = writer.encode(text, BarcodeFormat.QR_CODE, w, h, hint);
                BarcodeWriter          barcodeWriter = new BarcodeWriter();
                Bitmap map = barcodeWriter.Write(bm);


                //获取二维码实际尺寸(去掉二维码两边空白后的实际尺寸)
                int[] rectangle = bm.getEnclosingRectangle();

                //计算插入图片的大小和位置
                int middleW = Math.Min((int)(rectangle[2] / 3.5), logo.Width);
                int middleH = Math.Min((int)(rectangle[3] / 3.5), logo.Height);
                int middleL = (map.Width - middleW) / 2;
                int middleT = (map.Height - middleH) / 2;

                //将img转换成bmp格式,否则后面无法创建Graphics对象
                Bitmap bmpimg = new Bitmap(map.Width, map.Height, PixelFormat.Format32bppArgb);
                using (Graphics g = Graphics.FromImage(bmpimg))
                {
                    g.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                    g.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                    g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                    g.DrawImage(map, 0, 0);
                }
                //将二维码插入图片
                Graphics myGraphic = Graphics.FromImage(bmpimg);
                //白底
                myGraphic.FillRectangle(Brushes.White, middleL, middleT, middleW, middleH);
                myGraphic.DrawImage(logo, middleL, middleT, middleW, middleH);
                string suffix = ImgSuffix.Getsuffix(type);; //后缀
                if (!Directory.Exists(serverPth))
                {
                    Directory.CreateDirectory(serverPth);
                }
                //保存成图片
                bmpimg.Save($"{serverPth}{filename}{suffix}");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
コード例 #30
0
 public ImgNode(string name, Rect rect, Color color) : this(rect)
 {
     this.Name  = name;
     this.type  = ImgType.Color;
     this.color = color;
 }
コード例 #31
0
 //加载图片
 public static Sprite GetSprite(ImgType imgType, int id)
 {
     return(Resources.Load <GameObject>(imgType.ToString() + "/" + id).GetComponent <SpriteRenderer>().sprite);
 }
コード例 #32
0
ファイル: ExportUtility.cs プロジェクト: willhome/unity-psd
        /// <summary>
        /// 将图片分别保存到本地
        /// </summary>
        /// <param name="imgType"></param>
        /// <param name="singleNodes"></param>
        /// <param name="pictureInfo"></param>
        public static void SaveToTextures(ImgType imgType, Data.ImgNode[] singleNodes, Data.Exporter pictureInfo)
        {
            foreach (var node in singleNodes)
            {
                byte[] buf = EncordToPng(node.texture);

                var rootPath = exportPath;

                if (node.source == ImgSource.Globle)
                {
                    if (node.type == ImgType.Image || node.type == ImgType.AtlasImage)
                    {
                        rootPath = pictureInfo.ruleObj.globalSprite;
                    }
                    else
                    {
                        rootPath = pictureInfo.ruleObj.globalTexture;
                    }

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

                var atlaspath = rootPath + "/" + string.Format("{0}.png", node.texture.name);
                File.WriteAllBytes(Path.GetFullPath(atlaspath), buf);
                AssetDatabase.Refresh();

                // Get our texture that we loaded
                TextureImporter textureImporter = AssetImporter.GetAtPath(atlaspath) as TextureImporter;

                // Make sure the size is the same as our atlas then create the spritesheet
                textureImporter.maxTextureSize   = pictureInfo.ruleObj.maxSize;
                textureImporter.spritePackingTag = pictureInfo.name;
                switch (imgType)
                {
                case ImgType.Image:
                    textureImporter.textureType         = TextureImporterType.Sprite;
                    textureImporter.spriteImportMode    = SpriteImportMode.Single;
                    textureImporter.alphaIsTransparency = true;
                    textureImporter.spritePivot         = new Vector2(0.5f, 0.5f);
                    break;

                case ImgType.Texture:
                    textureImporter.textureType = TextureImporterType.Default;
                    break;

                default:
                    break;
                }
                ChargeTextureImportRule(textureImporter, exporter.ruleObj);
                AssetDatabase.ImportAsset(atlaspath, ImportAssetOptions.ForceUpdate);
            }


            foreach (Data.ImgNode node in singleNodes)
            {
                UnityEngine.Object.DestroyImmediate(node.texture);
            }
        }