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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 PSD Resolution and dimensions

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
fabiotesla Posted - Jul 27 2015 : 04:19:45
Hi,
I have a question about .PSD file:
I want to know how to read the actual size (resolution, width and height) for example in mm.
Thank You
2   L A T E S T    R E P L I E S    (Newest First)
fabiotesla Posted - Jul 29 2015 : 12:55:47
Very good!
Thank you very much!
Fabio
w2m Posted - Jul 28 2015 : 09:59:26
You did not specify if you want to load the separated layers of a PSD file or the entire image. This code will do both. See the note in the comments to not load layers.

procedure TForm1.Open1Click(Sender: TObject);
{ Open the psd image with layers.  See note to not load layers }
var
  i: Integer;
  iFrames: Integer;
  iPixelsPerInch: Integer;
  iMMWidth: double;
  iMMHeight: double;
begin
  OpenPictureDialog1.DefaultExt := 'psd';
  OpenPictureDialog1.Filename := ExtractFileName(AFilename);
  if OpenPictureDialog1.Execute then
  begin
    if FileExists(OpenPictureDialog1.Filename) then
    begin
      Screen.Cursor := crHourglass;
      try
        { Clear }
        ImageEnMView1.Clear;
        ImageEnMView1.Update;
        ImageEnView1.ClearAll;
        ImageEnView1.Update;
        { Get the filename }
        AFilename := OpenPictureDialog1.Filename;
        ImageEnView1.IO.ParamsFromFile(AFilename);
        ImageEnView1.IO.Params.PSD_LoadLayers :=
          ImageEnView1.IO.Params.FileType = ioPSD;
        { Change PSD_LoadLayers to False to load the base image without layers }
        // ImageEnView1.IO.Params.PSD_LoadLayers := False;
        { The screens pixelsperinch with small fonts is usually 96 }
        iPixelsPerInch := PixelsPerInch;
        if ImageEnView1.IO.Params.FileType = ioPSD then
        begin
          ImageEnView1.IO.LoadFromFilePSD(AFilename);
          if ImageEnView1.IO.Params.PSD_LoadLayers then
          begin
            for i := 0 to ImageEnView1.LayersCount - 1 do
            begin
              { Append the image }
              ImageEnMView1.AppendImage(ImageEnView1.Layers[i].Bitmap);
              { mm = (pixels * 25.4) / dpi }
              iMMWidth := (ImageEnView1.Layers[i].Bitmap.Width * 25.4) /
                iPixelsPerInch;
              iMMHeight := (ImageEnView1.Layers[i].Bitmap.Height * 25.4) /
                iPixelsPerInch;
              { Set the bottom text }
              ImageEnMView1.ImageBottomText[i] := IntToStr(Round(iMMWidth)) +
                ' mm. x ' + IntToStr(Round(iMMHeight)) + ' mm.';
            end;
          end
          else
          begin
            { Append the image from a file }
            ImageEnMView1.AppendImage(AFilename, True, iedtNone,
              iedtNone, iedtNone);
            { mm = (pixels * 25.4) / dpi }
            iMMWidth := (ImageEnView1.Layers[i].Bitmap.Width * 25.4) /
              iPixelsPerInch;
            iMMHeight := (ImageEnView1.Layers[i].Bitmap.Height * 25.4) /
              iPixelsPerInch;
            { Set the bottom text }
            ImageEnMView1.ImageBottomText[i] := IntToStr(Round(iMMWidth)) +
              ' mm. x ' + IntToStr(Round(iMMHeight)) + ' mm.'
          end;
          { Select the first frame }
          ImageEnMView1.SelectedImage := 0;
          { Set the ImageEnView imageindex to the first frame }
          ImageEnView1.IO.Params.ImageIndex := 0;
          if Fit1.Checked then
            ImageEnView1.Fit;
          ImageEnView1.MouseInteract := [miMoveLayers];
          UpdateStatusbar;
        end;
      finally
        Screen.Cursor := crDefault;
      end;
    end;
  end;
end;

procedure TForm1.UpdateStatusbar;
{ Show image information in the statusbar. }
var
  iPixelsPerInch: Integer;
  iMMWidth: double;
  iMMHeight: double;
begin
  Caption := 'MultiFrame PSD, TIF, GIF and ICO Images- ' + AFilename;
  StatusBar1.Panels[0].Text := EllipsifyText(True, ExtractFileDir(AFilename),
    Canvas, StatusBar1.Panels[0].Width - 10);
  StatusBar1.Panels[1].Text := EllipsifyText(False, ExtractFileName(AFilename),
    Canvas, StatusBar1.Panels[1].Width - 10);
  StatusBar1.Panels[2].Text := 'Frame: ' +
    IntToStr(ImageEnMView1.SelectedImage + 1);
  StatusBar1.Panels[3].Text := 'Frames: ' + IntToStr(ImageEnMView1.ImageCount);
  if ImageEnView1.IO.Params.FileType = ioICO then
  begin
    if ImageEnView1.IO.Params.BitsPerSample *
      ImageEnView1.IO.Params.SamplesPerPixel = 32 then
      StatusBar1.Panels[4].Text := 'Colors: RGBA32-Bit'
    else
      StatusBar1.Panels[4].Text := 'Colors: RGB' +
        IntToStr(ImageEnView1.IO.Params.BitsPerSample *
        ImageEnView1.IO.Params.SamplesPerPixel) + '-Bit';
  end
  else if ImageEnView1.IO.Params.FileType = ioGIF then
  begin
    if ImageEnView1.IO.Params.BitsPerSample *
      ImageEnView1.IO.Params.SamplesPerPixel = 32 then
      StatusBar1.Panels[4].Text := 'Colors: RGBA32-Bit'
    else if ImageEnView1.IO.Params.GIF_FlagTranspColor then
      StatusBar1.Panels[4].Text := 'Colors: RGB' +
        IntToStr(ImageEnView1.IO.Params.BitsPerSample *
        ImageEnView1.IO.Params.SamplesPerPixel) + '-Bit (Transparent)'
    else
      StatusBar1.Panels[4].Text := 'Colors: RGB' +
        IntToStr(ImageEnView1.IO.Params.BitsPerSample *
        ImageEnView1.IO.Params.SamplesPerPixel) + '-Bit';
  end
  else if ImageEnView1.IO.Params.FileType = ioICO then
  begin
    if ImageEnView1.IO.Params.BitsPerSample *
      ImageEnView1.IO.Params.SamplesPerPixel = 32 then
      StatusBar1.Panels[4].Text := 'Colors: RGBA32-Bit'
    else
      StatusBar1.Panels[4].Text := 'Colors: RGB' +
        IntToStr(ImageEnView1.IO.Params.BitsPerSample *
        ImageEnView1.IO.Params.SamplesPerPixel) + '-Bit';
  end
  else
  begin
    if ImageEnView1.IO.Params.BitsPerSample *
      ImageEnView1.IO.Params.SamplesPerPixel = 32 then
      StatusBar1.Panels[4].Text := 'Colors: RGBA-32Bit'
    else
      StatusBar1.Panels[4].Text := 'Colors: RGB-' +
        IntToStr(ImageEnView1.IO.Params.BitsPerSample *
        ImageEnView1.IO.Params.SamplesPerPixel) + 'Bit';
  end;
  iPixelsPerInch := PixelsPerInch;
  { mm = (pixels * 25.4) / dpi }
  iMMWidth := (ImageEnView1.Layers[ImageEnView1.LayersCurrent].Bitmap.Width *
    25.4) / iPixelsPerInch;
  iMMHeight := (ImageEnView1.Layers[ImageEnView1.LayersCurrent].Bitmap.Height *
    25.4) / iPixelsPerInch;
  StatusBar1.Panels[5].Text := 'Width: ' +
    IntegerToString(ImageEnView1.Layers[ImageEnView1.LayersCurrent]
    .Bitmap.Width) + ' pixels (' + IntToStr(Round(iMMWidth)) + ' mm.)';
  StatusBar1.Panels[6].Text := 'Height: ' +
    IntegerToString(ImageEnView1.Layers[ImageEnView1.LayersCurrent]
    .Bitmap.Height) + ' pixels (' + IntToStr(Round(iMMHeight)) + ' mm.)';
end;


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