01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: http://www.apache.org/licenses/LICENSE-2.0
10:
11: Unless required by applicable law or agreed to in writing, software
12: distributed under the License is distributed on an "AS IS" BASIS,
13: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: See the License for the specific language governing permissions and
15: limitations under the License.
16: ==================================================================== */
17: package org.apache.poi.hslf.blip;
18:
19: import org.apache.poi.hslf.model.Picture;
20: import org.apache.poi.hslf.exceptions.HSLFException;
21:
22: import javax.imageio.ImageIO;
23: import java.awt.image.BufferedImage;
24: import java.io.ByteArrayInputStream;
25: import java.io.IOException;
26:
27: /**
28: * Represents a PNG picture data in a PPT file
29: *
30: * @author Yegor Kozlov
31: */
32: public class PNG extends Bitmap {
33:
34: /**
35: * @return PNG data
36: */
37: public byte[] getData() {
38: byte[] data = super .getData();
39: try {
40: //PNG created on MAC may have a 16-byte prefix which prevents successful reading.
41: //Just cut it off!.
42: BufferedImage bi = ImageIO.read(new ByteArrayInputStream(
43: data));
44: if (bi == null) {
45: byte[] png = new byte[data.length - 16];
46: System.arraycopy(data, 16, png, 0, png.length);
47: data = png;
48: }
49: } catch (IOException e) {
50: throw new HSLFException(e);
51: }
52: return data;
53: }
54:
55: /**
56: * @return type of this picture
57: * @see org.apache.poi.hslf.model.Picture#PNG
58: */
59: public int getType() {
60: return Picture.PNG;
61: }
62:
63: /**
64: * PNG signature is <code>0x6E00</code>
65: *
66: * @return PNG signature (<code>0x6E00</code>)
67: */
68: public int getSignature() {
69: return 0x6E00;
70: }
71: }
|