コード例 #1
0
    private static void revitionImageSize(String picfile, int size, int quality)
        throws IOException {
      if (size <= 0) {
        throw new IllegalArgumentException("size must be greater than 0!");
      }

      if (!doesExisted(picfile)) {
        throw new FileNotFoundException(picfile == null ? "null" : picfile);
      }

      if (!BitmapHelper.verifyBitmap(picfile)) {
        throw new IOException("");
      }

      FileInputStream input = new FileInputStream(picfile);
      final BitmapFactory.Options opts = new BitmapFactory.Options();
      opts.inJustDecodeBounds = true;
      BitmapFactory.decodeStream(input, null, opts);
      try {
        input.close();
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      int rate = 0;
      for (int i = 0; ; i++) {
        if ((opts.outWidth >> i <= size) && (opts.outHeight >> i <= size)) {
          rate = i;
          break;
        }
      }

      opts.inSampleSize = (int) Math.pow(2, rate);
      opts.inJustDecodeBounds = false;

      Bitmap temp = safeDecodeBimtapFile(picfile, opts);

      if (temp == null) {
        throw new IOException("Bitmap decode error!");
      }

      deleteDependon(picfile);
      makesureFileExist(picfile);
      final FileOutputStream output = new FileOutputStream(picfile);
      if (opts != null && opts.outMimeType != null && opts.outMimeType.contains("png")) {
        temp.compress(Bitmap.CompressFormat.PNG, quality, output);
      } else {
        temp.compress(Bitmap.CompressFormat.JPEG, quality, output);
      }
      try {
        output.close();
      } catch (Exception e) {
        e.printStackTrace();
      }
      temp.recycle();
    }
コード例 #2
0
ファイル: CamActivity.java プロジェクト: trienvu/Cam1280
  /** Go through the specified directory, and create mFiles to display in our GridView */
  private List<GridViewItem> createGridItems(String directoryPath) {
    List<GridViewItem> items = new ArrayList<GridViewItem>();

    // List all the mFiles within the folder.
    File[] files = new File(directoryPath).listFiles(new ImageFileFilter());
    for (File file : files) {

      // Add the directories containing images or sub-directories
      if (file.isDirectory() && file.listFiles(new ImageFileFilter()).length > 0) {

        items.add(new GridViewItem(file.getAbsolutePath(), true, null));
      }
      // Add the images
      else {
        Bitmap image = BitmapHelper.decodeBitmapFromFile(file.getAbsolutePath(), 50, 50);
        items.add(new GridViewItem(file.getAbsolutePath(), false, image));
      }
    }

    return items;
  }
コード例 #3
0
ファイル: NfsManager.java プロジェクト: xch168/Lop
  public void ShowRecoredViewNotification(Uri uri, Bitmap bitmap, String filenName) {
    Intent viewIntent = new Intent(ACTION_VIEW, uri);
    PendingIntent pendingViewIntent = PendingIntent.getActivity(mContext, 0, viewIntent, 0);

    Notification.Builder builder = getBaseBuilder();
    String title = mContext.getResources().getString(R.string.lop_ntf_title_record_finish);
    builder.setContentTitle(title);
    builder.setContentText(filenName);
    builder.setContentIntent(pendingViewIntent);
    if (bitmap != null) {
      builder
          .setLargeIcon(mBitmapHelper.createSquareBitmap(bitmap)) //
          .setStyle(
              new Notification.BigPictureStyle() //
                  .setBigContentTitle(title)
                  .setSummaryText(filenName)
                  .bigPicture(bitmap));
    }

    notificationManager.notify(NOTIFICATION_ID, builder.build());
  }
コード例 #4
0
    private static void revitionImageSizeHD(String picfile, int size, int quality)
        throws IOException {
      if (size <= 0) {
        throw new IllegalArgumentException("size must be greater than 0!");
      }
      if (!doesExisted(picfile)) {
        throw new FileNotFoundException(picfile == null ? "null" : picfile);
      }

      if (!BitmapHelper.verifyBitmap(picfile)) {
        throw new IOException("");
      }

      int photoSizesOrg = 2 * size;
      FileInputStream input = new FileInputStream(picfile);
      final BitmapFactory.Options opts = new BitmapFactory.Options();
      opts.inJustDecodeBounds = true;
      BitmapFactory.decodeStream(input, null, opts);
      try {
        input.close();
      } catch (Exception e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }

      int rate = 0;
      for (int i = 0; ; i++) {
        if ((opts.outWidth >> i <= photoSizesOrg && (opts.outHeight >> i <= photoSizesOrg))) {
          rate = i;
          break;
        }
      }

      opts.inSampleSize = (int) Math.pow(2, rate);
      opts.inJustDecodeBounds = false;

      Bitmap temp = safeDecodeBimtapFile(picfile, opts);

      if (temp == null) {
        throw new IOException("Bitmap decode error!");
      }

      deleteDependon(picfile);
      makesureFileExist(picfile);

      int org = temp.getWidth() > temp.getHeight() ? temp.getWidth() : temp.getHeight();
      float rateOutPut = size / (float) org;

      if (rateOutPut < 1) {
        Bitmap outputBitmap;
        while (true) {
          try {
            outputBitmap =
                Bitmap.createBitmap(
                    ((int) (temp.getWidth() * rateOutPut)),
                    ((int) (temp.getHeight() * rateOutPut)),
                    Bitmap.Config.ARGB_8888);
            break;
          } catch (OutOfMemoryError e) {
            System.gc();
            rateOutPut = (float) (rateOutPut * 0.8);
          }
        }
        if (outputBitmap == null) {
          temp.recycle();
        }
        Canvas canvas = new Canvas(outputBitmap);
        Matrix matrix = new Matrix();
        matrix.setScale(rateOutPut, rateOutPut);
        canvas.drawBitmap(temp, matrix, new Paint());
        temp.recycle();
        temp = outputBitmap;
      }
      final FileOutputStream output = new FileOutputStream(picfile);
      if (opts != null && opts.outMimeType != null && opts.outMimeType.contains("png")) {
        temp.compress(Bitmap.CompressFormat.PNG, quality, output);
      } else {
        temp.compress(Bitmap.CompressFormat.JPEG, quality, output);
      }
      try {
        output.close();
      } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      temp.recycle();
    }