java left logo
java middle logo
java right logo
 

Home arrow Java ME Tips
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4096
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
How to implement Zoom in and Zoom out E-mail
User Rating: / 110
PoorBest 

This Java tip implements Zoom in and zoom out feature on an Image (Image Zoomer). This tip may help game developers to add various new kinds of appearances in games. This may also be useful for customized J2ME applications developed for mobile handsets.

public Image ZoomIn(Image img) {
    
    Image outImg = null;
    int[] rgbOutput = null;
    
    Graphics g = null;
    int width = 0,height = 0;
    
    try{
        
        width = img.getWidth();
        height = img.getHeight();
        outImg  = Image.createImage(height,width);
        int rgbInput[]=new int[width*height];
        rgbOutput = new int[width*height];
        img.getRGB(rgbInput,0,width,0,0,width,height);
        
        int i,j,k,l;
        k=0;
        int tempArr[][]  new int[height][width];
        
        for(i=0;i<height;i++)
            for(j=0;j<width;j++)
                tempArr[i][j= rgbInput[k++];
        
        k=0;
        for(i=0;i<height;i++) {
            for(j=0;j<width;j++) {
                rgbOutput[k]= tempArr[j][i];
                k++;
            }
        }
        g = outImg.getGraphics();
        
    catch(Exception e){}
    
    return outImg.createRGBImage(rgbOutput,height,width,true);
}

public Image zoomImage(Image img) {
    
    image outImg = null;
    
    int[] rgbOutput = null;
    Graphics g = null;
    int width = 0,height = 0;
    
    try {
        
        width  =  img.getWidth();
        height = img.getHeight();
        
        outImg  = Image.createImage(width<<1,height<<1);
        
        int rgbInput[]=new int[width*height];
        rgbOutput = new int[(width<<1)*(height<<1)];
        
        img.getRGB(rgbInput,0,width,0,0,width,height);
        
        int i,j,k;
        k=0;
        for(i=0;i<(height<<1);i+=2) {
            for(j=0;j<(width<<1);j+=2) {
                rgbOutput[i*(width<<1+ j= rgbInput[k;
                rgbOutput[(i+1)*(width<<1+ j]  = rgbInput[k];
                rgbOutput[i*(width<<1+ j+1]  = rgbInput[k];
                rgbOutput[(i+1)*(width<<1+ j+1]  = rgbInput[k];
                k++;
            }
        }
        
        g = outImg.getGraphics();
    catch(Exception e){}
    
    return outImg.createRGBImage(rgbOutput,width<<1,height<<1,true);
}

 Related Tips


 Related Tips

 
< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.