Exemplo n.º 1
0
        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;
                    }

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

                    try {
                        Tools.BinarySerializer(this.Images, Path.Combine(Application.StartupPath, this.ImagePath + "Images.db"));
                    } catch (Exception ex) {
                        Trace.WriteLine(ex);
                    }

                    this.UpdatePageCount();
                    this.DrawBackImage();
                    this.Invalidate();
                }
            } catch (Exception ex) {
                Trace.WriteLine(ex);
            } finally {
                this.IsShowDialog = false;
            }
        }
Exemplo n.º 2
0
 public SelectFaceArgs(ImageEntity img, int ImageIndex)
     : this(img) {
     this.ImageIndex = ImageIndex;
 }
Exemplo n.º 3
0
 public SelectFaceArgs(ImageEntity img)
     : this()
 {
     this.Img = img;
 }
Exemplo n.º 4
0
        private bool CustomHead()
        {
            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}", Guid.NewGuid(),
                                                                 Path.GetExtension(file));
                                string fullname = Path.Combine(Application.StartupPath, shortname);

                                try {
                                    Image.FromFile(file);
                                } catch {
                                    err++;
                                    break;
                                }

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

                                if (!Path.GetDirectoryName(file).Equals(Path.GetDirectoryName(fullname)))
                                {
                                    tmpImgMD5 = SecurityHelper.GetMD5(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(false);
                        }
                        if (err > 0)
                        {
                            MessageBox.Show(this, "表情添加失败,请重新选择!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return(false);
                        }
                        this.DrawBackImage();
                        this.Invalidate();
                        MessageBox.Show(this, "表情添加成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    try {
                        Tools.BinarySerializer(this.Images, Path.Combine(Application.StartupPath, this.ImagePath + "Images.db"));
                    } catch (Exception ex) {
                        Trace.WriteLine(ex);
                    }
                    this.UpdatePageCount();

                    return(true);
                }
            } catch { } finally {
                this.IsShowDialog = false;
            }

            return(false);
        }
Exemplo n.º 5
0
        public bool Init(int imageWidth, int imageHeight, int nHSpace, int nVSpace, int nColumns, int nRows)
        {
            if (this.DesignMode)
            {
                return(false);
            }

            try {
                ImageEntity img;
                this.Images.Clear();
                this.DrawImages.Clear();

                try {
                    if (!File.Exists(Path.Combine(Application.StartupPath, this.ImagePath + "Images.db")))
                    {
                        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 {
                            Tools.BinarySerializer(this.Images, Path.Combine(Application.StartupPath, this.ImagePath + "Images.db"));
                        } catch (Exception ex) {
                            Trace.WriteLine(ex);
                        }
                    }
                    else
                    {
                        this.Images = Tools.BinaryDeserialize <List <ImageEntity> >(Path.Combine(Application.StartupPath, this.ImagePath + "Images.db"));
                        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;

                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);
        }