Drawing a Image bigger then the screen

Georg

Member
Licensed User
Longtime User
Hi

I want to draw an Image bigger then the screen and have then scrollbars. I didn't found anything in the Treads. Someone can Help?

Georg
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This code moves a large image by dragging the mouse (the file is also attached):
B4X:
Sub Globals
    Dim x1,y1
    Dim maxX,maxY
End Sub

Sub App_Start
    Form1.Show
    drawer.New1("form1",false)
    bmpMap.New1("pic.jpg") 'Loads the image to a Bitmap object
    rectDest.New1(5,5,form1.Width-10,form1.Height-10) 'The form's rectangle
    rectSrc.New1(0,0,rectDest.Width,rectDest.Height) 'The bitmap's rectangle
    maxX = bmpMap.Width - rectDest.Width
    maxY = bmpMap.Height - rectDest.Height
    DrawMap
End Sub

Sub Form1_MouseDown (x,y)
    x1 = x
    y1 = y
End Sub

Sub Form1_MouseUp (x,y)
    RectSrc.X = Min(maxX,Max(RectSrc.X - x + x1,0)) 'Checks the bounds and updates the coordinates
    RectSrc.Y = Min(maxY,Max(RectSrc.Y - y + y1,0))
    DrawMap
End Sub

Sub DrawMap
    drawer.DrawImage1(bmpMap.Value,rectSrc.Value,rectDest.Value,false)
    drawer.Refresh2(rectDest.Value)
End Sub
 

Attachments

  • Map.zip
    51 KB · Views: 237

agraham

Expert
Licensed User
Longtime User
I had a look at your example. In this case are the LargeChange, SmallChange and Value parameters also accessible and be changed ?
Yes, they should be accessible through the HorizontalScroll and VerticalScroll properties of the Panel which are HScrollProperties and VScrollProperties types respectively. If you walk the Docs for Panel you should see them and their members.

B4X:
pnl1obj.FromControl("Panel1")
pnl1obj.SetProperty("AutoScroll", true)
hscrollobj.value = pnl1obj.GetProperty("HorizontalScroll") ' returns an HScrollProperties type
hscrollobj.SetProperty("LargeChange", 20)


The landing of the F111 is somewhat risky, isn't it ?
It's an Autralian one that sustained undercarriage damage on takeoff. They nearly dumped it in the sea but opted to belly it in after lightening it as much as possible. Surprisingly little damage was caused apparently!
 

agraham

Expert
Licensed User
Longtime User
is it possible to add the ValueChanged event to the panel's scrollbars
Unfortunately it looks like no :(.

The Door library can see two scroll bar property objects but not the scroll bars themselves. This is because the Panel is a native control, and so are its' scroll bars and the scroll bars are not exposed as .NET controls - only the Panel itself is. There is a Scroll event for the panel for the desktop but not on the device. However even on the desktop this event can't be used as the Door library doesn't know about the ScrollEventHandler object which this event returns.
 

agraham

Expert
Licensed User
Longtime User
Unfortunately it looks like no :(
Actually :)

Using the dzEventsMagic library :D


EDIT : Note that if you want to try this on the device that Line 14 should be changed to "MouseDown", as a Panel does not have a MouseClick event on the device, and lines 19,20 and 21 removed as on the device a Panel does not have HorizontalScroll and VerticalScroll properties. The scroll events will work.
 
Last edited:

mjcoon

Well-Known Member
Licensed User
I found that map.zip jolly useful starter-for-ten. I added a mouse_move method so I could watch the scrolling while the stylus was moving. But I found that when running on the desktop the method was triggered by the mouse "flying" over the panel without a mose-down event. Easily cured by making the movement conditional on having had a mouse-down, but a bit of a surprise since I presume that no device can have a flying stylus?

Cheers, Mike.
 

klaus

Expert
Licensed User
Longtime User
Yes on the desktop, if you don't want having the MouseMove event triggered always you should initiate a flag in the MouseDown event to enable it. In most cases you will need it anyway to show a reaction directly at MouseDown and not need to wait for a MouseMove.

There is a small extension to this with some graphics samples on the french forum, post #3.
http://www.b4x.com/forum/french-forum/2373-dessinez-cest-pas-gagne.html

Best regards.
 

alea46

Member
Licensed User
Becarefull for large size image

Hi,
When I start the program for my farm, I think there is no problem. But, when I try it on PPC (Asus 730), I got too big probems :
:( Size of image : the PPC need 29Mo memory for a 3000x3000 (*) bitmap, no solution to decrease the memory size (I would make it smaller with only 4 colors, but it's impossible).
:(Scrolling bar failed in error pnl1HScrollobj.value=pnl1obj.getproperty("horizontalscroll") error description : NullReferenceExeption.

Is someone encounter same problem?
Is someone have solution to this problem?

The program is design to assist farmer on tractor to guide them with more or less precision (GPS error).

(*) Note that 3000*3000 is the size I take to avoid problem to charge and discharge data for my Biggest Field within the scale I choose.
 

alea46

Member
Licensed User
How automatically focus on a pixel

Hi,
Thank's agraham for the precision.


If it's impossible to fix scroolbars values, is there an issue to center map on the part that is drawing, whitout any manipulation, like it could be possible with scroolbar property?

Thank's to Klaus who helps me in french forum to start.
 

agraham

Expert
Licensed User
Longtime User
is there an issue to center map on the part that is drawing, whitout any manipulation
I am afraid that I can't find a way to do that on the device using the scroll bars. However a workaround is to forget about AutoScroll and position the image control on the Panel by setting the Top and Left properties to negative values. If you also want scrollbars then use the ones in ControlsEx and write the code to move the image around.
 
Top