public static Artwork createArtworkFromFile(File file) throws IOException { Artwork artwork = new Artwork(); artwork.setFromFile(file); return artwork; }
/** * Creates an {@link AsfTagCoverField} from given artwork * * @param artwork artwork to create a ASF field from. * @return ASF field capable of storing artwork. */ public AsfTagCoverField createField(final Artwork artwork) { return new AsfTagCoverField(artwork.getBinaryData(), artwork.getPictureType(), artwork.getDescription(), artwork.getMimeType()); }
/** * Resize the image until the total size require to store the image is less than maxsize * * @param artwork * @param maxSize * @throws IOException */ public static void reduceQuality(Artwork artwork, int maxSize) throws IOException { while (artwork.getBinaryData().length > maxSize) { Image srcImage = artwork.getImage(); int w = srcImage.getWidth(null); int newSize = w / 2; makeSmaller(artwork, newSize); } }
public static Artwork createArtworkFromMetadataBlockDataPicture(MetadataBlockDataPicture coverArt) { Artwork artwork = new Artwork(); artwork.setFromMetadataBlockDataPicture(coverArt); return artwork; }
if (artwork.isLinked()) { return new MetadataBlockDataPicture( Utils.getDefaultBytes(artwork.getImageUrl(), TextEncoding.CHARSET_ISO_8859_1), artwork.getPictureType(), MetadataBlockDataPicture.IMAGE_IS_URL, "", BufferedImage image; try { image = artwork.getImage(); } catch (IOException ioe) { throw new FieldDataInvalidException("Unable to createField bufferd image from the image"); return new MetadataBlockDataPicture(artwork.getBinaryData(), artwork.getPictureType(), artwork.getMimeType(), artwork.getDescription(), image.getWidth(), image.getHeight(),
public TagField createField(Artwork artwork) throws FieldDataInvalidException { AbstractID3v2Frame frame = createFrame(getFrameAndSubIdFromGenericKey(FieldKey.COVER_ART).getFrameId()); FrameBodyAPIC body = (FrameBodyAPIC) frame.getBody(); body.setObjectValue(DataTypes.OBJ_PICTURE_DATA, artwork.getBinaryData()); body.setObjectValue(DataTypes.OBJ_PICTURE_TYPE, artwork.getPictureType()); body.setObjectValue(DataTypes.OBJ_MIME_TYPE, artwork.getMimeType()); body.setObjectValue(DataTypes.OBJ_DESCRIPTION, ""); return frame; }
public List<Artwork> getArtworkList() { List<TagField> coverartList = getFields(FieldKey.COVER_ART); List<Artwork> artworkList = new ArrayList<Artwork>(coverartList.size()); for (TagField next : coverartList) { FrameBodyAPIC coverArt = (FrameBodyAPIC) ((AbstractID3v2Frame) next).getBody(); Artwork artwork = new Artwork(); artwork.setMimeType(coverArt.getMimeType()); artwork.setPictureType(coverArt.getPictureType()); if (coverArt.isImageUrl()) { artwork.setLinked(true); artwork.setImageUrl(coverArt.getImageUrl()); } else { artwork.setBinaryData(coverArt.getImageData()); } artworkList.add(artwork); } return artworkList; }
public void setFromFile(File file) throws IOException { RandomAccessFile imageFile = new RandomAccessFile(file, "r"); byte[] imagedata = new byte[(int) imageFile.length()]; imageFile.read(imagedata); imageFile.close(); setBinaryData(imagedata); setMimeType(ImageFormats.getMimeTypeForBinarySignature(imagedata)); setDescription(""); setPictureType(PictureTypes.DEFAULT_ID); }
/** * Populate Artwork from MetadataBlockDataPicture as used by Flac and VorbisComment * * @param coverArt */ public void setFromMetadataBlockDataPicture(MetadataBlockDataPicture coverArt) { setMimeType(coverArt.getMimeType()); setDescription(coverArt.getDescription()); setPictureType(coverArt.getPictureType()); if (coverArt.isImageUrl()) { setLinked(coverArt.isImageUrl()); setImageUrl(coverArt.getImageUrl()); } else { setBinaryData(coverArt.getImageData()); } }
/** * @return list of artwork images */ public List<Artwork> getArtworkList() { List<Artwork> artworkList = new ArrayList<Artwork>(1); //Read Old Format if (getArtworkBinaryData() != null & getArtworkBinaryData().length > 0) { Artwork artwork = new Artwork(); artwork.setMimeType(getArtworkMimeType()); artwork.setBinaryData(getArtworkBinaryData()); artworkList.add(artwork); } //New Format (Supports Multiple Images) List<TagField> metadataBlockPics = this.get(VorbisCommentFieldKey.METADATA_BLOCK_PICTURE); for (TagField tagField : metadataBlockPics) { try { byte[] imageBinaryData = Base64Coder.decode(((TagTextField) tagField).getContent()); MetadataBlockDataPicture coverArt = new MetadataBlockDataPicture(ByteBuffer.wrap(imageBinaryData)); Artwork artwork = Artwork.createArtworkFromMetadataBlockDataPicture(coverArt); artworkList.add(artwork); } catch (IOException ioe) { throw new RuntimeException(ioe); } catch (InvalidFrameException ife) { throw new RuntimeException(ife); } } return artworkList; }
/** * Resize image using Java 2D * * @param artwork * @param size * @throws java.io.IOException */ private static void makeSmaller(Artwork artwork, int size) throws IOException { Image srcImage = 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 List<Artwork> getArtworkList() { List<TagField> coverartList = get(Mp4FieldKey.ARTWORK); List<Artwork> artworkList = new ArrayList<Artwork>(coverartList.size()); for (TagField next : coverartList) { Mp4TagCoverField mp4CoverArt = (Mp4TagCoverField) next; Artwork artwork = new Artwork(); artwork.setBinaryData(mp4CoverArt.getData()); artwork.setMimeType(Mp4TagCoverField.getMimeTypeForImageType(mp4CoverArt.getFieldType())); artworkList.add(artwork); } return artworkList; }
public BufferedImage getImage() throws IOException { ByteArrayInputStream bais = new ByteArrayInputStream(getBinaryData()); ImageInputStream iis = ImageIO.createImageInputStream(bais); BufferedImage bi = ImageIO.read(iis); return bi; }
for (Artwork artwork : afile.getTag().getArtworkList()) { BufferedImage bi = (BufferedImage) artwork.getImage(); ImageIO.write(bi, "png", outputstream); }
public List<Artwork> getArtworkList() { List<Artwork> artworkList = new ArrayList<Artwork>(images.size()); for (MetadataBlockDataPicture coverArt : images) { Artwork artwork = Artwork.createArtworkFromMetadataBlockDataPicture(coverArt); artworkList.add(artwork); } return artworkList; }
if (artwork.isLinked()) { return new MetadataBlockDataPicture( Utils.getDefaultBytes(artwork.getImageUrl(), TextEncoding.CHARSET_ISO_8859_1), artwork.getPictureType(), MetadataBlockDataPicture.IMAGE_IS_URL, "", BufferedImage image; try { image = artwork.getImage(); } catch (IOException ioe) { throw new FieldDataInvalidException("Unable to create MetadataBlockDataPicture from buffered:" + ioe.getMessage()); return new MetadataBlockDataPicture(artwork.getBinaryData(), artwork.getPictureType(), artwork.getMimeType(), artwork.getDescription(), image.getWidth(), image.getHeight(),
public TagField createField(Artwork artwork) throws FieldDataInvalidException { AbstractID3v2Frame frame = createFrame(getFrameAndSubIdFromGenericKey(FieldKey.COVER_ART).getFrameId()); FrameBodyAPIC body = (FrameBodyAPIC) frame.getBody(); body.setObjectValue(DataTypes.OBJ_PICTURE_DATA, artwork.getBinaryData()); body.setObjectValue(DataTypes.OBJ_PICTURE_TYPE, artwork.getPictureType()); body.setObjectValue(DataTypes.OBJ_MIME_TYPE, artwork.getMimeType()); body.setObjectValue(DataTypes.OBJ_DESCRIPTION, ""); return frame; }
/** * {@inheritDoc} */ public List<Artwork> getArtworkList() { List<TagField> coverartList = getFields(FieldKey.COVER_ART); List<Artwork> artworkList = new ArrayList<Artwork>(coverartList.size()); for (TagField next : coverartList) { FrameBodyAPIC coverArt = (FrameBodyAPIC) ((AbstractID3v2Frame) next).getBody(); Artwork artwork = new Artwork(); artwork.setMimeType(coverArt.getMimeType()); artwork.setPictureType(coverArt.getPictureType()); if (coverArt.isImageUrl()) { artwork.setLinked(true); artwork.setImageUrl(coverArt.getImageUrl()); } else { artwork.setBinaryData(coverArt.getImageData()); } artworkList.add(artwork); } return artworkList; }
public void setFromFile(File file) throws IOException { RandomAccessFile imageFile = new RandomAccessFile(file, "r"); byte[] imagedata = new byte[(int) imageFile.length()]; imageFile.read(imagedata); imageFile.close(); setBinaryData(imagedata); setMimeType(ImageFormats.getMimeTypeForBinarySignature(imagedata)); setDescription(""); setPictureType(PictureTypes.DEFAULT_ID); }