codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  converting JAVA code to JSP  Mahender at 06:12 on Monday, April 26, 2010
 

Hi everybody I am new to the JSP programming.
I have a code in java to create an image
I am unable to convert it into a JSP code.
Pleae help me any work can be appreciated
Here is my 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("/forum/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 = 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








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: Need some help with javascript code in Unity!
•  Re: Copy files from one directory to another in a local network
•  Re: number of hours and minutes spent
•  Re: Saving a Picture or Image contained within a Picturebox into Windows Registry
•  Join Apache Lucene EuroCon 2010
•  FREE dating software worth over $350 for free
•  FREE dating software worth over $350 for free
•  running a command in remote machine by using perl
•  converting JAVA code to JSP


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2010