PageRenderTime 94ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/ppt/scratchpad/src/org/apache/poi/hslf/blip/Bitmap.java

https://github.com/minstrelsy/POI-Android
Java | 88 lines | 38 code | 13 blank | 37 comment | 2 complexity | f72f796e1feb235d8e01c9a94aa66ce6 MD5 | raw file
  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.hslf.usermodel.PictureData;
  17. import org.apache.poi.poifs.filesystem.DocumentInputStream;
  18. import and.awt.BufferedImage;
  19. import android.graphics.BitmapFactory;
  20. import android.util.Log;
  21. import com.poi.poiandroid.Utils;
  22. import java.io.IOException;
  23. import java.io.ByteArrayOutputStream;
  24. import java.io.InputStream;
  25. /**
  26. * Represents a bitmap picture data: JPEG or PNG.
  27. * The data is not compressed and the exact file content is written in the stream.
  28. *
  29. * @author Yegor Kozlov
  30. */
  31. public abstract class Bitmap extends PictureData {
  32. public byte[] getData(){
  33. Log.d("BitmapPainter", "Start Paint");
  34. DocumentInputStream is = getStream();
  35. byte[] imgdata = new byte[imgsize - 17];
  36. try {
  37. if (rawdataPos > is.position()) {
  38. Log.d("Bitmap", "rawdataPos > is.position()");
  39. is.skip(rawdataPos - is.position() + 17);
  40. } else {
  41. is.reset();
  42. is.skip(rawdataPos + 17);
  43. }
  44. is.read(imgdata, 0, imgdata.length);
  45. } catch (IOException e) {
  46. e.printStackTrace();
  47. }
  48. // final BitmapFactory.Options options = new BitmapFactory.Options();
  49. // options.inJustDecodeBounds = true;
  50. // BitmapFactory.decodeByteArray(imgdata, 0, imgdata.length, options);
  51. //
  52. // // Calculate inSampleSize
  53. // options.inSampleSize = Utils.calculateInSampleSize(options, 480, 800);
  54. //
  55. // // Decode bitmap with inSampleSize set
  56. // options.inJustDecodeBounds = false;
  57. // Bitmap bm = BitmapFactory.decodeByteArray(imgdata, 0, imgdata.length, options);
  58. // Log.d("BitmapPainter", "bm: " + bm);
  59. // img = new BufferedImage(bm);
  60. // byte[] rawdata = getRawData();
  61. // byte[] imgdata = new byte[rawdata.length-17];
  62. // System.arraycopy(rawdata, 17, imgdata, 0, imgdata.length);
  63. return imgdata;
  64. }
  65. public void setData(byte[] data) throws IOException {
  66. ByteArrayOutputStream out = new ByteArrayOutputStream();
  67. byte[] checksum = getChecksum(data);
  68. out.write(checksum);
  69. out.write(0);
  70. out.write(data);
  71. setRawData(out.toByteArray());
  72. }
  73. }