Author Topic: Saving from a TImage...  (Read 1219 times)

Offline shamballa

  • Imaging User
  • *
  • Posts: 9
    • View Profile
Saving from a TImage...
« on: 5 June 2009, 04:50:13 »
Hi,

This may be a stupid question but is it possible to use a normal TImage with this library?

Basically what I am doing is converting Extended ASCII characters to a Bitmap which I then want to save in other formats but I am a little confused as to how I can do this with a normal TImage Component using this library or if this is even possible?

Please could you inform me if it is?

Many thanks

Shamballa

Offline shamballa

  • Imaging User
  • *
  • Posts: 9
    • View Profile
Re: Saving from a TImage...
« Reply #1 on: 5 June 2009, 14:09:18 »
ok I think I have found a way but not sure if it is the best way!

Code: [Select]
var
  ImgStream: TMemoryStream;
begin
  try
    ImgStream := TMemoryStream.Create;
    FImage := TMultiImage.Create;
    ASCIIImg.Picture.Graphic.SaveToStream(ImgStream);
    ImgStream.Position := 0;
    FImage.LoadMultiFromStream(ImgStream);
  finally
    ImgStream.Free;
  end;

...Then I am saving this way like in the Demo

Code: [Select]
var
  CopyPath: string;
begin
  SaveDlg.Filter := Imaging.GetImageFileFormatsFilter(False);
  SaveDlg.FileName := ChangeFileExt(ExtractFileName(FFileName), '');
  SaveDlg.FilterIndex := Imaging.GetFileNameFilterIndex(FFileName, False);
  if SaveDlg.Execute then
  begin
    CopyPath := ChangeFileExt(SaveDlg.FileName, '.' +
      Imaging.GetFilterIndexExtension(SaveDlg.FilterIndex, False));
    FImage.SaveToFile(CopyPath);
  end;

* This code "is" saving the images, but is there a better way?

Many thanks

Shamballa

Offline Galfar

  • Administrator
  • Imaging User
  • *****
  • Posts: 312
    • View Profile
    • Galfar's Homepage
Re: Saving from a TImage...
« Reply #2 on: 10 June 2009, 23:55:48 »
Sorry for late answer, so if I understand this correctly:

You have TImage on form with TBitmap assigned to Picture property and you want to save this TBitmap to image file format selected by user.

You can convert TBitmap to Imaging's image easier than in your code this way:
Code: [Select]
uses ...., ImagingComponents;
begin
  FImage := TSingleImage.Create;
  ConvertBitmapToImage(ASCIIImg.Picture.Bitmap, FImage);
  ....
  FImage.SaveToFile(CopyPath);
  ...
end;


Offline shamballa

  • Imaging User
  • *
  • Posts: 9
    • View Profile
Re: Saving from a TImage...
« Reply #3 on: 11 June 2009, 18:20:55 »
Hi,

Thank you very much, it works very well and is shorter code!

shamballa