Methods Summary |
---|
public static org.jaudiotagger.tag.images.StandardImageHandler | getInstanceOf()
if(instance==null)
{
instance = new StandardImageHandler();
}
return instance;
|
public boolean | isMimeTypeWritable(java.lang.String mimeType)
Iterator<ImageWriter> writers = ImageIO.getImageWritersByMIMEType(mimeType);
return writers.hasNext();
|
public void | makeSmaller(Artwork artwork, int size)Resize image using Java 2D
Image srcImage = (Image)artwork.getImage();
int w = srcImage.getWidth(null);
int h = srcImage.getHeight(null);
// Determine the scaling required to get desired result.
float scaleW = (float) size / (float) w;
float scaleH = (float) size / (float) h;
//Create an image buffer in which to paint on, create as an opaque Rgb type image, it doesnt matter what type
//the original image is we want to convert to the best type for displaying on screen regardless
BufferedImage bi = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB);
// Set the scale.
AffineTransform tx = new AffineTransform();
tx.scale(scaleW, scaleH);
// Paint image.
Graphics2D g2d = bi.createGraphics();
g2d.drawImage(srcImage, tx, null);
g2d.dispose();
if(artwork.getMimeType()!=null && isMimeTypeWritable(artwork.getMimeType()))
{
artwork.setBinaryData(writeImage(bi,artwork.getMimeType()));
}
else
{
artwork.setBinaryData(writeImageAsPng(bi));
}
|
public void | reduceQuality(Artwork artwork, int maxSize)Resize the image until the total size require to store the image is less than maxsize
while(artwork.getBinaryData().length > maxSize)
{
Image srcImage = (Image)artwork.getImage();
int w = srcImage.getWidth(null);
int newSize = w /2;
makeSmaller(artwork,newSize);
}
|
public void | showReadFormats()Show read formats
On Windows supports png/jpeg/bmp/gif
String[] formats = ImageIO.getReaderMIMETypes();
for(String f:formats)
{
System.out.println("r"+f);
}
|
public void | showWriteFormats()Show write formats
On Windows supports png/jpeg/bmp
String[] formats = ImageIO.getWriterMIMETypes();
for(String f:formats)
{
System.out.println(f);
}
|
public byte[] | writeImage(java.awt.image.BufferedImage bi, java.lang.String mimeType)Write buffered image as required format
Iterator<ImageWriter> writers = ImageIO.getImageWritersByMIMEType(mimeType);
if(writers.hasNext())
{
ImageWriter writer = writers.next();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
writer.setOutput(ImageIO.createImageOutputStream(baos));
writer.write(bi);
return baos.toByteArray();
}
throw new IOException("Cannot write to this mimetype");
|
public byte[] | writeImageAsPng(java.awt.image.BufferedImage bi)
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(bi, ImageFormats.MIME_TYPE_PNG,baos);
return baos.toByteArray();
|