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