1 /*
2 * JDiskCatalog
3 *
4 * Copyright 2007 Przemek Więch
5 *
6 * This file is part of JDiskCatalog.
7 *
8 * JDiskCatalog is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 package net.sf.jdiskcatalog.analysis;
24
25 import java.awt.image.RenderedImage;
26 import java.io.ByteArrayInputStream;
27 import java.io.ByteArrayOutputStream;
28 import java.io.IOException;
29
30 import javax.imageio.ImageIO;
31
32 /**
33 * Contains an image and its JPEG encoded form.
34 *
35 * @author Przemek Więch <pwiech@losthive.org>
36 * @version $Id$
37 */
38 public class JpegImage
39 {
40 private byte[] data = null;
41 private RenderedImage image = null;
42
43 public JpegImage(byte[] data) throws IOException
44 {
45 this.data = data;
46 image = ImageIO.read(new ByteArrayInputStream(data));
47 }
48
49 public JpegImage(RenderedImage image)
50 {
51 this.image = image;
52 }
53
54 public byte[] getData()
55 {
56 if (data == null)
57 {
58 ByteArrayOutputStream stream = new ByteArrayOutputStream();
59 try
60 {
61 ImageIO.write(image, "jpeg", stream);
62 data = stream.toByteArray();
63 }
64 catch (IOException e)
65 {
66 e.printStackTrace();
67 }
68 }
69 return data;
70 }
71
72 public RenderedImage getImage()
73 {
74 return image;
75 }
76 }