Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS 

Using the mousewheel to zoom in or out an SVG document

This code was originally copied from Mouse wheel programming in JavaScript [adomas.org]. I replaced about 5 lines of code to get the mousewheel controlling the zoom feature in the makeZoom.svg [dzone.com] file.

  /** This is high-level function; REPLACE IT WITH YOUR CODE.
 * It must react to delta being more/less than zero.
 */
function zoomInOut(delta) {
	if (delta >= 0)
		zoomIn()
	else
		zoomOut()
}

function wheel(event){
	var delta = 0;
	if (!event) event = window.event;
	if (event.wheelDelta) {
		delta = event.wheelDelta/120; 
		if (window.opera) delta = -delta;
	} else if (event.detail) {
		delta = -event.detail/3;
	}
	if (delta)
		zoomInOut(delta);
        if (event.preventDefault)
                event.preventDefault();
        event.returnValue = false;
}

/* Initialization code. */
if (window.addEventListener)
	window.addEventListener('DOMMouseScroll', wheel, false);
window.onmousewheel = document.onmousewheel = wheel;

Java - ZoomOUT image

public BufferedImage zoomOut(BufferedImage bi, int scale)
	{
		int width = bi.getWidth() / scale;
		int height = bi.getHeight() / scale;
		
		BufferedImage biScale = new BufferedImage(width, height, bi.getType());
		
		for(int i=0; i<width; i++)
			for(int j=0; j<height; j++)
				biScale.setRGB(i, j, bi.getRGB(i*scale, j*scale));
		
		return biScale;
	}

Java - ZoomIN Image

public BufferedImage zoomIn(BufferedImage bi, int scale)
	{
		int width = scale * bi.getWidth();
		int height = scale * bi.getHeight();
		
		BufferedImage biScale = new BufferedImage(width, height, bi.getType());
		
                // Cicla dando un valore medio al pixel corrispondente
		for(int i=0; i<width; i++)
			for(int j=0; j<height; j++)
				biScale.setRGB(i, j, bi.getRGB(i/scale, j/scale));
		
		return biScale;
	}

Using google map on mobile phone

Download the tile images for testing
from urllib import urlretrieve
turl =  'http://mt.google.com/mt?v=w2.4&x=%s&y=%s&zoom=%s'
tfile = '%s-%s-%s.gif'
z = 12
for x in range(5,10):
  for y in range(10,14):
    urlretrieve(turl % (x,y,z), tfile % (z,y,x))

Then put the images in the phone. Then use the following code
to browse around the images (and zoom in/out)
from appuifw import *
from key_codes import *
from graphics import Image
import e32

app.screen = 'full'
app.body = c= Canvas()

x, y, z = 10*256, 24*256, 11
dirname = u'C:\\system\\data\\gmap\\'  # where I save the tile images

def draw():
    gx, ox = divmod(x, 256)
    gy, oy = divmod(y, 256)
    f = dirname + '%s-%s-%s.gif' % (z,gy,gx)
    c.blit(Image.open(f), target=(-ox,-oy))

    if ox > 80:
        f = dirname + '%s-%s-%s.gif' % (z,gy,gx+1)
        c.blit(Image.open(f), target=(256-ox,-oy))
    if oy > 48:
        f = dirname + '%s-%s-%s.gif' % (z,gy+1,gx)
        c.blit(Image.open(f), target=(-ox,256-oy))
    if ox > 80 and oy > 48:
        f = dirname + '%s-%s-%s.gif' % (z,gy+1,gx+1)
        c.blit(Image.open(f), target=(256-ox,256-oy))

def move(dx,dy):
    global x, y
    x += dx * 50
    y += dy * 50
    draw()

def zoomin():
    global x,y,z
    x = x*2 + 88
    y = y*2 + 104
    z = z-1
    draw()

def zoomout():
    global x,y,z
    x = x/2 - 44
    y = y/2 - 52
    z = z+1
    draw()

c.bind(EKeyRightArrow,lambda:move(1, 0))
c.bind(EKeyLeftArrow,lambda:move(-1, 0))
c.bind(EKeyUpArrow,lambda:move(0, -1))
c.bind(EKeyDownArrow,lambda:move(0, 1))
c.bind(EKeySelect, zoomin)
c.bind(EKeyStar, zoomout)

running = 1
def quit():
    global running
    running = 0
app.exit_key_handler= quit

draw()
while running:
    e32.ao_sleep(0.1)

I put a bit more explanation in Nokia's forum here. (Newer version is available)
http://discussion.forum.nokia.com/forum/showthread.php?s=&postid=153609
Also see the screenshot here
http://flickr.com/photos/korakot/30189624/

New camera module

A few days ago, I posted an example of how to take
a photo with py_s60 1.1.0. But now, a new and better
version (1.1.3) is released. The camera module has
improved significantly.

Now it can
- use different sizes (640x480 and 160x120 in my case)
- use zoom (0 or 1 in my case)
- take photos at 12, 16 or 24-bit color ('RGB12', 'RGB16', 'RGB')
- using flash ('none', 'auto', 'forced', 'fill_in', 'red_eye_reduce')
- set white-balance and exposure (I use 'auto' for both,
but sometimes I may use 'night' exposure)
- return an image object which can save in 'jpg' or 'png' format

You can see that these have good default values
 # copy from camera.py
def take_photo(
  mode='RGB16',
  size=(640, 480),
  zoom=0,
  flash='none',
  exposure='auto',
  white_balance='auto'):

So the simplest example is
import camera
im = camera.take_photo()  # use all default values
im.save(u'C:\\test.jpg')

You can see what you can set on your phone
from camera import *
print image_modes()
print image_sizes()
print max_zoom()
print flash_modes()
print exposure_modes()
print white_balance_modes()

« Newer Snippets
Older Snippets »
Showing 1-5 of 5 total  RSS