ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 not visually edit mode
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

giancarlo

Italy
65 Posts

Posted - Feb 28 2017 :  16:44:37  Show Profile  Reply
there is a way to open a psd, add a layer then save it but not visually?

thank you

w2m

USA
1990 Posts

Posted - Mar 01 2017 :  13:05:08  Show Profile  Reply
In order to be able to add a layer to a psd file it is necessary to use a TImageEnView component. To accommodate not using a visible component, create and use a TImageEnView at run time and then free the component. When you create a TImageEnView at runtime set the parent to nil so it is not visible:
uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.ComCtrls, System.Contnrs,
  hyieutils, iexBitmaps, hyiedefs, iesettings, iexRulers, imageenview, imageenio, ieopensavedlg, ieview;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    AddLayerAndSave1: TButton;
    OpenImageEnDialog1: TOpenImageEnDialog;
    SaveImageEnDialog1: TSaveImageEnDialog;
    Open1: TButton;
    ImageEnView1: TImageEnView;
    StatusBar1: TStatusBar;
    procedure AddLayerAndSave1Click(Sender: TObject);
    procedure Open1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

procedure TForm1.AddLayerAndSave1Click(Sender: TObject);
var
  iFilename: string;
  iExtension: string;
  iFileType: TIOFileType;
  iImageEnView: TImageEnView;
  iLayer: integer;
begin
  iFilename := 'G:\Images\PSD\Beach.psd';
  OpenImageEnDialog1.InitialDir := 'G:\Images\PSD';
  if OpenImageEnDialog1.Execute then
  begin
    if FileExists(OpenImageEnDialog1.FileName) then
    begin
      iFilename := OpenImageEnDialog1.FileName;
      iExtension := ExtractFileExt(iFilename);
    end;
    if IsKnownFormat(iFilename) then
    begin
      iFileType := IEExtToFileFormat(iExtension);
      if iFileType = ioPSD then
      begin
        iImageEnView := TImageEnView.Create(nil);
        try
          iImageEnView.IO.Params.PSD_LoadLayers := True;
          iImageEnView.IO.Params.PSD_ReplaceLayers := True;
          iImageEnView.IO.LoadFromFilePSD(iFilename);
          iImageEnView.Update;
          MessageBox(0, PChar('The loaded image has ' + IntToStr(iImageEnView.LayersCount) + ' layers.'), 'Layer Count',
            MB_ICONINFORMATION or MB_OK);
          if (MessageBox(0, 'Add a layer to the PSD file?', 'Add a layer?', MB_ICONQUESTION or MB_YESNO) = mrYes) then
          begin
            iLayer := iImageEnView.LayersAdd;
            iImageEnView.Layers[iLayer].PosX := 0;
            iImageEnView.Layers[iLayer].PosY := 0;
            if (MessageBox(0, 'Save PSD file?', 'Save', MB_ICONQUESTION or MB_YESNO) = mrYes) then
            begin
              if SaveImageEnDialog1.Execute then
              begin
                iFilename := SaveImageEnDialog1.FileName;
                iImageEnView.IO.SaveToFilePSD(iFilename);
                if iImageEnView.IO.Aborting then
                begin
                  MessageBox(0, 'There was an error saveing image.', 'Error', MB_ICONWARNING or MB_OK);
                  exit;
                end;
                MessageBox(0, PChar('The saved image has ' + IntToStr(iImageEnView.LayersCount) + ' layers.'), 'Layer Count',
                  MB_ICONINFORMATION or MB_OK);
              end;
            end;
          end;
        finally
          iImageEnView.Free;
        end;
      end;
    end;
  end;

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
Go to Top of Page

giancarlo

Italy
65 Posts

Posted - Mar 02 2017 :  08:07:29  Show Profile  Reply
thank you
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: