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
 Updating images non-visually
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

RichardLight

United Kingdom
3 Posts

Posted - Feb 08 2013 :  11:23:07  Show Profile  Reply
Hi,

Simple HTTP CGI application: I want to update an image's metadata using ImageEn, and then serve it as an HTTP response. The basic approach, of loading an image file into ImageEnIO and then delivering it as the ContentStream of the HTTP response, is working fine. However, any changes I make to the Params of my ImageEnIO have no effect. Shouldn't this "just work"? :-

{create the bitmap and load the file:}
IEBitmap1 := TIEBitmap.Create;
ImageEnIO1 := TImageEnIO.Create(Self);
ImgStream := TMemoryStream.Create;
OutStream := TMemoryStream.Create;
try
ImageEnIO1.AttachedIEBitmap := IEBitmap1;
if (FileExists(FFileName)) then begin
ImageEnIO1.LoadFromFileAuto(FFileName);
ImageEnIO1.Params.SetProperty('EXIF_XPSubject', 'Dolly');
ImageEnIO1.Params.SetProperty('EXIF_XPTitle', 'Photograph of Dolly');
ImageEnIO1.Params.SetProperty('Width', '100');
ImageEnIO1.Params.SetProperty('Height', '100');
ImageEnIO1.AttachedIEBitmap.Resize(300, 300);
ImageEnIO1.SaveToStream(ImgStream, ioJPEG);
ImgStream.Position := 0;
...
Response.ContentStream := ImgStream;
Response.ContentType := 'image/jpeg';
Response.StatusCode := 200;

The Resize command works, but the SetProperty commands have no effect. I've tried adding an InjectJpegEXIFStream command into the mix, but it makes no difference and I don't see why it should be needed anyway.

Any help will be gratefully received.


Richard Light

w2m

USA
1990 Posts

Posted - Feb 08 2013 :  12:28:27  Show Profile  Reply
Unfortunately, I have never used SetProperty but you might try setting the EXIF data directly and add EXIF_HasEXIFData:= True:

var
  iIEBitmap: TIEBitmap;
  iImageEnIO: TImageEnIO;
  iImgStream: TMemoryStream;
  iOutStream: TMemoryStream;
begin
  iIEBitmap := TIEBitmap.Create;
  try
    iImageEnIO := TImageEnIO.Create(Self);
    try
      iImgStream := TMemoryStream.Create;
      try
        iOutStream := TMemoryStream.Create;
        try
          iImageEnIO.AttachedIEBitmap := iIEBitmap;
          if (FileExists(FFileName)) then
          begin
            iImageEnIO.LoadFromFileAuto(FFileName);
            iImageEnIO.Params.EXIF_XPTitle := 'Photograph of Dolly';
            iImageEnIO.Params.EXIF_XPSubject := 'Dolly';
            // This is important if you want change some EXIF fields
            iImageEnIO.Params.EXIF_HasEXIFData := True;
            iImageEnIO.AttachedIEBitmap.Resize(300, 300);
            iImageEnIO.InjectJpegEXIF(iImgStream, iOutStream);
            iImageEnIO.SaveToStream(iOutStream, ioJPEG);
            iImgStream.Position := 0;
            // ...
            Response.ContentStream := iImgStream;
          end;
        finally
          iOutStream.Free;
        end;
      finally
        iImgStream.Free;
      end;
    finally
      iImageEnIO.Free;
    end;
  finally
    iIEBitmap.Free;
  end;
end;

This code has not been tested.

InjectJpegEXIFStream replaces EXIF information of the InputStream stream (jpeg) with EXIF current in memory without loading or modifying the original image. OutputStream contains the modified stream. The method returns false if it fails.

William Miller
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Go to Top of Page

RichardLight

United Kingdom
3 Posts

Posted - Feb 08 2013 :  13:05:02  Show Profile  Reply
William,

That was the only line I needed:

iImageEnIO.Params.EXIF_HasEXIFData := True;

does the job a treat. No need for a separate stream or InjectJpegEXIFStream.

Many thanks: I would never have spotted that crucial boolean property lurking amongst the many EXIF parameters.

Richard

Richard Light
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: