Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

Bitmap.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.hslf.blip;
  16. import java.awt.Dimension;
  17. import java.awt.image.BufferedImage;
  18. import java.io.ByteArrayInputStream;
  19. import java.io.IOException;
  20. import javax.imageio.ImageIO;
  21. import org.apache.poi.ddf.EscherBSERecord;
  22. import org.apache.poi.ddf.EscherContainerRecord;
  23. import org.apache.poi.hslf.usermodel.HSLFPictureData;
  24. import org.apache.poi.hslf.usermodel.HSLFSlideShow;
  25. import org.apache.poi.util.IOUtils;
  26. import org.apache.poi.util.Internal;
  27. import org.apache.poi.util.Removal;
  28. import org.apache.poi.util.Units;
  29. /**
  30. * Represents a bitmap picture data: JPEG or PNG.
  31. * The data is not compressed and the exact file content is written in the stream.
  32. */
  33. public abstract class Bitmap extends HSLFPictureData {
  34. /**
  35. * @deprecated Use {@link HSLFSlideShow#addPicture(byte[], PictureType)} or one of it's overloads to create new
  36. * {@link Bitmap}. This API led to detached {@link Bitmap} instances (See Bugzilla
  37. * 46122) and prevented adding additional functionality.
  38. */
  39. @Deprecated
  40. @Removal(version = "5.3")
  41. public Bitmap() {
  42. this(new EscherContainerRecord(), new EscherBSERecord());
  43. }
  44. /**
  45. * Creates a new instance.
  46. *
  47. * @param recordContainer Record tracking all pictures. Should be attached to the slideshow that this picture is
  48. * linked to.
  49. * @param bse Record referencing this picture. Should be attached to the slideshow that this picture is linked to.
  50. */
  51. @Internal
  52. protected Bitmap(EscherContainerRecord recordContainer, EscherBSERecord bse) {
  53. super(recordContainer, bse);
  54. }
  55. @Override
  56. public byte[] getData(){
  57. byte[] rawdata = getRawData();
  58. int prefixLen = 16*getUIDInstanceCount()+1;
  59. return IOUtils.safelyClone(rawdata, prefixLen, rawdata.length-prefixLen, rawdata.length);
  60. }
  61. @Override
  62. protected byte[] formatImageForSlideshow(byte[] data) {
  63. byte[] checksum = getChecksum(data);
  64. byte[] rawData = new byte[checksum.length * getUIDInstanceCount() + 1 + data.length];
  65. int offset = 0;
  66. System.arraycopy(checksum, 0, rawData, offset, checksum.length);
  67. offset += checksum.length;
  68. if (getUIDInstanceCount() == 2) {
  69. System.arraycopy(checksum, 0, rawData, offset, checksum.length);
  70. offset += checksum.length;
  71. }
  72. offset++;
  73. System.arraycopy(data, 0, rawData, offset, data.length);
  74. return rawData;
  75. }
  76. @Override
  77. public Dimension getImageDimension() {
  78. try {
  79. BufferedImage bi = ImageIO.read(new ByteArrayInputStream(getData()));
  80. return new Dimension(
  81. (int)Units.pixelToPoints(bi.getWidth()),
  82. (int)Units.pixelToPoints(bi.getHeight())
  83. );
  84. } catch (IOException e) {
  85. return new Dimension(200,200);
  86. }
  87. }
  88. }