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
 Chromakey saving to jpg
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

bruce seymour

USA
3 Posts

Posted - Feb 22 2016 :  15:35:37  Show Profile  Reply
Just starting out with you product.

Using your chromakey demo I have successfully created an image with a background and a transparent foreground with jpg files. I now want to save it as a jpg. I have tried variations of

ImageEnView1.LayersMergeAll;
ImageEnView1.IO.SaveToFileJpeg('C:\output.jpg);

and

ImageEnView1.LayersSaveMergedTo('C:\output.jpg);

The images merger and save but the transparency is lost.

How do I preserver transparency and save to a jpg file?


Bruce

wesleybobato

Brazil
367 Posts

Posted - Feb 22 2016 :  15:39:44  Show Profile  Reply
Hi Bruce
Use this method Work OK.

var
 aBitmap: TIEBitmap;
begin
 aBitmap := TIEBitmap.Create;
  try
   aBitmap.Allocate( ImageEnView1.Width, ImageEnView1.Height );
   ImageEnView1.LayersDrawTo( aBitmap );
   aBitmap.Write( sFilename );
  finally
   FreeAndNil( aBitmap );
  end;
end;
Go to Top of Page

xequte

38611 Posts

Posted - Feb 22 2016 :  16:31:13  Show Profile  Reply
Hi Bruce

JPEG format does not support transparency.

Can you post your before and after images to show us what you mean?

Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

bruce seymour

USA
3 Posts

Posted - Feb 22 2016 :  17:16:46  Show Profile  Reply
Chromakey save works great as long as I run it from a button.

If I call your save routine from my routine that does the chromakey build it loses the transparency, same as before. I tried a sleep(4000) and ImageEnView1.Refresh before calling the save but no luck. If I put a showmessage('xyx'); to make it pause before calling the save routine it works.

What command do I use to prepare the ImageEnView1 before calling your save routine?

Bruce
Go to Top of Page

bruce seymour

USA
3 Posts

Posted - Feb 22 2016 :  17:56:59  Show Profile  Reply
below procedures works but notice comment - if I remote showmessage it stops working.

I'm looping through a filelist and applying chromekey to all files in the filelist.



procedure TFormChromaKey.FileListBoxGreenDoneChromeClick(Sender: TObject);
var
    BackGroundFileName, ForeGroundFileName : String;
    Tolerance: Double;
begin
    ForeGroundFileName := FileListBoxGreenDoneChrome.Directory + '\' + FileListBoxGreenDoneChrome.Items[FileListBoxGreenDoneChrome.ItemIndex];
    ImageEnViewForeground.IO.LoadFromFileJpeg(ForeGroundFileName);
    If DM1.dbTableReceivedEmail.FindKey([JustFileNameS(ForeGroundFileName)]) then begin
       BackGroundFileName := cfGSImageFolder + '\'
                            + DM1.dbTableReceivedEmail.FieldByName('PackageCode').AsString + '\'
                            + JustFileNameS(DM1.dbTableReceivedEmail.FieldByName('BackGroundFileName').AsString);
       If FileExists(BackGroundFileName) then begin
          ImageEnViewBackGround.IO.LoadFromFileJpeg(BackGroundFileName);
          ImageEnView1.LayersCurrent := 0;
          ImageEnView1.IO.LoadFromFile(BackGroundFileName);
          ImageEnView1.LayersCurrent := 1;
          fForegroundSrc.Read(ForeGroundFileName);
          if fForegroundSrc.Width > 1024 then fForegroundSrc.Resample( 1024, -1 );
          ImageEnView1.Deselect;
          ImageEnView1.Layers[ 1 ].Bitmap.Assign( fForegroundSrc );
          ImageEnView1.Deselect;
          ImageEnView1.Layers[ 1 ].Bitmap.Assign( fForegroundSrc );
          KeyColor := ImageEnView1.Proc.GuessChromaKeyColor( Tolerance );
          DelayedApplyChromaKey();


  // It works with below showmessage  // i tryed placing pauses in here but didn't work
          Showmessage('xyz');

  // If I remove showmessage it saves but the foreground loses it's transparency

          SaveTransParentLayers('C:\GoodEyeOw\ALL-GREEN\Done\' + JustFileNameS(ForeGroundFileName));
          end;
       end;
end;

// routine you sent
procedure TFormChromaKey.SaveTransParentLayers(SFileName: String);
var
   aBitmap: TIEBitmap;
begin
   aBitmap := TIEBitmap.Create;
   try
    aBitmap.Allocate( ImageEnView1.Width, ImageEnView1.Height );
    ImageEnView1.LayersDrawTo( aBitmap );
    aBitmap.Write(sFileName);
    finally
    FreeAndNil( aBitmap );
    end;
end;

/////////////////////////////////////////////////////
This button DOESN'T WORK

procedure TFormChromaKey.Button2Click(Sender: TObject);
begin
    FileListBoxGreenDoneChromeClick(Sender);  // will 
    SaveTransParentLayers('c:\testimage.jpg');
end;

///////////////////////////////////////////////////
This button WORKS if I run FileListBoxGreenDoneChromeClick(Sender);  first without showmessage;

procedure TFormChromaKey.Button2Click(Sender: TObject);
begin
    SaveTransParentLayers('c:\testimage.jpg');
end;

Go to Top of Page

xequte

38611 Posts

Posted - Feb 28 2016 :  21:02:56  Show Profile  Reply
Hi

I can see no reason the ShowMessage() would make any difference, though you could try calling ImageEnView1.Update() (as I can't see if your code does that).

Failing that, please email me a very simple demo showing the issue.


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: