Ciao Ho un'immagine del codice QR, e voglio ridimensionarla, quando provo a ridimensionarla a una piccola immagine usando questo codice, ottengo sempre un'immagine sfocata, e il codice QR non è più valido quando lo scannerizzo , ma funziona bene quando ho ridimensionare ad un grande immagini di dimensioni con lo stesso codice:come ridimensionare l'immagine in java?
public BufferedImage getScaledInstance(BufferedImage img,
int targetWidth,
int targetHeight,
Object hint,
boolean higherQuality)
{
int type = (img.getTransparency() == Transparency.OPAQUE) ?
BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB;
BufferedImage ret = (BufferedImage)img;
int w, h;
if (higherQuality) {
// Use multi-step technique: start with original size, then
// scale down in multiple passes with drawImage()
// until the target size is reached
w = img.getWidth();
h = img.getHeight();
} else {
// Use one-step technique: scale directly from original
// size to target size with a single drawImage() call
w = targetWidth;
h = targetHeight;
}
do {
if (higherQuality && w > targetWidth) {
w /= 2;
if (w < targetWidth) {
w = targetWidth;
}
}
if (higherQuality && h > targetHeight) {
h /= 2;
if (h < targetHeight) {
h = targetHeight;
}
}
BufferedImage tmp = new BufferedImage(w, h, type);
Graphics2D g2 = tmp.createGraphics();
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, hint);
// g2.setRenderingHint(RenderingHints.KEY_DITHERING, hint);
g2.drawImage(ret, 0, 0, w, h, null);
g2.dispose();
ret = tmp;
} while (w != targetWidth || h != targetHeight);
return ret;
}
qual è il problema, non esattamente a capire, per favore mi dia almeno un accenno, grazie
Non hai mostrato un dettaglio fondamentale - quello suggerimento interpolazione si sta impostando! –
grazie mille, il mio suggerimento di interpolazione è RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR, ho provato con tutti i valori possibili, ancora non ha funzionato – Walllzzz