10.3.1 Large image browsing
There are two ways when we need to display a larger size image than the screen size:
- Resize the image to fit the screen.
- Display the a part area of image to the screen and ability can change different the part area of image to screen.
The first way will make the large size picture lose details, we use the second way to implement this.
In the previous section (10.2) we showed how to use View class, Next we can use same method for scrolling large-size images.
We define four directions of movement: VIEW_MOVE_LEFT, VIEW_MOVE_RIGHT, VIEW_MOVE_UP, VIEW_MOVE_DOWN, and we can specify the offset offset (default 5 pixels) for each movement, which enables the scrolling of large-size images in any direction.
def _moveView( self, direction, offset = 5 ): screen = self.RPiSpark.Screen sW, sH = screen.getBufferSize() # LEFT if direction == VIEW_MOVE_LEFT: if screen.View.x - offset < 0: screen.View.x = 0 else: screen.View.moveOffset( -1 * offset, 0 ) self.actionStatus = ST_ACTION_REFRESH return # RIGHT if direction == VIEW_MOVE_RIGHT: if screen.View.x + screen.View.width + offset > sW: screen.View.x = sW - screen.View.width else: screen.View.moveOffset( offset, 0 ) self.actionStatus = ST_ACTION_REFRESH return # UP if direction == VIEW_MOVE_UP: if screen.View.y - offset < 0: screen.View.y = 0 else: screen.View.moveOffset( 0, -1 * offset ) self.actionStatus = ST_ACTION_REFRESH return # DOWN if direction == VIEW_MOVE_DOWN: if screen.View.y + screen.View.height + offset > sH: screen.View.y = sH - screen.View.height else: screen.View.moveOffset( 0, offset ) self.actionStatus = ST_ACTION_REFRESH return