Exemple #1
0
  public Bitmap getResBitmapMutable(Resources res, int bmpResId) {
    Options opts = new Options();
    opts.inDither = false;
    Bitmap b = BitmapFactory.decodeResource(res, bmpResId, opts);

    int w = b.getWidth();
    int h = b.getHeight();
    Bitmap mutable = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
    int[] pixels = new int[w * h];
    b.getPixels(pixels, 0, w, 0, 0, w, h);
    mutable.setPixels(pixels, 0, w, 0, 0, w, h);
    return mutable;
  }
 private void copyOptions(Options srcOptions, Options destOptions) {
   destOptions.inDensity = srcOptions.inDensity;
   destOptions.inDither = srcOptions.inDither;
   destOptions.inInputShareable = srcOptions.inInputShareable;
   destOptions.inJustDecodeBounds = srcOptions.inJustDecodeBounds;
   destOptions.inPreferredConfig = srcOptions.inPreferredConfig;
   destOptions.inPurgeable = srcOptions.inPurgeable;
   destOptions.inSampleSize = srcOptions.inSampleSize;
   destOptions.inScaled = srcOptions.inScaled;
   destOptions.inScreenDensity = srcOptions.inScreenDensity;
   destOptions.inTargetDensity = srcOptions.inTargetDensity;
   destOptions.inTempStorage = srcOptions.inTempStorage;
   if (Build.VERSION.SDK_INT >= 10) copyOptions10(srcOptions, destOptions);
   if (Build.VERSION.SDK_INT >= 11) copyOptions11(srcOptions, destOptions);
 }
    public SimulationView(Context context) {
      super(context);
      mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);

      DisplayMetrics metrics = new DisplayMetrics();
      getWindowManager().getDefaultDisplay().getMetrics(metrics);
      mXDpi = metrics.xdpi;
      mYDpi = metrics.ydpi;
      mMetersToPixelsX = mXDpi / 0.0254f;
      mMetersToPixelsY = mYDpi / 0.0254f;

      // rescale the ball so it's about 0.5 cm on screen
      Bitmap ball = BitmapFactory.decodeResource(getResources(), R.drawable.ballw);
      final int dstWidth = (int) (sBallDiameter * mMetersToPixelsX + 0.5f);
      final int dstHeight = (int) (sBallDiameter * mMetersToPixelsY + 0.5f);
      mBitmap = Bitmap.createScaledBitmap(ball, dstWidth, dstHeight, true);

      Options opts = new Options();
      opts.inDither = true;
      opts.inPreferredConfig = Bitmap.Config.RGB_565;
      mPool = BitmapFactory.decodeResource(getResources(), R.drawable.tableg, opts);
    }
Exemple #4
0
 public Bitmap getResBitmap(Resources res, int bmpResId) {
   Options opts = new Options();
   opts.inDither = false;
   return BitmapFactory.decodeResource(res, bmpResId, opts);
 }