Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: XE8 FMX TImageViewer get coordinates in bitmap from the screen


This question is answered. Helpful answers available: 1. Correct answers available: 1.


Permlink Replies: 15 - Last Post: Aug 2, 2015 1:34 PM Last Post By: Peter Guth
Peter Guth

Posts: 28
Registered: 2/11/05
XE8 FMX TImageViewer get coordinates in bitmap from the screen  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 21, 2015 5:21 PM
Hi,

I am using Firemonkey in XE8 (both mobile and desktop) to display a bitmap which shows an actual map. I know the real ground coordinates for every pixel in the bitmap, and want to get those ground coordinates that correspond to a pixel on the screen.

If the bitmap is zoomed out so that it has a white border around it, I can compute the location of the image in the window using ClientHeight, ClientWidth, and the BitmapScale property, and work out where in the bitmap I am.

If the scrollbars are active because the user has zoomed in, I cannot figure out what part of the bitmap is shown, and I think all the variables (like the x and y sent to ImageViewer1MouseMove) are relative to the viewport displayed and not the actual bitmap. I have tracked a number of the properties for the ImageViewer (e.g. Position, Margins, Padding, and ViewportPosition) but they appear to always be zero.

How can I compute what part of the bitmap is actually on screen?

Thanks for any assistance.
Peter Guth

Posts: 28
Registered: 2/11/05
Re: XE8 FMX TImageViewer get coordinates in bitmap from the screen  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 22, 2015 10:32 AM   in response to: Peter Guth in response to: Peter Guth
var
ScreenLastX,ScreenLastY, //coordinates of the current point, relative to the size of the scaled bitmap
MapLastX,MapLastY : integer; //coordinates of the current point, relative to the size of the original bitmap
BMP_blowup_x,BMP_blowup_y, //size of the full bitmap in pixels with the current BitmapScale
vpx,vpy : float; //x and y coordinates in pixels of upper left corner of the current screen view
//captured from NewViewportPosition in ImageViewer1ViewportPositionChange
xFrac,yFrac, //fractional position within the bitmap (0-1), with origin in the upper left corner
ULx,ULy,LRx,LRy : float; //coordinates in screen pixels of the corners of the bitmap in the image viewer, if it has a white collar

You can find the offset by setting a global variable and assigning it when the viewport changes. I would love to find out that this is saved, but I cannot find it. Thus I am leaving the question open, in hopes of finding a more elegant answer.

procedure TianMDMainForm.ImageViewer1ViewportPositionChange(Sender: TObject;
const OldViewportPosition, NewViewportPosition: TPointF;
const ContentSizeChanged: Boolean);
begin
vpx := NewViewPortPosition.X;
vpy := NewViewPortPosition.Y;
end;

procedure TianMDMainForm.ImageViewer1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Single);
begin
BMP_blowup_x := ImageViewer1.BitmapScale * ImageViewer1.Bitmap.Width;
BMP_blowup_y := ImageViewer1.BitmapScale * ImageViewer1.Bitmap.Height;

ScreenLastX := round(x + vpx);
ScreenLastY := round(Y + vpy);

if ImageViewer1.ClientWidth > BMP_blowup_x then begin
ULx := 0.5 * (ImageViewer1.ClientWidth - BMP_blowup_x);
LRx := ImageViewer1.ClientWidth - ULx;
xFrac := (x - ULx) / (LRx - ULx);
end
else begin
xfrac := (x + vpx)/ BMP_blowup_x;
end;

if ImageViewer1.ClientHeight > BMP_blowup_Y then begin
ULy := 0.5 * (ImageViewer1.ClientHeight - BMP_blowup_Y);
LRy := ImageViewer1.ClientHeight - ULy;
yFrac := (y - ULy) / (LRy - ULY);
end
else begin
yfrac := (y + vpy) / BMP_blowup_Y;
end;

MapLastX := round(xFrac * ImageViewer1.Bitmap.Width);
MapLastY := round(yFrac * ImageViewer1.Bitmap.Height);

Label1.Text := MapDraw.ScreenLocationString(MapLastx,MapLasty) ;

end;

Vadim Istomin

Posts: 112
Registered: 4/12/02
Re: XE8 FMX TImageViewer get coordinates in bitmap from the screen
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 24, 2015 12:07 PM   in response to: Peter Guth in response to: Peter Guth
Peter Guth wrote:
Hi,

I am using Firemonkey in XE8 (both mobile and desktop) to display a bitmap which shows an actual map. I know the real ground coordinates for every pixel in the bitmap, and want to get those ground coordinates that correspond to a pixel on the screen.

If the bitmap is zoomed out so that it has a white border around it, I can compute the location of the image in the window using ClientHeight, ClientWidth, and the BitmapScale property, and work out where in the bitmap I am.

If the scrollbars are active because the user has zoomed in, I cannot figure out what part of the bitmap is shown, and I think all the variables (like the x and y sent to ImageViewer1MouseMove) are relative to the viewport displayed and not the actual bitmap. I have tracked a number of the properties for the ImageViewer (e.g. Position, Margins, Padding, and ViewportPosition) but they appear to always be zero.

How can I compute what part of the bitmap is actually on screen?

Thanks for any assistance.

TFMXImageViewer is a terrible component with huge number of so called "bugs", which are actually design and coding errors. Fixing these errors is very difficult, because they involve a long chain of code in many components, which should not have anything to do with it, but they do (a TAniCalculations, to name one, for example). ViewportPosition, for example, behaves in a very strange way: it is always zero if the image is smaller than the viewport, and it is not zero if at least one of the image dimensions is larger than the viewport.

Try to look at the code presented in QuarkCube demos on YouTube, as, for example, https://www.youtube.com/watch?v=B1OIm6RIU3M, to understand how to use and how get the access to some private properties of the FMXImageViewer and correct its behavior (ContentBounds, ExtentX, ExtentY etc).

On a general note, there are ClientToScreen and ScreenToClient functions, which should help with translation of screen coordinates to actual bitmap coordinates and vice versa.

P.S. I do not have XE8, but I tested this component very thoroughly in XE4, XE5, XE6 and XE7. To the best of my knowledge, "bugs" of this component were never fixed.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: XE8 FMX TImageViewer get coordinates in bitmap from the screen  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 24, 2015 1:02 PM   in response to: Vadim Istomin in response to: Vadim Istomin
Vadim wrote:

P.S. I do not have XE8, but I tested this component very thoroughly
in XE4, XE5, XE6 and XE7. To the best of my knowledge, "bugs" of
this component were never fixed.

Were they reported to QualityCentral/QualityPortal?

--
Remy Lebeau (TeamB)
Vadim Istomin

Posts: 112
Registered: 4/12/02
Re: XE8 FMX TImageViewer get coordinates in bitmap from the screen  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 24, 2015 1:43 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Vadim wrote:

P.S. I do not have XE8, but I tested this component very thoroughly
in XE4, XE5, XE6 and XE7. To the best of my knowledge, "bugs" of
this component were never fixed.

Were they reported to QualityCentral/QualityPortal?

--
Remy Lebeau (TeamB)

I reported a lot of "bugs" since the time when I became a better tester for XE4 and later versions. These bugs were mainly regarding 3D and multimedia components, and they were opened, accepted and mainly ignored.
After I complained that bugs are not fixed (in a private beta testers forum), I was immediately excluded from beta testers by some "high official" at EMBT. Since that happened, I am not submitting reports to Quality Central anymore.

Edited by: Vadim Istomin on Jul 24, 2015 4:44 PM
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: XE8 FMX TImageViewer get coordinates in bitmap from the screen[Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 24, 2015 2:09 PM   in response to: Vadim Istomin in response to: Vadim Istomin
Vadim wrote:

After I complained that bugs are not fixed (in a private beta testers
forum), I was immediately excluded from beta testers by some "high
official" at EMBT.

I doubt that, but even if it were true, could it be you were excluded for
how you were complaining, rather than the fact that you were complaining
at all? Beta testers are supposed to find and report problems. Have you
tried contacting Embarcadero to reinstate your beta status?

Since that happened, I am not submitting reports to Quality Central
anymore.

Nothing should be posted to QC anymore, but certainly to QP. How do you
expect things to get fixed when they are not reported?

--
Remy Lebeau (TeamB)
Vadim Istomin

Posts: 112
Registered: 4/12/02
Re: XE8 FMX TImageViewer get coordinates in bitmap from the screen[Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 24, 2015 2:30 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Vadim wrote:

After I complained that bugs are not fixed (in a private beta testers
forum), I was immediately excluded from beta testers by some "high
official" at EMBT.

I doubt that, but even if it were true, could it be you were excluded for
how you were complaining, rather than the fact that you were complaining
at all? Beta testers are supposed to find and report problems. Have you
tried contacting Embarcadero to reinstate your beta status?

Since that happened, I am not submitting reports to Quality Central
anymore.

Nothing should be posted to QC anymore, but certainly to QP. How do you
expect things to get fixed when they are not reported?

--
Remy Lebeau (TeamB)

Typical TeamB answer. First, this is not true. Second, even if this is true, you have to blame yourself anyway. Brilliant!

I reported in a private forum that the bugs that were listed in the QC database as fixed were not fixed in the latest production release, and I proved that it was, indeed, true.
And yes, I was very angry, and I said that reporting bugs is a waist of time. After that some person, which name I do not want to mention, personally made sure that I could not login to the beta testers forum.
He did it so quickly, that I could not even respond to his reply to my message.

This is why I am not dealing with this anymore.
Peter Guth

Posts: 28
Registered: 2/11/05
Re: XE8 FMX TImageViewer get coordinates in bitmap from the screen  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 29, 2015 7:14 PM   in response to: Vadim Istomin in response to: Vadim Istomin
Thanks for the suggestions. I will try to check the videos, but I wish they had source code available.
Vadim Istomin

Posts: 112
Registered: 4/12/02
Re: XE8 FMX TImageViewer get coordinates in bitmap from the screen  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 29, 2015 8:26 PM   in response to: Peter Guth in response to: Peter Guth
Peter Guth wrote:
Thanks for the suggestions. I will try to check the videos, but I wish they had source code available.

But the source code IS available. You can read it from the screen, just click the "pause" button, and make sure that player's resolution is set to its maximum. This is less convenient than downloading the ZIP file, but the code is still there.
I can even say that looking at the process of coding step by step is much better for learning than just getting some "ready to go" demo project. I personally learned a lot from these movies, which are dedicated mostly to 3D components and 3D scene design.

I wish I could say "thank you" to the author!
Peter Guth

Posts: 28
Registered: 2/11/05
Re: XE8 FMX TImageViewer get coordinates in bitmap from the screen  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 31, 2015 8:18 AM   in response to: Vadim Istomin in response to: Vadim Istomin
I wish I could say "thank you" to the author!

I agree; he has put a lot of work into those videos, and is too self-effacing in the comment that most people won't appreciate his work, which is admittedly for a small audience. It takes a lot of study to catch all the nuances, and only being able to get snippets of code at a time.

My real complaint is the lack of documentation for the controls (tMesh is another I have struggled with), and the lack of serious examples that show how to work with them (there were some decent ones for tMesh, but they got broken in the changes to FireMonkey).
Vadim Istomin

Posts: 112
Registered: 4/12/02
Re: XE8 FMX TImageViewer get coordinates in bitmap from the screen  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 31, 2015 1:13 PM   in response to: Peter Guth in response to: Peter Guth
Peter Guth wrote:
I wish I could say "thank you" to the author!

I agree; he has put a lot of work into those videos, and is too self-effacing in the comment that most people won't appreciate his work, which is admittedly for a small audience. It takes a lot of study to catch all the nuances, and only being able to get snippets of code at a time.

My real complaint is the lack of documentation for the controls (tMesh is another I have struggled with), and the lack of serious examples that show how to work with them (there were some decent ones for tMesh, but they got broken in the changes to FireMonkey).

The lack of documentation? Please, don't even start. The situation with FMX documentation is appalling. Not surprisingly (since FMX is originally Russian), there is a very good book describing FireMonkey components, but it is in Russian (by D.D. Osipov, "Delphi programming for Windows, OSX, iOS and Android" St.Petersburg, 2014). This is not his first Delphi book, but probably the best. It even has a chapter about TMesh, TMeshData and TModel3D. As far as I know, EMBT never tried to arrange the translation of this book, or even to mention it anywhere. Instead of promoting books that have nothing to do with FireMonkey, they could order and publish the translation of this one.

For anyone who is interested and can read in Russian, here is the link: http://www.ozon.ru/context/detail/id/29512660/
Peter Guth

Posts: 28
Registered: 2/11/05
Re: XE8 FMX TImageViewer get coordinates in bitmap from the screen  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 2, 2015 9:41 AM   in response to: Vadim Istomin in response to: Vadim Istomin
Not only is the Firemonkey documentation an issue, but things have a habit or moving around to new homes in other units so that demos that once worked no longer do.

I will keep the book in mind, as I had two years of Russian 40 years ago and could figure out that the button on the web site said "Buy".

What I really want is to open a viewport that lets me address OpenGL directly, since I want to plot very large numbers of points (millions if the hardware would support it, certainly in the 100,000's) and I think Firemonkey will not like that. I have it working in Windows Firemonkey, and with that, I can fake the mesh.
Vadim Istomin

Posts: 112
Registered: 4/12/02
Re: XE8 FMX TImageViewer get coordinates in bitmap from the screen  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 2, 2015 12:57 PM   in response to: Peter Guth in response to: Peter Guth
Peter Guth wrote:
Not only is the Firemonkey documentation an issue, but things have a habit or moving around to new homes in other units so that demos that once worked no longer do.

I will keep the book in mind, as I had two years of Russian 40 years ago and could figure out that the button on the web site said "Buy".

What I really want is to open a viewport that lets me address OpenGL directly, since I want to plot very large numbers of points (millions if the hardware would support it, certainly in the 100,000's) and I think Firemonkey will not like that. I have it working in Windows Firemonkey, and with that, I can fake the mesh.

To use OpenGL directly in FMX you can create TContext3D using TContextManager or just use the Context property of the form. After that put your OpenGL commands (or drawing primitives available in Context class) between Context.BeginScene and Context.EndScene. Also, you probably saw the CubeMan3D demo, which shows how to create cross-platform OpenGL project without FireMonkey at all (and, of course, the example is very simplistic).

However, rendering a mesh with "a lot of points" will be practically limited by the maximal size of the TMeshData that you can allocate, so, most likely you will need 64-bit address space. By the way, I never worked with huge meshes, only with huge textures. But, in my experience, one can create and render 1250^3 pixels texture (4.315GB) on 64-bit system, but no more than ~600^3 pixels texture on 32-bit system, even though the video card is the same and technically it should support much more.
Peter Guth

Posts: 1
Registered: 6/22/98
Re: XE8 FMX TImageViewer get coordinates in bitmap from the screen  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 2, 2015 1:34 PM   in response to: Vadim Istomin in response to: Vadim Istomin
Thanks for the hints of drawing straight to the OpenGL in Firemonkey; I will have to try the out.

I have seen CubeMan, and have it working to display the geosptial data I want in Windows. But I have two issues with it:
1. It does not show how to hook up controls, as I would like to rotate the model interactively.
2. The Android version will not compile. They moved the location of a routine between XE5 and XE8, and darned if I cannot find it, so I am stuck until I find that (another thread on this forum).

I had better luck with the code at http://escargot.la.coocan.jp/SimpleSamples/SimpleSampleOpenGL_FMX.pas (I was not able to find the project file or the form, but was able to recreate them), and got it to run in a TForm3D in Windows. Since I upgraded to Windows 10, I cannot talk to my Nexus 7, so no luck there for a while (yet another thread on this forum).

I need to display two types of data: points clouds with points that could be all other the place (true 3D), and imagery that needs to be draped on the topography (only 2.5D). The second could use a tMesh, but it can also use the same code as the point cloud, which is just a lot of
glColor3f(PointXYZColor[i].r,PointXYZColor[i].g,PointXYZColor[i].b );
glVertex3f(0.075*PointXYZColor[i].x,0.01*PointXYZColor[i].z,0.075*PointXYZColor[i].y);
which I think might be faster than trying to set up TMesh, where every point has a different color and there is no function to set them.
Gilbert Padilla

Posts: 315
Registered: 3/8/04
Re: XE8 FMX TImageViewer get coordinates in bitmap from the screen [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 2, 2015 12:38 PM   in response to: Vadim Istomin in response to: Vadim Istomin
Does the book include sources?
Vadim Istomin

Posts: 112
Registered: 4/12/02
Re: XE8 FMX TImageViewer get coordinates in bitmap from the screen [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 2, 2015 1:10 PM   in response to: Gilbert Padilla in response to: Gilbert Padilla
Gilbert Padilla wrote:
Does the book include sources?

The book has a lot of code examples and, as they say on the first page, example projects are available for download at the publisher's site. However, I could not find any link to it anywhere; perhaps did not try hard enough.
By the way, I checked today, and it seems that the hard copy is not available anymore. However, they have e-book version for 359 roubles, which is less than $6.00.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02