-
Image size reduction
I'm storing the image in SQL database field as Image. From this image, I'm reducing its size to fit into visitors pass. But the clarity is lost. Here is the code that I' using
public static BufferedImage resizeAWT(BufferedImage src, double factorX, double factorY) {
int w = src.getWidth();
int h = src.getHeight();
int newW = (int)(Math.floor(factorX * w));
int newH = (int)(Math.floor(factorY * h));
Image temp = src.getScaledInstance(newW, newH, Image.SCALE_AREA_AVERAGING);
BufferedImage tgt = createBlankImage(src, newW, newH);
Graphics2D g = tgt.createGraphics();
g.drawImage(temp, 0, 0, null);
g.dispose();
return tgt;
}
//Uses image to create another image of the same "type", but of a factored size
public static BufferedImage createBlankImage(BufferedImage src, int w, int h) {
int type = src.getType();
if (type != BufferedImage.TYPE_CUSTOM)
return new BufferedImage(w, h, type);
else {
ColorModel cm = src.getColorModel();
WritableRaster raster = src.getRaster().createCompatibleWritableRaster(w, h);
boolean isRasterPremultiplied = src.isAlphaPremultiplied();
return new BufferedImage(cm, raster, isRasterPremultiplied, null);
}
}
.....
BufferedImage image3 = resizeAWT(bi1, 0.25, 0.25);
Is there any better method of reducing the size so that clarity is not lost?
-
Well.... for scaling an image there's a much easier way. The Image class has a getScaledInstance which will scale an image.
You can do something like:
Code:
someImage = someImage.getScaledInstance(desiredWidth, desiredHeight, Image.SCALE_SMOOTH);
[EDIT] Sorry, I see you used that. But perhaps the SCALE_SMOOTH was what you were looking for.
Similar Threads
-
By James Graham in forum .NET
Replies: 4
Last Post: 10-23-2011, 02:47 PM
-
Replies: 1
Last Post: 01-09-2006, 12:00 PM
-
By xsouldeath in forum Java
Replies: 0
Last Post: 12-10-2005, 10:56 PM
-
By Micrologix in forum VB Classic
Replies: 5
Last Post: 12-16-2002, 06:50 PM
-
Replies: 3
Last Post: 08-30-2001, 11:45 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks