Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

PNG.java 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 org.apache.poi.ddf.EscherBSERecord;
  17. import org.apache.poi.ddf.EscherContainerRecord;
  18. import org.apache.poi.hslf.usermodel.HSLFSlideShow;
  19. import org.apache.poi.sl.image.ImageHeaderPNG;
  20. import org.apache.poi.util.Internal;
  21. import org.apache.poi.util.Removal;
  22. /**
  23. * Represents a PNG picture data in a PPT file
  24. */
  25. public final class PNG extends Bitmap {
  26. /**
  27. * @deprecated Use {@link HSLFSlideShow#addPicture(byte[], PictureType)} or one of it's overloads to create new
  28. * {@link PNG}. This API led to detached {@link PNG} instances (See Bugzilla
  29. * 46122) and prevented adding additional functionality.
  30. */
  31. @Deprecated
  32. @Removal(version = "5.3")
  33. public PNG() {
  34. this(new EscherContainerRecord(), new EscherBSERecord());
  35. }
  36. /**
  37. * Creates a new instance.
  38. *
  39. * @param recordContainer Record tracking all pictures. Should be attached to the slideshow that this picture is
  40. * linked to.
  41. * @param bse Record referencing this picture. Should be attached to the slideshow that this picture is linked to.
  42. */
  43. @Internal
  44. public PNG(EscherContainerRecord recordContainer, EscherBSERecord bse) {
  45. super(recordContainer, bse);
  46. }
  47. @Override
  48. public byte[] getData() {
  49. return new ImageHeaderPNG(super.getData()).extractPNG();
  50. }
  51. @Override
  52. public PictureType getType(){
  53. return PictureType.PNG;
  54. }
  55. /**
  56. * PNG signature is {@code 0x6E00} or {@code 0x6E10}
  57. *
  58. * @return PNG signature ({@code 0x6E00} or {@code 0x6E10})
  59. */
  60. public int getSignature(){
  61. return (getUIDInstanceCount() == 1 ? 0x6E00 : 0x6E10);
  62. }
  63. /**
  64. * Sets the PNG signature - either {@code 0x6E00} or {@code 0x6E10}
  65. */
  66. public void setSignature(int signature) {
  67. switch (signature) {
  68. case 0x6E00:
  69. setUIDInstanceCount(1);
  70. break;
  71. case 0x6E10:
  72. setUIDInstanceCount(2);
  73. break;
  74. default:
  75. throw new IllegalArgumentException(signature+" is not a valid instance/signature value for PNG");
  76. }
  77. }
  78. }