Пример #1
0
  public void storeBitmap(Bitmap existingFile) {
    Log.d(LOGGER, "Scaling file ...");

    final int maxSize = game.getWidth() / 3;
    int outWidth;
    int outHeight;
    int inWidth = existingFile.getWidth();
    int inHeight = existingFile.getHeight();
    if (inWidth > inHeight) {
      outWidth = maxSize;
      outHeight = (inHeight * maxSize) / inWidth;
    } else {
      outHeight = maxSize;
      outWidth = (inWidth * maxSize) / inHeight;
    }
    Bitmap scaledFile = Bitmap.createScaledBitmap(existingFile, outWidth, outHeight, false);

    File destination = new File(getFilesDir(), "RandomBotImage.png");
    FileOutputStream fOut;
    try {
      fOut = new FileOutputStream(destination);
      Log.d(LOGGER, "Storing file ...");
      scaledFile.compress(Bitmap.CompressFormat.PNG, 100, fOut);
      fOut.flush();
      fOut.close();
    } catch (Exception e) {
      Log.e(LOGGER, "Exception was thrown:" + e.getMessage());
    }
    Log.d(LOGGER, "RandomBot File ready to use.");

    game.setRandomBotImage(destination.getPath(), scaledFile);
  }