Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-26-2010, 08:18 AM   PM User | #1
mahender
New to the CF scene

 
Join Date: Apr 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
mahender is an unknown quantity at this point
converting JAVA code to JSP

Hi every body I am new to JSP programing.I have a java code to create an image I am unable to convert that cod ein to JSP.Can any body help me, every work can be appreciated.
Code:
Here is my JAVA code
import java.awt.image.*;
import java.io.*;
import java.util.*;
import javax.imageio.*;
import javax.swing.*;
 
public class ExampleCreate {
    public static void main(String[] args) throws Exception {
        final int H = 2530;
        final int W = 3630;
        int[] pixels = createPixels(W*H);
        BufferedImage image = toImage(pixels, W, H);
        display(image);
        ImageIO.write(image, "jpg", new File("static.jpg"));
    }
  
  static int[] createPixels(int size) throws Exception{
       int[] pixels = new int[size];
       int[] colors = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,102,104,106,108,110,112,114,116,118,120,122,124,126,0xff0000,0x00ff00,0x0000ff,0x00000f,0xfff000,0xff00ff,0xffffff,0xf00000};
       FileReader fr = new FileReader("SST.tmp");
       BufferedReader br = new BufferedReader(fr);
       String text = br.readLine();
       int c = 0;
       for(int i = 0; i < size; ++ i){
       		text = br.readLine();
       		c = Integer.parseInt(text);
       		if(c < 0)
       			c = 0;
       		pixels[i] = colors[c];
       }
       br.close();
   return pixels;
 }
 
    static BufferedImage toImage(int[] pixels, int w, int h) {
        DataBuffer db = new DataBufferInt(pixels, w*h);
        WritableRaster raster = Raster.createPackedRaster(db,
            w, h, w, new int[] {0xff0000, 0xff00, 0xff}, null);
        ColorModel cm = new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
        return new BufferedImage(cm, raster, false, null);
    }
 
    static void display(BufferedImage image) {
        final JFrame f = new JFrame("");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.getContentPane().add(new JLabel(new ImageIcon(image)));
        f.pack();
        SwingUtilities.invokeLater(new Runnable(){
            public void run() {
                f.setLocationRelativeTo(null);
                f.setVisible(true);
            }
        });
    }
}
thanks&regards
Mahender
mahender is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:35 PM.


Advertisement
Log in to turn off these ads.