Converting transparent GIF to JPEG via servlet


    Sponsored Links


  • 1. Customizing a JTabbedPane?
    Hi, Some time ago I spent some time investigating how I could add a 'close' button to the tabs of Components in a JTabbedPane, (eg. tabs in Firefox browser) however I gave up unsuccesful. Could someone provide some hints on how to approach this 'problem'? Thanks! -- Luc Van Bogaert
  • 2. Tetris applet
    Hello all, <disclaimer> >From all of my lurking about the c.l.j.* groups, I believe this is where I should post this question(at least I hope so). If not, please direct me to the proper group. Thanks. </disclaimer> I am fairly new to java(i.e. I have been doing some server-side programming/database related programming for a while, but haven't gotten into the graphical stuff) and especially new to threads. I am considering making a *simple* Tetris applet, and I had a few questions. 1. What sort of array (2 dimensional) should I use for the game board/ play area? I was thinking of boolean[][] so that I could easily know if any particular spot in the grid had a 'brick' in it. 2. I was thinking of using an array of Point objects to store the information on the individual tetris pieces (tetraminos?). Is this a good approach, or has someone else found a better way? 3. Should I use a single thread for the entire applet or could I seperate the threads into one controlling the piece moving downward/ checking for bottom collision and one controlling the piece rotating/ moving horizontally? I think one thread would be the best approach, but I'm not sure. 4. Should I break this down into seperate classes for the game board and tetraminos? Should I break it down further than that? 5. Any other suggestions are GREATLY appreciated! Thanks in advance for any and all help. HightowerC
  • 3. is this normal?
    Hi to everyone, I had installed jdk 1.5.0_10 196Mo Then Sun's update came on adding: 60 Mo for jre 1.5.0_11 60 Mo for jre 1.6.0_01 witch brings up the jre folder up to 206Mo witch brings up the java folder up to 350Mo with the jdk Suns improves or just talk much more? Thanks for your attention. Jean Pierre Daviau

Converting transparent GIF to JPEG via servlet

Postby john_pallozzi » Sun, 01 May 2005 07:06:36 GMT


Using JAI I'm writing a servlet to decode a transparent GIF and write
it to the output stream as an encoded JPEG. I can't quite get it to
work. I either get a broken image or a solid color. Below is my source
code. Any help would be greatly appriciated.


John P.

package leads;

import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.sql.*;
import oracle.sql.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.color.*;
import java.awt.image.renderable.*;

public class GetImageConveter extends HttpServlet
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
System.out.println("YOU GOT HERE - VERY BEGINNING");
Statement stmt = null;
ResultSet result = null;
String id = req.getParameter("id");
System.out.println("YOU GOT HERE - ID: " + id);
if (id == null || id.trim().length() == 0)

String query = "select img_blob from lds_image where id = " + id;
Connection conn = LeadsUtil.getConnection();
InputStream is = null;

stmt = conn.createStatement();
result = stmt.executeQuery(query);
if (!
throw new Exception("Debug: cannot not fetch image from db");

is = result.getBinaryStream(1);
System.out.println("YOU GOT HERE 1");
ForwardSeekableStream Fstream = new ForwardSeekableStream(is);
String[] names = ImageCodec.getDecoderNames(Fstream);

for(int i = 0; i < names.length; i++){
System.out.println("STREAM TYPE: " + names[i]);

ImageEncoder imgEnc = null;
ImageDecoder decoder =
RenderedImage img = decoder.decodeAsRenderedImage();
imgEnc = ImageCodec.createImageEncoder("JPEG",
resp.getOutputStream(), null);

if(img.getColorModel().hasAlpha() == true){
Raster img_raster = decoder.decodeAsRaster();
int height = img_raster.getHeight();
int width = img_raster.getWidth();
Rectangle img_rect = new Rectangle(0, 0, width, height);
WritableRaster writable_raster =
BufferedImage bi = new BufferedImage(img.getColorModel(),
writable_raster, false, null);
int counter = 0;
for(int a = 0; a < width; a++){
for(int b = 0; b < height; b++){
int rgba = bi.getRGB(a, b);
int red = (rgba >> 16) & 0xff;
int green = (rgba >> 8) & 0xff;
int blue = rgba & 0xff;
int alpha = (rgba >> 24) & 0xff;
bi.setRGB(a,b,((red << 16) | (green << 8) | blue));
System.out.println("Pixel Counter: " +
System.out.println("Second Branch");
width = bi.getWidth();
height = bi.getHeight();
// BufferedImage rgbImage = new BufferedImage(width,
height, BufferedImage.TYPE_INT_RGB);
BufferedImage rgbImage = new BufferedImage(width, height,

Similar Threads:

1.convert jpeg to gif

2.Table Background Transparent GIF


Table Background & Transparent GIF are the new trend to protect your
pics. Is it efficient or can people still go around and take my pics?

thanks to get transparent index from gif

4.Transparent gif in JLabel


I have set a gif image with a transparent bacground as an icon for a 
JLabel. However, this background is shown white, and not transparent.

Is it possible to make it transparent?


5.converting java to jpeg

I have to programmatically convert an HTML file to a jpeg one (no
commercial products).
Any suggestions will be very appreciated...
Thanks to all

6. How to convert HTML page to gif

7. How to convert JPEG to binary using Java & save into database

8. jsp, open gif file and convert it to BufferedImage

Return to JAVA


Who is online

Users browsing this forum: No registered users and 48 guest