| 1 | |
package org.jaudiotagger.tag.datatype; |
| 2 | |
|
| 3 | |
import org.jaudiotagger.tag.id3.valuepair.ImageFormats; |
| 4 | |
import org.jaudiotagger.tag.reference.PictureTypes; |
| 5 | |
|
| 6 | |
import javax.imageio.ImageIO; |
| 7 | |
import javax.imageio.stream.ImageInputStream; |
| 8 | |
import java.awt.image.BufferedImage; |
| 9 | |
import java.io.IOException; |
| 10 | |
import java.io.ByteArrayInputStream; |
| 11 | |
import java.io.RandomAccessFile; |
| 12 | |
import java.io.File; |
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | 231 | public class Artwork |
| 18 | |
{ |
| 19 | |
private byte[] binaryData; |
| 20 | |
private String mimeType; |
| 21 | |
private String description; |
| 22 | |
private boolean isLinked; |
| 23 | |
private String imageUrl; |
| 24 | |
private int pictureType; |
| 25 | |
|
| 26 | |
public byte[] getBinaryData() |
| 27 | |
{ |
| 28 | 1491421 | return binaryData; |
| 29 | |
} |
| 30 | |
|
| 31 | |
public void setBinaryData(byte[] binaryData) |
| 32 | |
{ |
| 33 | 207 | this.binaryData = binaryData; |
| 34 | 207 | } |
| 35 | |
|
| 36 | |
public String getMimeType() |
| 37 | |
{ |
| 38 | 89 | return mimeType; |
| 39 | |
} |
| 40 | |
|
| 41 | |
public void setMimeType(String mimeType) |
| 42 | |
{ |
| 43 | 231 | this.mimeType = mimeType; |
| 44 | 231 | } |
| 45 | |
|
| 46 | |
public String getDescription() |
| 47 | |
{ |
| 48 | 12 | return description; |
| 49 | |
} |
| 50 | |
|
| 51 | |
public void setDescription(String description) |
| 52 | |
{ |
| 53 | 80 | this.description = description; |
| 54 | 80 | } |
| 55 | |
|
| 56 | |
public BufferedImage getImage() throws IOException |
| 57 | |
{ |
| 58 | 98 | ByteArrayInputStream bais = new ByteArrayInputStream(getBinaryData()); |
| 59 | 98 | ImageInputStream iis = ImageIO.createImageInputStream(bais); |
| 60 | 98 | BufferedImage bi = ImageIO.read(iis); |
| 61 | 98 | return bi; |
| 62 | |
} |
| 63 | |
|
| 64 | |
public boolean isLinked() |
| 65 | |
{ |
| 66 | 4 | return isLinked; |
| 67 | |
} |
| 68 | |
|
| 69 | |
public void setLinked(boolean linked) |
| 70 | |
{ |
| 71 | 24 | isLinked = linked; |
| 72 | 24 | } |
| 73 | |
|
| 74 | |
public String getImageUrl() |
| 75 | |
{ |
| 76 | 0 | return imageUrl; |
| 77 | |
} |
| 78 | |
|
| 79 | |
public void setImageUrl(String imageUrl) |
| 80 | |
{ |
| 81 | 24 | this.imageUrl = imageUrl; |
| 82 | 24 | } |
| 83 | |
|
| 84 | |
public int getPictureType() |
| 85 | |
{ |
| 86 | 65 | return pictureType; |
| 87 | |
} |
| 88 | |
|
| 89 | |
public void setPictureType(int pictureType) |
| 90 | |
{ |
| 91 | 203 | this.pictureType = pictureType; |
| 92 | 203 | } |
| 93 | |
|
| 94 | |
public void setFromFile(File file) throws IOException |
| 95 | |
{ |
| 96 | 55 | RandomAccessFile imageFile = new RandomAccessFile(file, "r"); |
| 97 | 55 | byte[] imagedata = new byte[(int) imageFile.length()]; |
| 98 | 55 | imageFile.read(imagedata); |
| 99 | 55 | imageFile.close(); |
| 100 | |
|
| 101 | 55 | setBinaryData(imagedata); |
| 102 | 55 | setMimeType(ImageFormats.getMimeTypeForBinarySignature(imagedata)); |
| 103 | 55 | setPictureType(PictureTypes.DEFAULT_ID); |
| 104 | |
|
| 105 | 55 | } |
| 106 | |
|
| 107 | |
public static Artwork createArtworkFromFile(File file) throws IOException |
| 108 | |
{ |
| 109 | 54 | Artwork artwork = new Artwork(); |
| 110 | 54 | artwork.setFromFile(file); |
| 111 | 54 | return artwork; |
| 112 | |
} |
| 113 | |
} |