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
 Getting Viewed Image Position and Size
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

wshowalter

USA
12 Posts

Posted - Oct 07 2014 :  09:12:30  Show Profile  Reply
I have what should be a fairly simple question to answer, but I can't seem to tease it out of the forums or help.

I have an image displayed in an ImageEnView component. The user can zoom the image as they choose. I simply want to know what to know what the image coordinates are (X, Y, Width and Height) for what the user is seeing. I can get part of that using the Scr2Bmp( ViewX ), but then there's the OffsetX and ExtentX which confuse the matter.

Can anyone help me?

Wayne

w2m

USA
1990 Posts

Posted - Oct 07 2014 :  14:17:20  Show Profile  Reply
It sure would be nice if there was a VisibleBitmapLeft, VisibleBitmapTop, VisibleBitmapHeight, and VisibleBitmapWidth values and/or VisibleBitmapRect to precisely return the values which automatically adjusts for zoom.

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
Go to Top of Page

xequte

39142 Posts

Posted - Oct 08 2014 :  17:59:54  Show Profile  Reply
This is one of those things that seems more complex than it is. To get the visible are of the bitmap you can use:

function TfrmMain.VisibleBitmapRect(aImageEnView : TImageEnView) : TRect;
begin
  Result.Left   := aImageEnView.XScr2Bmp( 0 );
  Result.Top    := aImageEnView.YScr2Bmp( 0 );
  Result.Right  := aImageEnView.XScr2Bmp( aImageEnView.ClientWidth );
  Result.Bottom := aImageEnView.YScr2Bmp( aImageEnView.ClientHeight );
end;


Another example:

  // OUTPUT THE VISIBLE BITMAP IN IEVIEW1 to IEVIEW2

  // Get a rect of the bitmap area showing
  VisibleBmpRect.Left   := ImageEnView1.XScr2Bmp( 0 );
  VisibleBmpRect.Top    := ImageEnView1.YScr2Bmp( 0 );
  VisibleBmpRect.Right  := ImageEnView1.XScr2Bmp( ImageEnView1.ClientWidth );
  VisibleBmpRect.Bottom := ImageEnView1.YScr2Bmp( ImageEnView1.ClientHeight );

  // Draw VisibleBmpRect area of IEView1 bitmap to IEView2 bitmap
  IEView2.IEBitmap.Width  := IERectangle( VisibleBmpRect ).Width;
  IEView2.IEBitmap.Height := IERectangle( VisibleBmpRect ).Height;
  IEView1.IEBitmap.DrawToTIEBitmap( IEView2.IEBitmap, 0, 0, IERectangle( VisibleBmpRect ) );
  IEView2.Update;


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

wshowalter

USA
12 Posts

Posted - Oct 09 2014 :  08:14:33  Show Profile  Reply
Nigel,

Your post lead to my ultimate solution, so thanks. If the image does not fully fit the frame, your equations are not quite correct. I believe this is accurate, though:

function VisibleImageCoordinates( AnImageEnView: TImageEnView ) : TRect;
begin
Result.Left := AnImageEnView.XScr2Bmp( AnImageEnView.OffsetX );
Result.Top := AnImageEnView.YScr2Bmp( AnImageEnView.OffsetY );
Result.Right := AnImageEnView.XScr2Bmp( AnImageEnView.ClientWidth - AnImageEnView.OffsetX ) - 1;
Result.Bottom := AnImageEnView.YScr2Bmp( AnImageEnView.ClientHeight - AnImageEnView.OffsetY ) - 1;
end;

What is returned are the left/top most and right/bottom most pixel indexes in the image, as currently displayed. Very handy. Build this into a future version of TImageEnView?

Cheers,
Wayne Showalter
Go to Top of Page

xequte

39142 Posts

Posted - Oct 09 2014 :  16:22:51  Show Profile  Reply
Sorry Wayne,

You are quite right. I neglected to consider images smaller than the view.

In v5.1.2 you can use the VisibleBitmapRect property. It is read and write, so you can also use it to show an area of the image.

Examples

// Show the central portion of an image
ImageEnView1.VisibleBitmapRect := Rect(100, 100, 200, 200);

// Output the visible bitmap in ImageEnView1 to ImageEnView2
ImageEnView2.IEBitmap.Width  := IERectangle( ImageEnView1.VisibleBitmapRect ).Width;
ImageEnView2.IEBitmap.Height := IERectangle( ImageEnView1.VisibleBitmapRect ).Height;
ImageEnView1.IEBitmap.DrawToTIEBitmap( ImageEnView2.IEBitmap, 0, 0, IERectangle( ImageEnView1.VisibleBitmapRect ) );
ImageEnView2.Update;



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: