コード例 #1
0
ファイル: EmotionForm.cs プロジェクト: zhangx3000/GFF
 private void DeleteItem_Click(object sender, EventArgs e)
 {
     this.IsShowDialog = true;
     try
     {
         if (MessageBox.Show(this, "请您确认删除?", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) ==
             DialogResult.OK)
         {
             ImageEntity img = this.Images.Find(item => item.MD5 == this.DrawImages[this.imageIndex].MD5);
             if (img != null)
             {
                 img.IsDelete = true;
             }
             var dels = this.Images.FindAll(item => item.IsDelete);
             if (dels != null && dels.Count > 0)
             {
                 foreach (var item in dels)
                 {
                     try
                     {
                         File.Delete(item.FullName);
                     }
                     catch { }
                 }
             }
             this.DrawImages.Clear();
             this.DrawImages = this.Images.FindAll(item => !item.IsDelete);
             this.UpdatePageCount();
             this.DrawBackImage();
             this.Invalidate();
             this.RaiseOnChanged();
         }
     }
     catch (Exception ex)
     {
         Trace.WriteLine(ex);
     }
     finally
     {
         this.IsShowDialog = false;
     }
 }
コード例 #2
0
ファイル: EmotionForm.cs プロジェクト: zhangx3000/GFF
 public SelectFaceArgs(ImageEntity img, int ImageIndex)
     : this(img)
 {
     this.ImageIndex = ImageIndex;
 }
コード例 #3
0
ファイル: EmotionForm.cs プロジェクト: zhangx3000/GFF
 public SelectFaceArgs(ImageEntity img)
     : this()
 {
     this.Img = img;
 }
コード例 #4
0
ファイル: EmotionForm.cs プロジェクト: zhangx3000/GFF
        /// <summary>
        /// 添加自定义表情
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddItem_Click(object sender, EventArgs e)
        {
            try
            {
                this.Demo.Visible = false;
                this.IsShowDialog = true;
                int            count = 0;
                int            err   = 0;
                OpenFileDialog dlg   = new OpenFileDialog
                {
                    Filter = ("图像文件 (*.jpg;*.png;*.gif;*.bmp)|*.jpg;*.jpeg;*.png;*.gif;*.bmp|" +
                              "JPEG 文件 (*.jpg;*.jpeg)|*.jpg;*.jpeg|" +
                              "PNG 文件 (*.png)|*.png|" +
                              "GIF 文件 (*.gif)|*.gif|" +
                              "位图文件 (*.bmp)|*.bmp|" +
                              "所有文件 (*.*)|*.*"),
                    FilterIndex      = 0,
                    Title            = "选择头像",
                    RestoreDirectory = true,
                    Multiselect      = true
                };

                string tmpImgMD5 = "";
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    foreach (string file in dlg.FileNames)
                    {
                        if (File.Exists(file))
                        {
                            try
                            {
                                string shortname = string.Format(this.CustomImagePath + "{0}{1}", DateTime.Now.Ticks,
                                                                 Path.GetExtension(file));
                                string fullname = Path.Combine(Application.StartupPath, shortname);

                                try
                                {
                                    Image.FromStream(new MemoryStream(File.ReadAllBytes(file)));
                                }
                                catch
                                {
                                    err++;
                                    break;
                                }

                                FileHelper.CreateDir(Path.GetDirectoryName(fullname));

                                if (!Path.GetDirectoryName(file).Equals(Path.GetDirectoryName(fullname)))
                                {
                                    tmpImgMD5 = EncryptionHelper.MD5Helper.GetFileMd5(file);

                                    if (this.DrawImages.Exists(item => item.MD5.ToLower() == tmpImgMD5.ToLower()))
                                    {
                                        count++;
                                        break;
                                    }
                                    File.Copy(file, fullname, true);
                                }

                                ImageEntity img = new ImageEntity(fullname)
                                {
                                    IsCustom = true
                                };

                                if (!this.Images.Exists(item => item.MD5.ToLower() == img.MD5.ToLower()))
                                {
                                    this.Images.Add(img);
                                }
                                else
                                {
                                    ImageEntity tmp = this.Images.Find(item => item.MD5.ToLower() == img.MD5.ToLower());
                                    if (tmp != null)
                                    {
                                        tmp.IsDelete = false;
                                    }
                                }

                                this.DrawImages.Clear();

                                this.DrawImages = this.Images.FindAll(item => !item.IsDelete);
                            }
                            catch
                            {
                            }
                        }
                    }
                    if (dlg.FileNames.Length > 1)
                    {
                        this.DrawBackImage();
                        this.Invalidate();
                        MessageBox.Show(this,
                                        string.Format("共选择{0}个表情,{1}个表情己存在,成功添加{2}个表情,添加失败{3}个表情!", dlg.FileNames.Length,
                                                      count, dlg.FileNames.Length - count - err, err), "提示信息",
                                        MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        if (count > 0)
                        {
                            MessageBox.Show(this, "表情已存在,请重新选择!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        if (err > 0)
                        {
                            MessageBox.Show(this, "表情添加失败,请重新选择!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return;
                        }
                        this.DrawBackImage();
                        this.Invalidate();
                        MessageBox.Show(this, "表情添加成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    try
                    {
                        FileHelper.SerializeFile(Path.Combine(Application.StartupPath, this.ImagePath + "Images.db"), this.Images);
                    }
                    catch (Exception ex)
                    {
                        Trace.WriteLine(ex);
                    }
                    this.UpdatePageCount();
                    this.RaiseOnChanged();
                }
            }
            catch { }
            finally
            {
                this.IsShowDialog = false;
            }
        }
コード例 #5
0
ファイル: EmotionForm.cs プロジェクト: zhangx3000/GFF
        public bool Init(int imageWidth, int imageHeight, int nHSpace, int nVSpace, int nColumns, int nRows)
        {
            imagedbPath = Path.Combine(Application.StartupPath, this.ImagePath + "Images.db");

            if (this.DesignMode)
            {
                return(false);
            }

            try
            {
                ImageEntity img;
                this.Images.Clear();
                this.DrawImages.Clear();
                try
                {
                    if (!File.Exists(imagedbPath))
                    {
                        List <string> listFace = new List <string>(Directory.GetFiles(Path.Combine(Application.StartupPath, this.ImagePath)));
                        listFace.Sort(new Comparison <string>(GlobalResourceManager.CompareEmotionName));
                        foreach (string imgPath in listFace)
                        {
                            img = new ImageEntity(imgPath);

                            if (img.Image != null)
                            {
                                this.Images.Add(img);
                            }
                        }
                        try
                        {
                            FileHelper.SerializeFile(imagedbPath, this.Images);
                        }
                        catch (Exception ex)
                        {
                            Trace.WriteLine(ex);
                        }
                    }
                    else
                    {
                        this.Images = FileHelper.DeserializeFile <List <ImageEntity> >(imagedbPath);
                        try
                        {
                            foreach (var item in this.Images)
                            {
                                if (!File.Exists(item.FullName))
                                {
                                    item.IsDelete = true;
                                }
                            }
                        }
                        catch { }

                        foreach (var imgItem in this.Images.FindAll(item => item.IsDelete))
                        {
                            try
                            {
                                File.Delete(imgItem.FullName);
                            }
                            catch
                            {
                            }
                        }
                    }
                }
                catch
                {
                    this.Images = new List <ImageEntity>();
                }

                this.DrawImages = this.Images.FindAll(item => !item.IsDelete);

                this.Images = this.DrawImages.FindAll(item => !item.IsDelete);

                this.Demo.Width = imageWidth * 3 - 10;

                this.Demo.Height = imageHeight * 3 - 10;

                this._nColumns = nColumns;
                this._nRows    = nRows;
                this._nHSpace  = nHSpace;
                this._nVSpace  = nVSpace;

                this._imageWidth  = imageWidth;
                this._imageHeight = imageHeight;
                this._nItemWidth  = imageWidth + nHSpace;
                this._nItemHeight = imageHeight + nVSpace;

                this._nBitmapWidth  = this._nColumns * this._nItemWidth + 1;
                this._nBitmapHeight = this._nRows * this._nItemHeight + 1;
                this.Width          = this._nBitmapWidth;
                this.Height         = this._nBitmapHeight + 20;

                using (Graphics g = this.CreateGraphics())
                {
                    this.PageIndex      = 0;
                    this.PageImageCount = this._nColumns * this._nRows;

                    this.UpdatePageCount();

                    this.ClientRect = new Rectangle(0, 0, this.Width - 1, this.Height - 1);

                    this.FaceRect = new RectangleF(0f, 0f, this._nBitmapWidth, this._nBitmapHeight);

                    this.Rect = new RectangleF(1f, 1f, this._nBitmapWidth - 2, this._nBitmapHeight - 2);

                    SizeF s = g.MeasureString("上一页", this.Font);
                    SizeF i = g.MeasureString(string.Format("{0}/{1}", this.PageCount, this.PageCount), this.Font);
                    SizeF z = g.MeasureString("单击右键进行管理!", this.Font);

                    this.PageInfoRect = new RectangleF(new PointF(this.ClientRect.Width - s.Width * 2 - i.Width - 20, this.FaceRect.Height + 3), i);

                    this.PageDownRect = new RectangleF(new PointF(this.ClientRect.Width - s.Width - 10, this.FaceRect.Height + 3), s);

                    this.PageUpRect = new RectangleF(new PointF(this.ClientRect.Width - s.Width * 2 - 10, this.FaceRect.Height + 3), s);

                    this.MemoRect = new RectangleF(new PointF(6, this.FaceRect.Height + 3), z);

                    this.HoveColor = Color.Blue;

                    this.DrawBackImage();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(false);
            }
            return(true);
        }