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
 I think this is a bug... LoadFromFile...
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

yogiyang

India
727 Posts

Posted - Sep 29 2016 :  09:42:26  Show Profile  Reply
Hello,

I don't know whether this is a but or not. But I am guessing that it is a bug!

Please download this sample code: https://www.dropbox.com/s/7cnjyi8shx697o0/LoadFromFileSample.zip?dl=0

Let me try and explain as to what is happening:
  • Load any file with multiple layers like for example a .psd file with multiple layers
  • Select any layer and load an image using code like this: ImageEnVect1.IO.LoadFromFile(fn);
  • The loaded image is getting stretched or resized as per the selected layer's current size.
    Again here if you have selected a landscape layer and you load a landscape orientation image you will hardly notice it. But if you load a portrait orientation image replacing the image in a landscape layer the loaded image gets stretched.

Why?

Not Add a new Layer and then load an image. The image comes perfectly in its actual size.
Why?

TIA



Yogi Yang

xequte

38615 Posts

Posted - Sep 29 2016 :  12:21:09  Show Profile  Reply
Hi Yogi

That is by design. LoadFromFile will load into the active layer/bitmap. If you have created and sized a layer then that is respected when loading.

Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

yogiyang

India
727 Posts

Posted - Sep 30 2016 :  00:05:05  Show Profile  Reply
Hello Nigel,

But then what is the solution. How can we get ImageEn to respect the size of loaded file and reset layer size as per the image getting loaded.

One way around this would be to Add a new layer and load the image in that layer. Doing this seems to load the image in its actual size and then swap that layer with the layer in question. Finally delete/remove the layer in question.

If there is any better way please share with me.

TIA


Yogi Yang
Go to Top of Page

xequte

38615 Posts

Posted - Sep 30 2016 :  02:15:39  Show Profile  Reply
Hi Yogi

Other than the way you mention you can size the layer after loading (wrapping the code in a LockPaint/UnlockPaint block.

You can use a method like the following to calculate the new size:

http://www.imageen.com/help/IEAdjustRectToAspectRatio.html


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

yogiyang

India
727 Posts

Posted - Oct 01 2016 :  09:32:52  Show Profile  Reply
Hello Nigel,

Thanks for the hint. But I am not able to understand as to how I can use this function and benefit from it.

Can you please give sample code for my particular case.

TIA


Yogi Yang
Go to Top of Page

xequte

38615 Posts

Posted - Oct 01 2016 :  13:42:18  Show Profile  Reply
It would be something like:

// Load an image into the second layer while maintaining its aspect ratio
ImageEnView1.LockPaint();
ImageEnView1.LayersCurrent := 1;
ImageEnView1.IO.LoadFromFile( 'D:\image.jpeg' );
aRect := GetImageRectWithinArea( ImageEnView1.CurrentLayer.Bitmap.Width, ImageEnView1.CurrentLayer.Bitmap.Height, 
                                 ImageEnView1.CurrentLayer.Width, ImageEnView1.CurrentLayer.Height );
ImageEnView1.CurrentLayer.PosX := ImageEnView1.CurrentLayer.PosX + aRect.Left;
ImageEnView1.CurrentLayer.PosY := ImageEnView1.CurrentLayer.PoxY + aRect.Top;
ImageEnView1.CurrentLayer.Width := aRect.Right - aRect.Left;
ImageEnView1.CurrentLayer.Height := aRect.Bottom - aRect.Top;
ImageEnView1.UnlockPaint();


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page

xequte

38615 Posts

Posted - Oct 25 2016 :  22:12:06  Show Profile  Reply
FYI, in the next release you can call:

ImageEnView1.CurrentLayer.RestoreAspectRatio();


Nigel
Xequte Software
www.xequte.com
nigel@xequte.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: