예제 #1
0
 /** 获得功能表底部背景图片: 底层为BitmapDrawable格式 */
 public MImage getBottomBg() {
   if (isVertical()) {
     if (mBottomBg_v == null) {
       try {
         mBottomBg_v =
             generateMImage(R.drawable.shorcut_slaver, getScreenWidth(), getRealNum(85), 0);
       } catch (OutOfMemoryError e) {
         e.printStackTrace();
         OutOfMemoryHandler.handle();
       }
     }
     return mBottomBg_v;
   } else {
     if (mBottomBg_h == null) {
       try {
         mBottomBg_h =
             generateMImage(R.drawable.shorcut_slaver, getScreenHeight(), getRealNum(85), -90.0f);
       } catch (OutOfMemoryError e) {
         e.printStackTrace();
         OutOfMemoryHandler.handle();
       }
     }
     return mBottomBg_h;
   }
 }
예제 #2
0
 /** 获得功能表底部背景图片:当拖动图标至桌面时的背景效果图 */
 public MImage getMoveToDeskBg() {
   if (isVertical()) {
     if (mMoveToDesk_v == null) {
       try {
         mMoveToDesk_v =
             generateMImage(R.drawable.appfunc_movetodesk, getScreenWidth(), getRealNum(85), 0);
       } catch (OutOfMemoryError e) {
         e.printStackTrace();
         OutOfMemoryHandler.handle();
       }
     }
     return mMoveToDesk_v;
   } else {
     if (mMoveToDesk_h == null) {
       try {
         mMoveToDesk_h =
             generateMImage(
                 R.drawable.appfunc_movetodesk, getScreenHeight(), getRealNum(85), -90.0f);
       } catch (OutOfMemoryError e) {
         e.printStackTrace();
         OutOfMemoryHandler.handle();
       }
     }
     return mMoveToDesk_h;
   }
 }
예제 #3
0
  private void createSingleImageFromMultipleImages(Bitmap bitmap, int mCounter) {
    if (mCounter == 0) {
      try {
        this.mManyBitmapSuperposition =
            Bitmap.createBitmap(
                DeviceInfo.mScreenWidthForPortrait,
                DeviceInfo.mScreenHeightForPortrait,
                bitmap.getConfig());
        this.mCanvas = new Canvas(this.mManyBitmapSuperposition);
      } catch (OutOfMemoryError error) {
        error.printStackTrace();
        System.gc();
      } finally {

      }
    }
    if (this.mCanvas != null) {
      int number = DeviceInfo.mScreenHeightForPortrait / 64;
      if (mCounter >= (mCounter / number) * number
          && mCounter < ((mCounter / number) + SNOW_BLOCK) * number) {
        this.mCanvas.drawBitmap(
            bitmap, (float) ((mCounter / number) * 64), (float) ((mCounter % number) * 64), null);
      }
    }
  }
예제 #4
0
  public static void dolayout(
      Graph2D graph,
      CycleEnum cycleType,
      byte partitionLayoutStyle,
      int maxDevAngle,
      boolean fromSketch,
      boolean enableOnlyCore,
      boolean groupNodeHiding,
      boolean selfLoopLayouter,
      boolean parallelEdgeLayouter,
      boolean subgraphLayouter,
      boolean labelLayouter,
      boolean componentLayouter,
      boolean orientationLayouter) {

    CircularLayouter clo = new CircularLayouter();
    switch (cycleType) {
      case SINGLE_CYCLE:
        clo.setLayoutStyle(CircularLayouter.SINGLE_CYCLE);
        break;
      case BCC_ISOLATED:
        clo.setLayoutStyle(CircularLayouter.BCC_ISOLATED);
        break;
      case BCC_COMPACT:
        clo.setLayoutStyle(CircularLayouter.BCC_COMPACT);
        break;
      case CIRCULAR_CUSTOM_GROUPS:
        clo.setLayoutStyle(CircularLayouter.CIRCULAR_CUSTOM_GROUPS);
        break;
      default:
        clo.setLayoutStyle(CircularLayouter.BCC_COMPACT);
        break;
    }
    clo.setMaximalDeviationAngle(maxDevAngle);
    clo.setPartitionLayoutStyle(partitionLayoutStyle);
    clo.setFromSketchModeEnabled(fromSketch);

    if (enableOnlyCore) {
      clo.enableOnlyCore();
    }
    clo.setLabelLayouterEnabled(labelLayouter);
    clo.setSubgraphLayouterEnabled(subgraphLayouter);
    clo.setSelfLoopLayouterEnabled(selfLoopLayouter);
    clo.setComponentLayouterEnabled(componentLayouter);
    clo.setParallelEdgeLayouterEnabled(parallelEdgeLayouter);
    clo.setOrientationLayouterEnabled(orientationLayouter);
    clo.setGroupNodeHidingEnabled(groupNodeHiding);

    try {
      new BufferedLayouter(clo).doLayout(graph);
    } catch (ArrayIndexOutOfBoundsException e) {
      e.printStackTrace();
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
    } catch (OutOfMemoryError e) {
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
예제 #5
0
  public static String getFileSha1(String path) throws IOException {
    File file = new File(path);
    FileInputStream in = new FileInputStream(file);
    MessageDigest messagedigest;
    try {
      messagedigest = MessageDigest.getInstance("SHA-1");

      byte[] buffer = new byte[1024 * 1024 * 10];
      int len = 0;

      while ((len = in.read(buffer)) > 0) {
        // 该对象通过使用 update()方法处理数据
        messagedigest.update(buffer, 0, len);
      }

      // 对于给定数量的更新数据,digest 方法只能被调用一次。在调用 digest 之后,MessageDigest
      // 对象被重新设置成其初始状态。
      return getFormattedText(messagedigest.digest()); // byte2hex(messagedigest.digest());
    } catch (NoSuchAlgorithmException e) {
      // NQLog.e("getFileSha1->NoSuchAlgorithmException###", e.toString());
      e.printStackTrace();
    } catch (OutOfMemoryError e) {
      // NQLog.e("getFileSha1->OutOfMemoryError###", e.toString());
      e.printStackTrace();
      throw e;
    } finally {
      in.close();
    }
    return null;
  }
  protected void onCreateIcons() {
    ImageView icon_small = (ImageView) getOptionView().findViewById(R.id.icon_small);
    ImageView icon_big = (ImageView) getOptionView().findViewById(R.id.icon_big);
    Resources res = getContext().getBaseContext().getResources();

    if (null != res) {
      int id =
          res.getIdentifier(
              "feather_tool_icon_" + mResourceName,
              "drawable",
              getContext().getBaseContext().getPackageName());
      if (id > 0) {

        Bitmap big, small;

        try {
          Bitmap bmp = BitmapFactory.decodeResource(res, id);
          big =
              ThumbnailUtils.extractThumbnail(
                  bmp, (int) (bmp.getWidth() / 1.5), (int) (bmp.getHeight() / 1.5));
          bmp.recycle();
          small =
              ThumbnailUtils.extractThumbnail(
                  big, (int) (big.getWidth() / 1.5), (int) (big.getHeight() / 1.5));
        } catch (OutOfMemoryError e) {
          e.printStackTrace();
          return;
        }
        icon_big.setImageBitmap(big);
        icon_small.setImageBitmap(small);
      }
    }
  }
예제 #7
0
  public Level(int length, int height) {
    //        ints = new Vector();
    //        booleans = new Vector();
    this.length = length;
    this.height = height;

    xExit = 50;
    yExit = 10;
    //        System.out.println("Java: Level: lots of news here...");
    //        System.out.println("length = " + length);
    //        System.out.println("height = " + height);
    try {
      map = new byte[length][height];
      //        System.out.println("map = " + map);
      data = new byte[length][height];
      //        System.out.println("data = " + data);
      spriteTemplates = new SpriteTemplate[length][height];

      marioTrace = new int[length][height + 1];
    } catch (OutOfMemoryError e) {
      System.err.println("Java: MarioAI MEMORY EXCEPTION: OutOfMemory exception. Exiting...");
      e.printStackTrace();
      System.exit(-3);
    }
    //        System.out.println("spriteTemplates = " + spriteTemplates);
    //        observation = new byte[length][height];
    //        System.out.println("observation = " + observation);
  }
예제 #8
0
 /**
  * 获取关闭高光图标的副本
  *
  * @return
  */
 public BitmapDrawable getColseLightIconCopy() {
   try {
     if (mCloseLightIcon == null) {
       if (mThemeController == null) {
         mThemeController = AppFuncFrame.getThemeController();
       }
       BitmapDrawable origImg =
           (BitmapDrawable)
               mThemeController.getDrawable(
                   mThemeController.getThemeBean().mAppIconBean.mKillAppLight);
       if (origImg != null) {
         Bitmap copy = origImg.getBitmap().copy(Bitmap.Config.ARGB_8888, true);
         if (copy != null) {
           mCloseLightIcon = new BitmapDrawable(mContext.getResources(), copy);
         }
       }
     }
   } catch (OutOfMemoryError e) {
     e.printStackTrace();
     OutOfMemoryHandler.handle();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return mCloseLightIcon;
 }
예제 #9
0
 public static boolean compressBitmapFile(
     String dstPath, String srcPath, int reqWidth, int reqHeight) {
   final BitmapFactory.Options options = new BitmapFactory.Options();
   options.inJustDecodeBounds = true;
   options.inPurgeable = true;
   BitmapFactory.decodeFile(srcPath, options);
   if (options.outWidth > 0) {
     if (options.outWidth > reqWidth || options.outHeight > reqHeight) {
       options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
       options.inJustDecodeBounds = false;
       try {
         Bitmap bmp = BitmapFactory.decodeFile(srcPath, options);
         FileHelper.saveBitmapToFile(dstPath, bmp, 90);
       } catch (OutOfMemoryError e) {
         e.printStackTrace();
         return false;
       }
     } else {
       FileHelper.copyFile(dstPath, srcPath);
     }
   } else {
     return false;
   }
   return true;
 }
예제 #10
0
 /**
  * Rotate.
  *
  * @param b the b
  * @param degrees the degrees
  * @return the bitmap
  */
 private Bitmap rotate(final Bitmap b, int degrees) {
   Logger.v(TAG, "rotate entry");
   Bitmap bitmap = b;
   if (degrees != 0 && bitmap != null) {
     Matrix m = new Matrix();
     m.setRotate(degrees, (float) bitmap.getWidth() / 2, (float) bitmap.getHeight() / 2);
     try {
       Bitmap bitmapRotated =
           Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), m, true);
       if (bitmap != bitmapRotated) {
         bitmap.recycle();
         bitmap = bitmapRotated;
       } else {
         Logger.d(TAG, "no need to rotate");
       }
     } catch (OutOfMemoryError ex) {
       // We have no memory to rotate. Return the original bitmap.
       ex.printStackTrace();
     }
   } else {
     Logger.d(TAG, "rotate no need to rotate");
   }
   Logger.v(TAG, "rotate exit");
   return bitmap;
 }
예제 #11
0
 public static Bitmap loadBitmap(String url, UrlBitmapDownloadCallback callback) {
   if (TextUtils.isEmpty(url)) {
     return null;
   }
   SoftReference<Bitmap> sf = mapUrlToBitmap.get(url);
   Bitmap bmp = null;
   if (sf != null) {
     bmp = sf.get();
   }
   if (bmp == null) {
     String filePath = FilePaths.getUrlFileCachePath(url);
     if (new File(filePath).exists()) {
       BitmapFactory.Options op = new BitmapFactory.Options();
       SystemUtils.computeSampleSize(op, filePath, 1024, 1024 * 512);
       try {
         bmp = BitmapFactory.decodeFile(filePath, op);
       } catch (OutOfMemoryError e) {
         e.printStackTrace();
         op.inSampleSize *= 2;
         bmp = BitmapFactory.decodeFile(filePath, op);
       }
     }
     if (bmp == null) {
       if (callback != null) {
         mapUrlToCallback.put(url, callback);
       }
       requestDownloadBitmap(url, filePath);
     } else if (bmp != null) {
       mapUrlToBitmap.put(url, new SoftReference<Bitmap>(bmp));
     }
   }
   return bmp;
 }
예제 #12
0
 public void m3980a(int i) {
   try {
     this.f3127b = BitmapFactory.decodeResource(this.f3132g, i);
   } catch (OutOfMemoryError e) {
     e.printStackTrace();
   }
 }
예제 #13
0
 private final Bitmap compress(String uri, int reqWidth, int reqHeight) {
   Bitmap bitmap = null;
   try {
     BitmapFactory.Options opts = new BitmapFactory.Options();
     opts.inJustDecodeBounds = true;
     BitmapFactory.decodeFile(uri, opts);
     int height = opts.outHeight;
     int width = opts.outWidth;
     int inSampleSize = 1;
     if (width > height && width > reqWidth) {
       inSampleSize = Math.round((float) width / (float) reqWidth);
     } else if (height > width && height > reqHeight) {
       inSampleSize = Math.round((float) height / (float) reqHeight);
     }
     if (inSampleSize <= 1) inSampleSize = 1;
     opts.inSampleSize = inSampleSize;
     opts.inJustDecodeBounds = false;
     opts.inPreferredConfig = Config.RGB_565;
     opts.inPurgeable = true;
     opts.inInputShareable = true;
     opts.inTargetDensity = getResources().getDisplayMetrics().densityDpi;
     opts.inScaled = true;
     opts.inTempStorage = new byte[16 * 1024];
     bitmap =
         BitmapFactory.decodeStream(new BufferedInputStream(new FileInputStream(uri)), null, opts);
   } catch (FileNotFoundException e) {
     e.printStackTrace();
   } catch (OutOfMemoryError e) {
     e.printStackTrace();
   }
   return bitmap;
 }
예제 #14
0
 /**
  * 获取编辑文件夹高光图标的副本
  *
  * @return
  */
 public BitmapDrawable getEditLightIconCopy() {
   try {
     if (mEditLightIcon == null) {
       // BitmapDrawable origImg = (BitmapDrawable) mActivity
       // .getResources().getDrawable(
       // R.drawable.eidt_folder_light);
       if (mThemeController == null) {
         mThemeController = AppFuncFrame.getThemeController();
       }
       BitmapDrawable origImg =
           (BitmapDrawable)
               mThemeController.getDrawable(
                   mThemeController.getThemeBean().mAppIconBean.mEditHighlightFolder);
       if (origImg != null) {
         Bitmap copy = origImg.getBitmap().copy(Bitmap.Config.ARGB_8888, true);
         if (copy != null) {
           mEditLightIcon = new BitmapDrawable(mContext.getResources(), copy);
         }
       }
     }
   } catch (OutOfMemoryError e) {
     e.printStackTrace();
     OutOfMemoryHandler.handle();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return mEditLightIcon;
 }
예제 #15
0
  @Override
  public View getView(int position, View convertView, ViewGroup arg2) {
    // TODO Auto-generated method stub

    convertView = mInflater.inflate(R.layout.test_list_row, null);

    ImageView iv = (ImageView) convertView.findViewById(R.id.imageView);

    // 用try catch 块包围住
    try {
      setImage(iv);
    } catch (OutOfMemoryError e) {
      // 这里就是当内存泄露时 需要做的事情
      e.printStackTrace();

      Log.d("memory", "out");

      // 释放内存资源
      recycleMemory();

      // 将刚才 发生异常没有执行的 代码 再重新执行一次
      setImage(iv);
    }

    return convertView;
  }
예제 #16
0
 /**
  * 获取卸载图标的副本
  *
  * @return
  */
 public BitmapDrawable getKillIconCopy() {
   try {
     if (mKillImg == null) {
       // BitmapDrawable origImg = (BitmapDrawable) mActivity
       // .getResources().getDrawable(R.drawable.kill);
       if (mThemeController == null) {
         mThemeController = AppFuncFrame.getThemeController();
       }
       BitmapDrawable origImg =
           (BitmapDrawable)
               mThemeController.getDrawable(
                   mThemeController.getThemeBean().mAppIconBean.mDeletApp);
       if (origImg != null) {
         Bitmap copy = origImg.getBitmap().copy(Bitmap.Config.ARGB_8888, true);
         if (copy != null) {
           mKillImg = new BitmapDrawable(mContext.getResources(), copy);
         }
       }
     }
   } catch (OutOfMemoryError e) {
     e.printStackTrace();
     OutOfMemoryHandler.handle();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return mKillImg;
 }
    @Override
    public View instantiateItem(ViewGroup container, int position) {
      PhotoView photoView = new PhotoView(container.getContext());
      ImageFetcher fetcher = ImageLoader.createImageFetcher((BaseActivity) context);
      fetcher.setLoadingImage(R.drawable.default_weibo_image);
      try {

        Msg_ChatMessageBean bean = data.get(position);
        Bitmap bitmap = ImageUtil.byteArray2Bitmap(bean.Image);
        photoView.setImageBitmap(bitmap);
        photoView.setOnPhotoTapListener(
            new OnPhotoTapListener() {

              @Override
              public void onPhotoTap(View view, float x, float y) {
                Msg_ImageZoomActivity.this.onBackPressed();
              }
            });

        container.addView(photoView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
      } catch (Exception e) {
        e.printStackTrace();
      } catch (OutOfMemoryError ex) {
        ex.printStackTrace();
      }
      return photoView;
    }
예제 #18
0
  /**
   * @param dataStore A ShapeFileDataStore containing geometries to convert.
   * @param keyAttributes The names of attributes to be concatenated to generate record keys.
   * @throws Exception
   */
  public static void convertFeatures(
      GeometryStreamConverter converter, ShapefileDataStore dataStore, List<String> keyAttributes)
      throws Exception {
    SimpleFeatureType schema = dataStore.getSchema();
    int numFeatures = dataStore.getCount(Query.ALL);
    FeatureReader<SimpleFeatureType, SimpleFeature> reader = null;
    try {
      List<AttributeDescriptor> attrDesc = schema.getAttributeDescriptors();
      String header = "\"the_geom_id\", \"the_geom_key\"";
      for (int i = 1; i < attrDesc.size(); i++) {
        String colName = attrDesc.get(i).getLocalName();
        if (GeometryStreamConverter.debugDBF) header += ", \"" + colName + '"';
        // if any specified attribute matches colName, case insensitive, overwrite specified
        // attribute name with name having correct case
        for (int j = 0; j < keyAttributes.size(); j++)
          if (keyAttributes.get(j).equalsIgnoreCase(colName)) keyAttributes.set(j, colName);
      }
      // debug: read schema and print it out
      if (GeometryStreamConverter.debugDBF) System.out.println(header);

      // loop through features and parse them
      long startTime = System.currentTimeMillis(),
          endTime = startTime,
          debugInterval = 60000,
          nextDebugTime = startTime + debugInterval;
      int featureCount = 0;

      reader = dataStore.getFeatureReader();
      CoordinateReferenceSystem projection = schema.getCoordinateReferenceSystem(); // may be null
      String projectionWKT = projection == null ? null : projection.toWKT();

      while (reader.hasNext()) {
        endTime = System.currentTimeMillis();
        if (GeometryStreamConverter.debugTime && endTime > nextDebugTime) {
          System.out.println(
              String.format(
                  "Processing %s/%s features, %s minutes elapsed",
                  featureCount, numFeatures, (endTime - startTime) / 60000.0));
          while (endTime > nextDebugTime) nextDebugTime += debugInterval;
        }
        convertFeature(converter, reader.next(), keyAttributes, projectionWKT);
        featureCount++;
      }

      if (GeometryStreamConverter.debugTime && endTime - startTime > debugInterval)
        System.out.println(
            String.format(
                "Processing %s features completed in %s minutes",
                numFeatures, (endTime - startTime) / 60000.0));
    } catch (OutOfMemoryError e) {
      e.printStackTrace();
      throw e;
    } finally {
      try {
        if (reader != null) reader.close();
      } catch (IOException e) {
      }
    }
  }
    @Override
    protected CacheableBitmapDrawable doInBackground(String... params) {
      try {
        // Return early if the ImageView has disappeared.
        if (holder.userId != userId) {
          return null;
        }
        final String url = params[0];

        // Now we're not on the main thread we can check all caches
        CacheableBitmapDrawable result;

        try {
          result = mCache.get(url, null);
        } catch (Exception e) {
          result = null;
        }

        if (null == result) {
          Log.d("ImageUrlAsyncTask", "Downloading: " + url);

          // The bitmap isn't cached so download from the web
          HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
          InputStream is = new BufferedInputStream(conn.getInputStream());

          Bitmap b = decodeSampledBitmapFromResourceMemOpt(is, 500, 500);

          try {
            is.close();
          } catch (Exception e) {

          }
          try {
            conn.disconnect();
          } catch (Exception e) {

          }

          // Add to cache
          try {
            result = mCache.put(url, b);
          } catch (Exception e) {
            result = null;
          }

        } else {
          Log.d("ImageUrlAsyncTask", "Got from Cache: " + url);
        }

        return result;

      } catch (IOException e) {
        Log.e("ImageUrlAsyncTask", e.toString());
      } catch (OutOfMemoryError e) {
        e.printStackTrace();
      }

      return null;
    }
예제 #20
0
 public static void loadImage(String path, ImageLoadingListener listener) {
   ImageLoader loader = ImageLoader.getInstance();
   try {
     loader.loadImage(path, DEFAULT_DISPLAY_IMAGE_OPTIONS, listener);
   } catch (OutOfMemoryError e) {
     e.printStackTrace();
   }
 }
예제 #21
0
  /**
   * @param path
   * @param limitMax 限制最大边
   * @param quality 质量
   * @return
   */
  public static byte[] getAddBitmapByte(String path, int limitMax, int quality) {
    // 用于存储bitmap的字节数组
    int LIMIT_MAX_MARGIN = limitMax;
    byte[] data = null;
    Bitmap localBitmap = null;
    try {
      localBitmap = revitionImageSize(path, 2 * LIMIT_MAX_MARGIN);
    } catch (IOException e1) {
      e1.printStackTrace();
    }

    if (localBitmap != null) {
      int width = localBitmap.getWidth();
      int height = localBitmap.getHeight();
      if (width > LIMIT_MAX_MARGIN || height > LIMIT_MAX_MARGIN) {
        // 创建操作图片用的matrix对象
        Matrix matrix = new Matrix();
        // 计算宽高缩放率.
        float scaleWidth = 0;
        float scaleHeight = 0;
        int newWidth = 0;
        int newHeight = 0;
        if (width > height) {
          newWidth = LIMIT_MAX_MARGIN;
          newHeight = (LIMIT_MAX_MARGIN * height) / width;
          scaleWidth = ((float) newWidth) / width;
          scaleHeight = ((float) newHeight) / height;
        } else {
          newHeight = LIMIT_MAX_MARGIN;
          newWidth = (LIMIT_MAX_MARGIN * width) / height;
          scaleWidth = ((float) newWidth) / width;
          scaleHeight = ((float) newHeight) / height;
        }
        // 缩放图片动作
        matrix.postScale(scaleWidth, scaleHeight);
        // 创建缩放后的图片
        try {
          localBitmap =
              Bitmap.createBitmap(localBitmap, 0, 0, (int) width, (int) height, matrix, true);
        } catch (Exception e) {
          e.printStackTrace();
        } catch (OutOfMemoryError e) {
          e.printStackTrace();
        }
      }
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      // 压缩图片质量
      localBitmap.compress(Bitmap.CompressFormat.JPEG, quality, bos);
      data = bos.toByteArray();
      try {
        localBitmap.recycle();
        bos.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    return data;
  }
예제 #22
0
 public static void displayRoundImage(ImageView view, String path, ImageLoadingListener listener) {
   ImageLoader loader = ImageLoader.getInstance();
   try {
     loader.displayImage(path, view, ROUND_DISPLAY_IMAGE_OPTIONS, listener);
   } catch (OutOfMemoryError e) {
     e.printStackTrace();
     loader.clearMemoryCache();
   }
 }
예제 #23
0
 public static void safeSetImageBitmap(ImageView iv, String path) {
   BitmapFactory.Options op = new BitmapFactory.Options();
   computeSampleSize(op, path, 512, 512 * 512);
   try {
     iv.setImageBitmap(BitmapFactory.decodeFile(path, op));
   } catch (OutOfMemoryError e) {
     e.printStackTrace();
   }
 }
예제 #24
0
 @Override
 public Object readData(Context context, InputStream is) {
   Bitmap bitmap = null; // assume that we call this method only for photos
   try {
     bitmap = BitmapFactory.decodeStream(is);
   } catch (OutOfMemoryError error) {
     error.printStackTrace();
   }
   return bitmap;
 }
예제 #25
0
파일: bwtest.java 프로젝트: bigcao/WordSeg
  public static void main(String[] args) {
    byte[] T, U, V;
    int[] A;
    int i, j, n, pidx;
    long start, finish;

    for (i = 0; i < args.length; ++i) {
      System.out.print(args[i] + ": ");
      try {
        /* Open a file for reading. */
        File f = new File(args[i]);
        FileInputStream s = new FileInputStream(f);

        n = (int) f.length();
        System.out.print(n + " bytes ... ");

        /* Allocate 5n bytes of memory. */
        T = new byte[n];
        U = new byte[n];
        V = new byte[n];
        A = new int[n];

        /* Read n bytes of data. */
        s.read(T);
        s.close();
        s = null;
        f = null;

        /* Construct the suffix array. */
        start = new Date().getTime();
        pidx = new sais().bwtransform(T, U, A, n);
        finish = new Date().getTime();
        System.out.println(((finish - start) / 1000.0) + " sec");

        System.out.print("unbwtcheck ... ");
        unbwt(U, V, A, n, pidx);
        for (j = 0; j < n; ++j) {
          if (T[j] != V[j]) {
            System.err.println("error " + j + ": " + T[j] + ", " + V[j]);
            return;
          }
        }
        System.err.println("Done.");

        T = null;
        U = null;
        V = null;
        A = null;
      } catch (IOException e) {
        e.printStackTrace();
      } catch (OutOfMemoryError e) {
        e.printStackTrace();
      }
    }
  }
예제 #26
0
 /**
  * Get from disk cache.
  *
  * @param data Unique identifier for which item to get
  * @return The bitmap if found in cache, null otherwise
  */
 public Bitmap getBitmapFromDiskCache(String data, Bitmap.Config config) {
   if (mDiskCache != null) {
     try {
       return mDiskCache.get(data, config);
     } catch (OutOfMemoryError error) {
       error.printStackTrace();
       cleanMemCache();
     }
   }
   return null;
 }
예제 #27
0
파일: Helper.java 프로젝트: nainoi/Confly
  public static void createThumbnail(String filePath, String folderName) {
    FileInputStream epubInputStream = null;
    BufferedOutputStream bos = null;
    try {
      epubInputStream = new FileInputStream(new File(filePath));
      String lastPath = filePath.substring(filePath.lastIndexOf('/') + 1);
      String savePath = getThumbnailDirectory(folderName) + "/" + lastPath;

      if (!Helper.fileExits(savePath)) {
        byte[] cis = FileEncrypt.decrypt_data(epubInputStream);
        if (cis == null) return;

        FileOutputStream outputStream = new FileOutputStream(new File(savePath));
        bos = new BufferedOutputStream(outputStream);
        bos.write(cis, 0, cis.length);
        bos.flush();
        bos.close();

        byte[] imageData = null;

        // PDFView pdfView = new PDFView(getApplicationContext(),null);

        Bitmap imageBitmap = decodeFile(new File(savePath));

        int targetWidth = 150;

        double aspectRatio = (double) imageBitmap.getHeight() / (double) imageBitmap.getWidth();
        int targetHeight = (int) (targetWidth * aspectRatio);

        // imageBitmap = Bitmap.createScaledBitmap(imageBitmap,(int)(imageBitmap.getWidth()*0.4),
        // (int)(imageBitmap.getHeight()*0.4), true);
        imageBitmap = Bitmap.createScaledBitmap(imageBitmap, targetWidth, targetHeight, true);

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        imageBitmap.compress(Bitmap.CompressFormat.JPEG, 90, baos);
        imageData = baos.toByteArray();

        outputStream = new FileOutputStream(new File(savePath));
        bos = new BufferedOutputStream(outputStream);
        bos.write(imageData, 0, imageData.length);
        bos.flush();
        bos.close();

        Thread.sleep(10);
      }
      // InputStream is = new ByteArrayInputStream(cis);
      // imageView.setImageBitmap(decodeFile(new File(savePath)));
    } catch (OutOfMemoryError e) {
      e.printStackTrace();
    } catch (Exception e) {
      e.printStackTrace();
      // imageView.setImageResource(R.drawable.no_image_detail);
    }
  }
예제 #28
0
  public static Bitmap rotateBitmap(String src, Bitmap bitmap) {
    try {
      int orientation = getExifOrientation(src);

      if (orientation == 1) {
        return bitmap;
      }

      Matrix matrix = new Matrix();
      switch (orientation) {
        case 2:
          matrix.setScale(-1, 1);
          break;
        case 3:
          matrix.setRotate(180);
          break;
        case 4:
          matrix.setRotate(180);
          matrix.postScale(-1, 1);
          break;
        case 5:
          matrix.setRotate(90);
          matrix.postScale(-1, 1);
          break;
        case 6:
          matrix.setRotate(90);
          break;
        case 7:
          matrix.setRotate(-90);
          matrix.postScale(-1, 1);
          break;
        case 8:
          matrix.setRotate(-90);
          break;
        default:
          return bitmap;
      }

      try {
        Bitmap oriented =
            Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
        bitmap.recycle();
        return oriented;
      } catch (OutOfMemoryError e) {
        e.printStackTrace();
        return bitmap;
      }
    } catch (IOException e) {
      e.printStackTrace();
    }

    return bitmap;
  }
예제 #29
0
  // @see http://sylvana.net/jpegcrop/exif_orientation.html
  public static Bitmap rotateBitmap(String src, Bitmap bitmap) {
    try {
      int orientation = getExifOrientation(src);
      if (orientation == 1) {
        return bitmap;
      }

      Matrix matrix = new Matrix();
      switch (orientation) {
        case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
          matrix.setScale(-1, 1);
          break;
        case ExifInterface.ORIENTATION_ROTATE_180:
          matrix.setRotate(180);
          break;
        case ExifInterface.ORIENTATION_FLIP_VERTICAL:
          matrix.setRotate(180);
          matrix.postScale(-1, 1);
          break;
        case ExifInterface.ORIENTATION_TRANSPOSE:
          matrix.setRotate(90);
          matrix.postScale(-1, 1);
          break;
        case ExifInterface.ORIENTATION_ROTATE_90:
          matrix.setRotate(90);
          break;
        case ExifInterface.ORIENTATION_TRANSVERSE:
          matrix.setRotate(-90);
          matrix.postScale(-1, 1);
          break;
        case ExifInterface.ORIENTATION_ROTATE_270:
          matrix.setRotate(-90);
          break;
        default:
          return bitmap;
      }

      try {
        Bitmap oriented =
            Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
        bitmap.recycle();
        return oriented;
      } catch (OutOfMemoryError e) {
        e.printStackTrace();
        return bitmap;
      }
    } catch (IOException e) {
      e.printStackTrace();
    }

    return bitmap;
  }
예제 #30
0
 public static Bitmap createBitmapSafely(
     int width, int height, Bitmap.Config config, int retryCount) {
   try {
     return Bitmap.createBitmap(width, height, config);
   } catch (OutOfMemoryError e) {
     e.printStackTrace();
     if (retryCount > 0) {
       System.gc();
       return createBitmapSafely(width, height, config, retryCount - 1);
     }
     return null;
   }
 }