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