"Rubber-band" rectangle

mjcoon

Well-Known Member
Licensed User
I think that I can see how to elaborate Klaus's "MoveRect" example program to draw a rectangle that the user can drag to cover any part of the screen. (The sort of thing often used to use to specify an area to which to zoom; which is my intended purpose!)

But since this is a common function I thought I'd ask whether anyone has already published such a sample here?

Mike.
 

klaus

Expert
Licensed User
Longtime User
Hi Mike,

Attached you'll find an example of zooming a bitmap with a selectable "Rubber-band" rectangle.
The program is based on the ShowZoomBitmap program from the Graphics Tutorial.
You can:
- zoom to a given, user defined, zoom factor 0.05 to 5
- zoom to 100% 1 screen pixel = 1 image pixel
- zoom to make the image width fit the screen width
- zoom to make the image height fit the screen height
- zoom to a "Rubber-band" rectangle

Best regards.
 

Attachments

  • ShowZoomBitmap1.jpg
    ShowZoomBitmap1.jpg
    23.1 KB · Views: 240
  • ShowZoomBitmap2.jpg
    ShowZoomBitmap2.jpg
    20.5 KB · Views: 228
Last edited:

mjcoon

Well-Known Member
Licensed User
Attached you'll find an example of zooming a bitmap with a selectable "Rubber-band" rectangle. ...

Thanks Klaus, I shall study that. (I'm not sure that my usage will involve any bitmap.)

Just to show I did not sit back waiting, attached is a version of MoveRect.sbp that does what I meant. It uses beta-version features.

Mike.
 

Attachments

  • RubberRect.sbp
    2.5 KB · Views: 282

mjcoon

Well-Known Member
Licensed User
- zoom to a "Rubber-band" rectangle

Hi Klaus, I have started to cherry-pick the portions that I want from that useful program.

Since I am effectively showing vector graphics (actually GPS tracks) I don't have a bitmap to zoom for-real; what I will be doing is drawing a fresh bitmap.

So I am not sure whether I really need scroll-bars at all. But for now I have left them in. But I initially got an error at line:
B4X:
  ' zoome image width smaller than the screen widths
 ScrollX.Value=0      ' ScrollX.Value, ImageX and rectSrc.X = 0

Fortunately I have now found the problem (a simple typo; 'twas ever thus!).

I am going to have to invent some scaling to latitude and longitude, since I do not have an image with real pixels.

Mike.
 
Last edited:

klaus

Expert
Licensed User
Longtime User
The error you got happened with very small images, in that case it could happen that even Scroll.Maximum became negative and if the Scroll.Minimum value is bigger than Scroll.Maximum then Scroll.Minimum is set to Scroll.Maximum.

I hadn't tested the program with small images.

Attached an updated version, 6.90 beta version.

I don't have a bitmap to zoom for-real; what I will be doing is drawing a fresh bitmap.
I don't really understand what you do mean with fresh bitmap?

In any case you have a bitmap with a given size and a given scale.
The bitmap could be an empty one or a background map. I'm shure that you will need scrolling and zooming.

You have 2 choices for the zooming:
- zoom the whole bitmap and extract the desired part and copy it to the form.
- extract the desired part from the bitmap, zoom it and copy it to the form

The attached program uses the 2nd method.
For your application I would suggest you to use the first method, it is more efficient if you want to scroll the image. The ZoomScaledImage program from the Graphics tutorial and the ScaledMaps program both use the first method.

Best regards.
 

klaus

Expert
Licensed User
Longtime User
Attached you'll find a program ZoomScaledImage with the first method, a 6.90 version.
But it doesn't have, yet, the "Rubberband" rectangle zooming.
It is an evolution of the DrawOnScaledImage program from the Graphics tutorial.

Best regards.
 

mjcoon

Well-Known Member
Licensed User
I don't really understand what you do mean with fresh bitmap?

Thanks again Klaus (and for subsequent message).

What I'm doing is more like a drawing program, in that, at least to start with I won't have a background image. (We have a terminology problem; of course we are always drawing pixels on the screen. But in a drawing program a zoomed image is not derived from the pixels of an earlier bitmap but is re-drawn on a fresh bitmap.)

BTW on my old Psion I had (still have) an amazingly capable drawing program that came with the attached demo drawing. Zooming took only a fraction of a second.

I'm sure there is stuff about drawing programs too in this forum.

Best regards, Mike.
 

Attachments

  • TRACTION.jpg
    TRACTION.jpg
    19.6 KB · Views: 242

mjcoon

Well-Known Member
Licensed User
Hi All (and especially Klaus)...

My program is progressing and I have got round to trying it compiled for the device. I can briefly see my map shown on the foreground (my code derives, as I said earlier, from Klaus's) but the painted part of the screen turns black and what I have drawn is invisible. Whereas on the desktop, either under IDE or compiled, what I draw is shown against a grey background (probably the 220,220,220 that is the default form colour).

So where does the black-out come from? [Cracked it; had not properly altered Klaus's code. Don't understand difference between desktop and device, though...]

Mike.
 
Last edited:

mjcoon

Well-Known Member
Licensed User
Klaus's rubber-band zoom for images is simple and fast. But it is not "WYSIWYG" in the sense that you can draw a rectangle of any aspect ratio and then rules are applied to adjust the rectangle to fit the screen when zoomed.

But because I am examining data (GPS tracks) I want to display an accurate rectangle to show exactly what will appear when zoomed. And to adjust the rectangle accordingly.

Thus my rectangle manipulation is more like a drawing in which the sides or corners can be "picked up" and moved about, or the rectangle moved bodily. (Just like the IDE Designer.)

Except that the aspect ratio remains fixed. Thus if you move a side the adjacent sides also move. If you move a corner then either of the adjacent sides stay with the pointer but not necessarily the corner itself.

If anyone wants to use these features in an open-source project please let me know and I'll extract the code from my module. But it will take some work, so don't ask if you just want to play with it! N.B. There may still be flaws. A very small rectangle cannot have an accurate aspect ratio!

Mike.
 
Top