Προς το περιεχόμενο

about servlets and images


Elise23

Προτεινόμενες αναρτήσεις

Δημοσ.

Θα ήθελα να μου πείτε πως θα διαβάσει ένα servlet την εικόνα που εχει φορτώσει ο χρήστης στον server για να κάνει μια επεξεργασία. Παρακάτω έχω βρει κώδικα για decolorize. Σε αυτό τον κώδικα που θα ορίσω τη διαδρομή που βρίσκεται η εικόνα και πως ορίζεται ή μήπως θα ορίσω τη διαδρομή της εικόνας στο container (web.xml);

 

import java.awt.*;

import java.awt.image.*;

import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;

import Acme.JPM.Encoders.*;

import image.GrayscaleImageFilter;

 

public class DeColorize extends HttpServlet {

 

public void doGet(HttpServletRequest req, HttpServletResponse res)

 

throws ServletException, IOException {

 

 

res.setContentType("image/gif");

ServletOutputStream out = res.getOutputStream();

// Get the image location from the path info

String source = req.getPathTranslated();

if (source == null) {

throw new ServletException("Extra path information " +

"must point to an image");

}

// Construct an unshown frame

// No addNotify() because its peer isn't needed

Frame frame = new Frame();

// Load the image

Image image = Toolkit.getDefaultToolkit().getImage(source);

MediaTracker mt = new MediaTracker(frame);

mt.addImage(image, 0);

try {

mt.waitForAll();

}

catch (InterruptedException e) {

getServletContext().log(e, "Interrupted while loading image");

throw new ServletException(e.getMessage());

}

// Get the size of the image

 

int width = image.getWidth(frame);

int height = image.getHeight(frame);

// Create an image to match, run through a filter

Image filtered = frame.createImage(

new FilteredImageSource(image.getSource(),

new GrayscaleImageFilter()));

// Encode and return the filtered image

GifEncoder encoder = new GifEncoder(filtered, out);

encoder.encode();

}

}

Αρχειοθετημένο

Αυτό το θέμα έχει αρχειοθετηθεί και είναι κλειστό για περαιτέρω απαντήσεις.

  • Δημιουργία νέου...