示例#1
0
        private void button2_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Title  = "请选择图像文件";
            openFileDialog.Filter = "(*.jpg;*.png;*.bmp;*.jpeg;*.gif;*.tiff;*.ico)|*.jpg;*.png;*.bmp;*.jpeg;*.gif;*.tiff;*.ico";
            DialogResult dialogResult = openFileDialog.ShowDialog();

            if (!dialogResult.ToString().Equals("Cancel"))
            {
                try
                {
                    pApplication.Open(Path.GetFullPath(openFileDialog.FileName));
                }
                catch (Exception err)
                {
                    MessageBox.Show(this, err.Message, "运行出现异常", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
            }
        }
示例#2
0
        static private void UpdatePsd(FileInfo fileInfo, Dictionary <string, Color> convertMap, string saveFolder)
        {
            Console.Out.WriteLine("Start Convert " + fileInfo.FullName);

            Photoshop.Document  psdDocument = PhotoshopApplication.Open(fileInfo.FullName);
            Photoshop.ArtLayers layers      = psdDocument.ArtLayers;
            for (int index = 0; index < layers.Count; ++index)
            {
                try
                {
                    Photoshop.ArtLayer layer = layers[index + 1];
                    var layName = layer.Name.ToUpper();
                    var findKey = convertMap.Single(x => layName.Contains(x.Key));
                    var color   = findKey.Value;

                    switch (layer.LayerType)
                    {
                    case Photoshop.PsLayerType.psArtLayer:
                    {
                        switch (layer.Kind)
                        {
                        case Photoshop.PsLayerKind.psSolidFillLayer:
                        {
                            PhotoshopApplication.ActiveDocument.ActiveLayer = layer;
                            UpdateSolidFillColor(color);
                        }
                        break;

                        case Photoshop.PsLayerKind.psTextLayer:
                        {
                            PhotoshopApplication.ActiveDocument.ActiveLayer = layer;
                            Photoshop.TextItem text = layer.TextItem;
                            text.Color.RGB.HexValue = color.R.ToString("X2").ToLower() + color.G.ToString("X2").ToLower() + color.B.ToString("X2").ToLower();
                            break;
                        }

                        default:
                        {
                            ConsoleColor oldColor = Console.ForegroundColor;
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.Out.WriteLine("Convert Error : Layer Name - " + layName + "   LayerKind - " + layer.Kind);
                            Console.ForegroundColor = oldColor;
                            break;
                        }
                        }
                    }
                    break;

                    default:
                    {
                        throw new Exception();
                    }
                    }
                }
                catch
                {
                }
            }

            psdDocument.SaveAs(saveFolder + "\\" + fileInfo.Name);
            psdDocument.Close();
            Console.Out.WriteLine("Convert Finished, Save to " + saveFolder + "\\" + fileInfo.Name);
        }