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
 Swap two Images with each other?

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
yogiyang Posted - Oct 12 2017 : 08:01:01
Hello,

I am using following code to swap images of Layers with each other but it is not working as expected. Both the selected Layers are disappearing.

Can someone point out as to what mistake I am making please?


var
  I, J: Integer;

  SelectPhotoCount, SelectPhotoNum: Integer;
  ieTemp1,ieTemp2, ieTemp3: TImageEnView;

  Layer1X, Layer1Y, Layer1W, Layer1H: Integer;
  Layer2X, Layer2Y, Layer2W, Layer2H: Integer;

  LayerCnt, Layer1Num, Layer2Num: Integer;

begin
   if ImageEnViewMain.IsEmpty then
    Exit;


  ieTemp1 := TImageEnView.Create(nil);
  ieTemp1.LayersAdd;
  ieTemp2 := TImageEnView.Create(nil);
  ieTemp2.LayersAdd;

  try
    if ImageEnViewMain.LayersSelCount = 2 then
    begin
      LayerCnt := 1;
      for I := 1 to ImageEnViewMain.LayersCount - 1 do
      begin
        if ImageEnViewMain.Layers[i].Selected then
        begin
          if ImageEnViewMain.Layers[i].IsMask = False and ImageEnViewMain.Layers[i].Visible = True then
          begin
            if LayerCnt = 1 then
            begin
              Layer1Num := i;

              Layer1X := ImageEnViewMain.Layers[i].PosX;
              Layer1Y := ImageEnViewMain.Layers[i].PosY;
              Layer1W := ImageEnViewMain.Layers[i].Width;
              Layer1H := ImageEnViewMain.Layers[i].Height;

              ImageEnViewMain.Layers[i].Assign(ieTemp1.CurrentLayer);

              ieTemp1.CurrentLayer.PosX;
              ieTemp1.CurrentLayer.PosY;
              ieTemp1.CurrentLayer.Width;
              ieTemp1.CurrentLayer.Height;

              LayerCnt := LayerCnt + 1;
            end
            else
            begin
              Layer2Num := i;

              Layer2X := ImageEnViewMain.Layers[i].PosX;
              Layer2Y := ImageEnViewMain.Layers[i].PosY;
              Layer2W := ImageEnViewMain.Layers[i].Width;
              Layer2H := ImageEnViewMain.Layers[i].Height;

              ImageEnViewMain.Layers[i].Assign(ieTemp2.CurrentLayer);

              ieTemp2.CurrentLayer.PosX;
              ieTemp2.CurrentLayer.PosY;
              ieTemp2.CurrentLayer.Width;
              ieTemp2.CurrentLayer.Height;

              LayerCnt := LayerCnt + 1;
            end;  //if LayerCnt = 1 then
          end;  //if ImageEnViewMain.Layers[i].IsMask = False and ImageEnViewMain.Layers[i].Visible = True then
        end;  //if ImageEnViewMain.Layers[i].Selected then
        if LayerCnt = 3 then
        begin
          //Swap the Layers contents
          ImageEnViewMain.LockUpdate;

          ImageEnViewMain.LayersCurrent := Layer2Num;
          ieTemp1.CurrentLayer.Assign(ImageEnViewMain.CurrentLayer);
          ImageEnViewMain.CurrentLayer.PosX := Layer2X;
          ImageEnViewMain.CurrentLayer.PosY := Layer2Y;
          ImageEnViewMain.CurrentLayer.Width := Layer2W;
          ImageEnViewMain.CurrentLayer.Height := Layer2H;

          ImageEnViewMain.LayersCurrent := Layer1Num;
          ieTemp2.CurrentLayer.Assign(ImageEnViewMain.CurrentLayer);
          ImageEnViewMain.CurrentLayer.PosX := Layer1X;
          ImageEnViewMain.CurrentLayer.PosY := Layer1Y;
          ImageEnViewMain.CurrentLayer.Width := Layer1W;
          ImageEnViewMain.CurrentLayer.Height := Layer1H;

          ImageEnViewMain.UnLockUpdate;
          ImageEnViewMain.Update;
          Break;
        end;

      end;  //for I := 1 to ImageEnViewMain.LayersCount - 1 do
    end;  //if ImageEnViewMain.LayersSelCount > 2 then
  finally
    FreeAndNil(ieTemp1);
    FreeAndNil(ieTemp2);
  end;
end;


TIA



Yogi Yang
2   L A T E S T    R E P L I E S    (Newest First)
yogiyang Posted - Oct 24 2017 : 08:31:35
Hello,

Sorry for very late reply.

Thanks Nigel.

I will try you code first thing tomorrow.

TIA




Yogi Yang
xequte Posted - Oct 12 2017 : 19:21:45
Hi Yogi

If you are only swapping the image, why not use use:

bmp := TIEBitmap.create;
bmp.assign( ImageEnViewMain.Layers[1].Bitmap );
ImageEnViewMain.Layers[1].Bitmap.assign( ImageEnViewMain.Layers[2].Bitmap );
ImageEnViewMain.Layers[2].Bitmap.assign( bmp );
bmp.Free;


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com