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
 Using TImageEnFolderMView to change images

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
Waheed Posted - Jan 24 2014 : 13:54:07
What is the proper way to change a selected image file in ImageEnFolderMView1 and save the changes?
I have a button, both ImageEnProc1 and ImageEnIO1 are linked to ImageEnFolderMView1:

the button onClick:
For j := 0 To TImageEnFolderMView1.ImageCount - 1 Do Begin
      if ImageEnFolderMView1.Checked[j] then begin
         ImageEnFolderMView1.SelectedImage := j;
         ImageEnIO1.LoadFromFile(ImageEnFolderMView1.SelectedFilename);
         ImageEnProc1.Negative;
         ImageEnIO1.SaveToFile(ImageEnFolderMView1.SelectedFilename);
         ImageEnFolderMView1.UpdateImage(j);
      end;
End;

The selected image is not changed. What is missing?
5   L A T E S T    R E P L I E S    (Newest First)
w2m Posted - Jan 25 2014 : 11:12:08
Yes, the processing is done on the selected image. The iexHelperfunctions are relatively new, but they have some great functions that make using imageen a lot simpler and faster to use by using functions to open, save and create thumbnails, apply shadows, and much more.

William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Waheed Posted - Jan 25 2014 : 10:58:38
Wow, thank you very much. I've combined both methods. And that was exactly what I want.

The helper functions were new to me. Also, whenever I run the proc on ImageEnMView1 it would be processing the selected image, correct?

Anyway thanks a lot for your patience and understanding.
w2m Posted - Jan 25 2014 : 09:09:40
Very frequently I see developers trying to use TImageEnProc and TImageEnIO with ImageEnMView. This is incorrect usage. Think of using TImageEnProc and TImageEnIO when working with TImageEnView or
TImageEnVect which hold a single TBitmap or TIEBitmap, but not with TImageEnMView that typically holds more than one bitmap. ImageEnMView was designed to display multiple frames of images like multiframed tif files or icon files or multiple independent images with each image having its own unique filename. Instead use the encapsulated version of ImageEnIO or ImageEnProc contained in TImageEnMView... ImageEnMView.Proc and ImageEnMView.IO. Do not use ImageEnIO or ImageEnProc with TImageEnMView.

To execute a TImageENProc function with TImageEnMView just use TImageEnMView.Proc.Negative. A ImageEnProc.Negative filter or another chosen procedure will be executed for each selected image in TImageEnMView.

If you are just trying to apply a negative filter to the image then here is the code:
procedure TForm1.ApplyNegativeFilter1Click(Sender: TObject);
{ Apply a negative filter to checked images in ImageEnMView1. }
var
  i: Integer;
begin
  for i := 0 to ImageEnMView1.ImageCount - 1 do
  begin
    if ImageEnMView1.Checked[i] then
    begin
      { Set the selected image }
      ImageEnMView1.SelectedImage := i;
      { Note: It is not correct to use ImageEnProc... always use
        ImageEnMView.Proc for processing images in ImageEnMView }
      { Use ImageEnMView.Proc to apply a negative filter to the selected image }
      ImageEnMView1.Proc.Negative;
      { Update the image }
      ImageEnMView1.UpdateImage(i);
    end;
  end;
  { Note: if ImageEnMView.Update is not called the changes may not be visible }
  { Update ImageEnMView }
  ImageEnMView1.Update;
end;

To save each checked image then here is the code:
Note: Add iexhelperfunctions to uses.
procedure TForm1.SaveCheckedImages1Click(Sender: TObject);
{ Save checked images to disk with the same filename.  Saved images will replace
  existing images. }
var
  i: Integer;
  iIEBitmap: TIEBitmap;
begin
  for i := 0 to ImageEnMView1.ImageCount - 1 do
  begin
    if ImageEnMView1.Checked[i] then
    begin
      { Set the selected image }
      ImageEnMView1.SelectedImage := i;
      { Get the TIEBitmap }
      iIEBitmap := ImageEnMView1.GetTIEBitmap(i);
      try
        { For simplicity save the bitmap with the original filename with
          IESaveToFile which is found in iexhelperfunctions.pas }
        iIEBitmap.IESaveToFile(ImageEnMView1.MIO.Params[i].Filename, 80);
      finally
        { Release the bitmap to prevent memory leaks }
        ImageEnMView1.ReleaseBitmap(i, True);
      end;
    end;
  end;
end;

Download demo here:
./attach/w2m/2014125103835_ImageEnMViewProc.zip

William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html
Waheed Posted - Jan 25 2014 : 07:45:05
Ok I replace the ImageEnFolderMView with ImageEnMView, adjusted the code as follows and the Proc and IO also, and still it didn't work:


  For j := 0 To imageList.ImageCount - 1 Do Begin
      if imageList2.Checked[j] then begin
         imageList2.SelectedImage := j;
         ImageEnIO1.LoadFromFile(imageList2.ImageFileName[imageList2.SelectedImage]);
         imgProc.Negative;
         ImageEnIO1.SaveToFile(imageList2.ImageFileName[imageList2.SelectedImage]);
         imageList2.UpdateImage(j);
      end;
   End;


Now what am I doing wrong? I want to negate all checked images.
w2m Posted - Jan 24 2014 : 16:54:11
The images in ImageEnFolderMView are all tied to the windows file system. That means the thumbnails are loaded from files in a folder.

So you should not replace bitmaps like you are attempting to do because ImageEnFolderMView uses the windows file system similar to that used by Windows Explorer. If you replace a thumbnail many functions in ImageEnFolderMView will not work correctly.

You should use InsertFile or AppendFile instead.

function InsertFile(idx : Integer; const sFilename : string; bSelectIt : Boolean = True; bCheckFileType : Boolean = True) : Boolean;
function AppendFile(const sFilename : string; bSelectIt : Boolean = True; bCheckFileType : Boolean = True) : integer;

Having advised against this with ImageEnFolderMView there is nothing wrong doing this with ImageEnMView, in fact here is how to do it:

procedure TForm1.ReplaceIEBitmap1Click(Sender: TObject);
var
  idx: Integer;
begin
   idx := ImageEnMView1.SelectedImage;
   ImageEnMView1.SetIEBitmap(idx, ImageenView1.IEBitmap);
   ImageEnMView1.UpdateImage(idx);
   ImageEnMView1.ImageTopText[idx].Caption := IntToStr(ImageenView1.IEBitmap.Width) +
    ' x ' + IntToStr(ImageenView1.IEBitmap.Height) + ' RGB ' +
    IntToStr(ImageenView1.IO.Params.BitsPerSample * ImageenView1.IO.Params.SamplesPerPixel)  +
    '-bit';
    ImageEnMView1.ImageInfoText[idx].Caption := 'DPI: ' + IntToStr(ImageEnView1.IO.Params.Dpi);
    ImageEnMView1.ImageBottomText[idx].Caption := ExtractFilename(ImageEnView1.IO.Params.Filename);
end;

Perhaps this can be best explained by ImageEnFolderMView works with files and image files and ImageEnMView works with images. So if you need to manipulate files then use ImageEnFolderMView, and if you are displaying and processing images use ImageEnMView.

William Miller
Adirondack Software & Graphics
Email: w2m@frontiernet.net
EBook: http://www.imageen.com/ebook/
Apprehend: http://www.frontiernet.net/~w2m/index.html