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
 Copying to a bitmap from a TImageEnView
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

bmesser

United Kingdom
234 Posts

Posted - Nov 22 2012 :  06:03:43  Show Profile  Reply
Hi

I have a routine that takes the layers displayed in an TImageEnView component grabs a bitmap from the merged layer and adds it to my animated GIF. All works very well. What I want to do is grab a similar merged bitmap but from a zoomed TImageEnView component rather than the whole thing. I've tried to do this with CopyRectTo but without much luck, could someone point me at the correct method?

I've attached some pseudo code to give you an idea what works at the moment.

Bruce.

bmp : TBitMap;
iebmp : TIEBitMap;

for idx:=ImageEnView.LayersCount-1 downto 0 do
begin
  ImageEnView.LayersMergeTo(0,idx,iebmp);
  iebmp.CopyToTBitmap(bmp);
  iebmp.FreeImage;
  AddBitmapToAnimatedGIF(GIF,bmp,false); // routine to add to animated GIF
end;

w2m

USA
1990 Posts

Posted - Nov 23 2012 :  13:58:26  Show Profile  Reply
procedure TFormMain.SaveAsGIF1Click(Sender: TObject);
// Create an animated gif from the layers in a TImageEnVect (TimageEnView) accounting for zoom
var
  i: integer;
  iFilename: string;
  iIEBitmap: TIEBitmap;
  iIndex: integer;
  iImageEnMView: TImageEnMView;
  iWidth: integer;
  iHeight: integer;
  iFrames: integer;
begin
  iFilename := 'anim.gif';
  // Create TImageEnMView to save the multiframe file
  iImageEnMView := TImageEnMView.Create(nil);
  try
    for i := 0 to ImageEnVect1.LayersCount - 1 do
    begin
      // Get the zoomed image dimensions-Get the width of the area used to show current image.
      iWidth := ImageEnVect1.ExtentX;
      // Get the height of the area used to show the current image.
      iHeight := ImageEnVect1.ExtentY;
      // Create the TIEBitmap to hold the image from a layer
      iIEBitmap := TIEBitmap.Create(iWidth, iHeight, ie24RGB);
      try
        // Copy the layers IEBitmap to iIEBitmap
        // This is a cropped and zoomed image which should be similar to the zoomed image on the screen
        ImageEnVect1.Layers[i].Bitmap.RenderToCanvasWithAlpha(iIEBitmap.Canvas, 0, 0, iWidth, iHeight, 0, 0, iWidth, iHeight,
          255, rfNone);
        // AppendImage appends a new image at last position in the list and returns the new image position
        iIndex := iImageEnMView.AppendImage;
        // Set the TIEBitmap to the iImageEnMView frame
        iImageEnMView.SetIEBitmap(iIndex, iIEBitmap);
        // Set the Gif's image index
        iImageEnMView.MIO.Params[i].GIF_ImageIndex := iIndex;
        // Free the Bitmap
        iImageEnMView.ReleaseBitmap(i);
      finally
        iIEBitmap.Free;
      end;
    end;
  // Save the animated multiframe GIF file.
  iImageEnMView.MIO.SaveToFileGIF(iFilename);
  finally;
    iImageEnMView.Free;
  end;
    iFrames := IEGetFileFramesCount(iFilename);
  MessageBox(0, PWideChar(IntToStr(iFrames) +
    ' frames were added to the GIF file and the file was saved as ' + iFilename + '.'), '',
    MB_ICONINFORMATION or MB_OK);
end;

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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: