Esempio n. 1
0
  @Override
  protected void setImage(Context context, ImageView view) {
    try {
      if (!isVectorBased()) { // Raster image (PNG, JPG, GIF, ...):
        view.setImageBitmap(BitmapUtils.loadBitmap(context, file));
      } else { // Vector image (SVG or SVGZ):

        // Using svg-android lib:
        SVG svg = new SVGBuilder().readFromInputStream(new FileInputStream(file)).build();
        view.setImageDrawable(new SVGDrawable(svg));

        // Using AndroidSVG lib:
        // SVG svg = SVG.getFromInputStream(new FileInputStream(file));
        // view.setImageDrawable(new PictureDrawable(svg.renderToPicture()));
      }
    } catch (Exception e) {
      Log.e(TAG, "Could not load image from file", e);
    }
  }
      @Override
      protected Bitmap doInBackground(Void... params) {
        Bitmap bitmap = null;
        try {
          // TODO use EXIF data to determine proper rotation? Cf.
          // http://stackoverflow.com/q/12944123/1084488

          // Decode scaled bitmap:
          bitmap = BitmapUtils.loadBitmap(getContext(), data);

          // Rotate (TODO is this always needed?)
          Matrix bitmapMatrix = new Matrix();
          bitmapMatrix.postRotate(90);
          bitmap =
              Bitmap.createBitmap(
                  bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), bitmapMatrix, false);
        } catch (Exception e) {
          Debug.e(e);
        }
        return bitmap;
      }