Exemple #1
0
        //将文件转换为bmp 256色
        void convertBitmap(String fileName, String outFile)
        {
            Bitmap bitmap       = new Bitmap(fileName);
            String outName      = Path.GetFileNameWithoutExtension(fileName);
            Bitmap bitmapResult = bitmap.Clone(new Rectangle(0, 0, bitmap.Width, bitmap.Height), PixelFormat.Format8bppIndexed);
            String outFileName  = Path.Combine(SVProData.IconPath, outFile);

            ///如果已经存在,不执行该文件的导入
            if (_pixmapManage.isItemExist(outName))
            {
                SVLog.WinLog.Warning(String.Format("图元名称{0} 已经存在, 导入失败!", outName));
                return;
            }

            MemoryStream outStream = new MemoryStream();

            bitmapResult.Save(outStream, ImageFormat.Bmp);

            //保存文件
            SVPixmapFile pixFile = new SVPixmapFile();

            pixFile.ShowName = outName;
            pixFile.Pixmap   = outStream;

            imageList.Images.Add(outName, pixFile.getBitmapFromData());
            imageList1.Images.Add(outName, pixFile.getBitmapFromData());

            pixFile.writePixmapFile(outFileName);

            if (this.listRadio.Checked)
            {
                listView.View           = View.Details;
                listView.SmallImageList = imageList;
                listView.LargeImageList = imageList1;
            }
            else
            {
                listView.View           = View.LargeIcon;
                listView.SmallImageList = imageList1;
                listView.LargeImageList = imageList1;
            }

            ListViewItem viewItem = listView.Items.Add(outName);

            viewItem.ImageKey = outName;

            _pixmapManage.insertItemByClass(treeView.SelectedNode.Text, outName, outFile);
            saveIconInfo();
        }
Exemple #2
0
        /// <summary>
        /// 添加图元到当前窗口中
        /// </summary>
        /// <param oldName="sender"></param>
        /// <param oldName="e"></param>
        private void importIcon_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Multiselect = true;
            openFileDialog.Filter      = "(JPG)|*.jpg|(BMP)|*.bmp|(PNG)|*.png";

            String nowTimeString = DateTime.Now.ToFileTime().ToString();

            BindingList <Node> nodeList = this.piclistView.ItemsSource as BindingList <Node>;

            ///弹出图片选择窗口
            if (openFileDialog.ShowDialog() == true)
            {
                Int32 index = 1;
                foreach (var fileName in openFileDialog.FileNames)
                {
                    ///根据路径获取名称
                    String itemName = Path.GetFileNameWithoutExtension(fileName);
                    ///如果已经存在,不执行该文件的导入
                    if (_picManager.isItemExist(itemName))
                    {
                        SVLog.WinLog.Warning(String.Format("图元名称 {0} 已经存在, 导入失败!", itemName));
                        continue;
                    }

                    ///保存图片
                    convertBitmap(fileName, nowTimeString + index.ToString());
                    index++;

                    ///界面显示
                    Node node = createNodeFromName(itemName);
                    nodeList.Add(node);
                }

                ///保存图标信息到配置文件中
                saveIconInfo();
            }
        }