Ejemplo n.º 1
0
 /**
  * 更有游戏画布为指定大小
  *
  * @param bit
  * @param w
  * @param h
  */
 public void updateResize(Bitmap bit, int w, int h) {
   if (!isRunning) {
     return;
   }
   if (bit == null) {
     return;
   }
   canvas = surfaceHolder.lockCanvas(null);
   if (canvas != null) {
     int nw = bit.getWidth();
     int nh = bit.getHeight();
     float scaleWidth = ((float) w) / nw;
     float scaleHeight = ((float) h) / nh;
     tmp_matrix.reset();
     tmp_matrix.postScale(scaleWidth, scaleHeight);
     tmp_matrix.postTranslate(width / 2 - w / 2, height / 2 - h / 2);
     synchronized (surfaceHolder) {
       if (resizePaint == null) {
         resizePaint = new Paint();
       }
       resizePaint.setFilterBitmap(true);
       canvas.drawBitmap(bit, tmp_matrix, resizePaint);
       resizePaint.setFilterBitmap(false);
       if (emulatorButtons != null) {
         emulatorButtons.draw(canvas);
       }
     }
     surfaceHolder.unlockCanvasAndPost(canvas);
   }
 }
  /**
   * Doing effects, etc, that we don't need to do every draw()
   *
   * @param bitmap
   */
  private void setAndPreprocessBitmap(Bitmap bitmap) {
    if (bitmap.getWidth() <= 0 || bitmap.getHeight() <= 0) return;
    // if (waveform != null && waveform != bitmap) waveform.recycle();
    waveform = bitmap;

    int scaledWidth = width * 2;
    int scaledHeight = height; // no change here.
    int clippedWidth = getScaledWidth(scaledWidth, bitmap);
    Bitmap clipped = clipBitmap(bitmap, clippedWidth);

    Bitmap canvasbmp = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(canvasbmp);
    Rect canvasrect = canvas.getClipBounds();
    Rect clippedrect = new Rect(0, 0, clipped.getWidth(), clipped.getHeight());

    paint.setFilterBitmap(true);
    paint.setAlpha(120);
    canvas.drawBitmap(makeBlurry(bitmap, 3), clippedrect, canvasrect, paint);
    paint.setFilterBitmap(false);
    paint.setAlpha(180);
    canvas.drawBitmap(bitmap, clippedrect, canvasrect, paint);

    oldProcessedWaveform = processedWaveform;
    processedWaveform = canvasbmp;
    timeSinceTransition = System.currentTimeMillis();
    // if (oldwaveform != null) oldwaveform.recycle();
    clipped.recycle();
  }
 HolographicOutlineHelper() {
   mHolographicPaint.setFilterBitmap(true);
   mHolographicPaint.setAntiAlias(true);
   mBlurPaint.setFilterBitmap(true);
   mBlurPaint.setAntiAlias(true);
   mErasePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
   mErasePaint.setFilterBitmap(true);
   mErasePaint.setAntiAlias(true);
 }
Ejemplo n.º 4
0
  /**
   * Drawing src bitmap to dest bitmap with round mask. Dest might be squared, src is recommended to
   * be square
   *
   * @param src source bitmap
   * @param dest destination bitmap
   * @param clearColor clear color
   */
  public static void drawInRound(Bitmap src, Bitmap dest, int clearColor) {
    if (dest.getWidth() != dest.getHeight()) {
      throw new RuntimeException("dest Bitmap must have square size");
    }
    clearBitmap(dest, clearColor);
    Canvas canvas = new Canvas(dest);

    int r = dest.getWidth() / 2;
    Rect sourceRect = WorkCache.RECT1.get();
    Rect destRect = WorkCache.RECT2.get();
    sourceRect.set(0, 0, src.getWidth(), src.getHeight());
    destRect.set(0, 0, dest.getWidth(), dest.getHeight());

    Paint paint = WorkCache.PAINT.get();
    paint.reset();
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(Color.RED);
    paint.setAntiAlias(true);
    canvas.drawCircle(r, r, r, paint);

    paint.reset();
    paint.setFilterBitmap(true);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(src, sourceRect, destRect, paint);

    canvas.setBitmap(null);
  }
Ejemplo n.º 5
0
  /**
   * Drawing src bitmap to dest bitmap with rounded corners
   *
   * @param src source bitmap
   * @param dest destination bitmap
   * @param radius radius in destination bitmap scale
   * @param clearColor clear color
   */
  public static void drawRoundedCorners(Bitmap src, Bitmap dest, int radius, int clearColor) {
    clearBitmap(dest, clearColor);
    Canvas canvas = new Canvas(dest);

    Rect sourceRect = WorkCache.RECT1.get();
    Rect destRect = WorkCache.RECT2.get();
    sourceRect.set(0, 0, src.getWidth(), src.getHeight());
    destRect.set(0, 0, dest.getWidth(), dest.getHeight());

    RectF roundRect = WorkCache.RECTF1.get();
    roundRect.set(0, 0, dest.getWidth(), dest.getHeight());

    Paint paint = WorkCache.PAINT.get();
    paint.reset();
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(Color.RED);
    paint.setAntiAlias(true);
    canvas.drawRoundRect(roundRect, radius, radius, paint);

    paint.reset();
    paint.setFilterBitmap(true);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(src, sourceRect, destRect, paint);

    canvas.setBitmap(null);
  }
  public ColorHueView(Context ctx, AttributeSet attrs) {
    super(ctx, attrs);
    DisplayMetrics metrics = ctx.getResources().getDisplayMetrics();
    float mDpToPix = metrics.density;
    mDotRadius = DOT_SIZE * mDpToPix;
    mBorder = BORDER_SIZE * mDpToPix;

    mDotPaint = new Paint();

    mDotPaint.setStyle(Paint.Style.FILL);
    mDotPaint.setColor(ctx.getResources().getColor(R.color.slider_dot_color));
    mSliderColor = ctx.getResources().getColor(R.color.slider_line_color);

    mLinePaint1 = new Paint();
    mLinePaint1.setColor(Color.GRAY);
    mLinePaint2 = new Paint();
    mLinePaint2.setColor(mSliderColor);
    mLinePaint2.setStrokeWidth(4);

    mBitmap = Bitmap.createBitmap(256, 2, Bitmap.Config.ARGB_8888);
    mTmpBuff = new int[mBitmap.getWidth() * mBitmap.getHeight()];
    mPaint.setAntiAlias(true);
    mPaint.setFilterBitmap(true);
    fillBitmap();
    makeCheckPaint();
  }
  @SuppressLint("DrawAllocation")
  @Override
  protected void onDraw(Canvas canvas) {

    Drawable drawable = getDrawable();

    if (drawable == null) {
      return;
    }

    if (getWidth() == 0 || getHeight() == 0) {
      return;
    }
    Bitmap b = ((BitmapDrawable) drawable).getBitmap();
    Bitmap bitmap = b.copy(Bitmap.Config.ARGB_8888, true);

    int w = getWidth(), h = getHeight();

    Bitmap roundBitmap = getCroppedBitmap(bitmap, w);

    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    paint.setColor(color);
    // paint.setXfermode( new PorterDuffXfermode( Mode.SRC_IN ) );
    canvas.drawCircle(w / 2, w / 2, w / 2, paint);

    canvas.drawBitmap(roundBitmap, 0, 0, null);
  }
Ejemplo n.º 8
0
  public static Bitmap getRoundedBitmap(Bitmap src, int radius) {
    Bitmap roundBitmap;
    roundBitmap =
        (src.getWidth() == radius || src.getHeight() == radius)
            ? src
            : Bitmap.createScaledBitmap(src, radius, radius, false);
    Bitmap des =
        Bitmap.createBitmap(
            roundBitmap.getWidth(), roundBitmap.getHeight(), Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(des);
    final Rect rect = new Rect(0, 0, des.getWidth(), des.getHeight());

    final Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);

    canvas.drawARGB(0, 0, 0, 0);

    paint.setColor(Color.parseColor("#BAB399"));

    canvas.drawCircle(
        des.getWidth() / 2 + 0.7f, des.getHeight() / 2 + 0.7f, des.getWidth() / 2 - 10f, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(roundBitmap, rect, rect, paint);

    return des;
  }
Ejemplo n.º 9
0
  public static Bitmap getRoundedCroppedBitmap(Bitmap bitmap, int radius) {
    Bitmap finalBitmap;
    if (bitmap.getWidth() != radius || bitmap.getHeight() != radius)
      finalBitmap = Bitmap.createScaledBitmap(bitmap, radius, radius, false);
    else finalBitmap = bitmap;
    Bitmap output =
        Bitmap.createBitmap(
            finalBitmap.getWidth(), finalBitmap.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, finalBitmap.getWidth(), finalBitmap.getHeight());

    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(Color.parseColor("#BAB399"));
    canvas.drawCircle(
        finalBitmap.getWidth() / 2 + 0.7f,
        finalBitmap.getHeight() / 2 + 0.7f,
        finalBitmap.getWidth() / 2 + 0.1f,
        paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(finalBitmap, rect, rect, paint);

    return output;
  }
Ejemplo n.º 10
0
  public static Bitmap getCroppedBitmap(Bitmap bmp, int radius) {
    Bitmap sbmp;
    if (bmp.getWidth() != radius || bmp.getHeight() != radius)
      sbmp = Bitmap.createScaledBitmap(bmp, radius, radius, false);
    else sbmp = bmp;
    Bitmap output = Bitmap.createBitmap(sbmp.getWidth(), sbmp.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, sbmp.getWidth(), sbmp.getHeight());

    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 255, 255, 255);
    paint.setColor(Color.parseColor("#7f97d2"));
    canvas.drawCircle(
        sbmp.getWidth() / 2 + 0.7f,
        sbmp.getHeight() / 2 + 0.7f,
        sbmp.getWidth() / 2 - strokeWidth,
        paint); // 2-9f
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(sbmp, rect, rect, paint);

    //        Paint pTouch = new Paint(Paint.ANTI_ALIAS_FLAG);
    //	    pTouch.setXfermode(new PorterDuffXfermode(Mode.DST_IN));
    //	    pTouch.setAlpha(255);
    //	    pTouch.setColor(Color.TRANSPARENT);
    //	    pTouch.setMaskFilter(new BlurMaskFilter(15, Blur.NORMAL));

    //	    canvas.drawCircle(sbmp.getWidth() / 2-.6f, sbmp.getHeight() / 2, ((float)
    // Math.ceil((sbmp.getHeight()+15)/11))+.2f, pTouch);
    //	    canvas.drawCircle(sbmp.getWidth() / 2-.6f, sbmp.getHeight() / 2, 57, pTouch);
    return output;
  }
Ejemplo n.º 11
0
  @Override
  protected void onDraw(Canvas canvas) {
    Drawable drawable = getDrawable();
    if (drawable == null) {
      return;
    }
    if (getWidth() == 0 || getHeight() == 0) {
      return;
    }

    Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
    if (null == bitmap) {
      return;
    }
    final Paint paint = new Paint();
    final Rect rect1 = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
    final Rect rect2 = new Rect(0, 0, bitmap.getWidth(), bitmap.getWidth());
    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);

    Bitmap output =
        Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);

    Canvas canvas1 = new Canvas(output);
    canvas1.drawCircle(
        bitmap.getWidth() / 2.0f, bitmap.getWidth() / 2.0f, bitmap.getWidth() / 2.0f, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas1.drawBitmap(bitmap, rect1, rect1, paint);
    float sx = ((float) getWidth()) / (float) output.getWidth();
    float sy = ((float) getHeight()) / (float) output.getHeight();
    Matrix matrix = new Matrix();
    matrix.setScale(sx, sx);
    output = Bitmap.createBitmap(output, 0, 0, output.getWidth(), output.getHeight(), matrix, true);
    canvas.drawBitmap(output, 0, 0, null);
  }
Ejemplo n.º 12
0
  /**
   * @param bmp
   * @param radius
   * @return
   */
  public static Bitmap getCroppedBitmap(Bitmap bmp, float radius) {
    Bitmap sbmp;
    int width = (int) radius;
    if (bmp.getWidth() != width || bmp.getHeight() != width) {
      sbmp = Bitmap.createScaledBitmap(bmp, width, width, false);
    } else {
      sbmp = bmp;
    }
    Bitmap output = Bitmap.createBitmap(sbmp.getWidth(), sbmp.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, sbmp.getWidth(), sbmp.getHeight());

    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(Color.parseColor("#BAB399"));
    canvas.drawCircle(
        sbmp.getWidth() / 2 + 0.7f, sbmp.getHeight() / 2 + 0.7f, sbmp.getWidth() / 2 + 0.1f, paint);
    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(sbmp, rect, rect, paint);
    return output;
  }
Ejemplo n.º 13
0
 public static Paint createBitmapPaint() {
   Paint paint = new Paint();
   paint.setDither(true);
   paint.setFilterBitmap(true);
   paint.setAntiAlias(true);
   return paint;
 }
Ejemplo n.º 14
0
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    Drawable mDrawable = getDrawable();
    if (mDrawable == null) {
      return;
    }

    if (mDrawable.getIntrinsicWidth() == 0 || mDrawable.getIntrinsicHeight() == 0) {
      return; // nothing to draw (empty bounds)
    }

    if (null == maskBitmap) {
      return;
    }

    int saveCount = canvas.getSaveCount();
    canvas.save();
    paint.setFilterBitmap(false);
    paint.setXfermode(mXfermode);
    canvas.drawBitmap(maskBitmap, null, mRoundRect, paint);
    paint.setXfermode(null);
    canvas.restoreToCount(saveCount);
  }
 Engine() {
   super();
   prefs = GalleryWallpaper.this.getSharedPreferences(SHARED_PREFS_NAME, Context.MODE_PRIVATE);
   prefs.registerOnSharedPreferenceChangeListener(this);
   this.onSharedPreferenceChanged(prefs, GalleryWallpaper.SHARED_PREFS_REPLACEIMAGE);
   this.onSharedPreferenceChanged(prefs, GalleryWallpaper.SHARED_PREFS_SYNC);
   onSharedPreferenceChanged(prefs, null);
   backgroundPaint.setFilterBitmap(false);
   backgroundPaint.setAntiAlias(true);
   backgroundPaint.setColor(Color.BLACK);
   textPaint.setAntiAlias(true);
   textPaint.setColor(Color.WHITE);
   textPaint.setShadowLayer(5f, 1f, 1f, Color.GRAY);
   textPaint.setSubpixelText(true);
   textPaint.setTextAlign(Paint.Align.LEFT);
   textPaint.setTextSize(18);
   textPaint.setTypeface(Typeface.MONOSPACE);
   this.setTouchEventsEnabled(true);
   if (Build.VERSION.SDK_INT >= 14) {
     try {
       // hinting = textPaint.HINTING_ON;
       int hinting = textPaint.getClass().getField("HINTING_ON").getInt(textPaint);
       // textPaint.setHinting(hinting);
       textPaint.getClass().getMethod("setHinting", int.class).invoke(textPaint, hinting);
     } catch (IllegalAccessException e) {
       System.err.println(e.toString());
     } catch (InvocationTargetException e) {
       System.err.println(e.toString());
     } catch (NoSuchMethodException e) {
       System.err.println(e.toString());
     } catch (NoSuchFieldException e) {
       System.err.println(e.toString());
     }
   }
 }
Ejemplo n.º 16
0
  public static final Bitmap getMiniThumb(
      final Bitmap bitmap, final int thumbnailWidth, final int thumbnailHeight) {
    if (null == bitmap) return null;

    final int width = bitmap.getWidth();
    final int height = bitmap.getHeight();
    // Detect faces to find the focal point, otherwise fall back to the
    // image center.
    int focusX = width / 2;
    int focusY = height / 2;
    // We have commented out face detection since it slows down the
    // generation of the thumbnail and screennail.

    // final FaceDetector faceDetector = new FaceDetector(width, height, 1);
    // final FaceDetector.Face[] faces = new FaceDetector.Face[1];
    // final int numFaces = faceDetector.findFaces(bitmap, faces);
    // if (numFaces > 0 && faces[0].confidence() >=
    // FaceDetector.Face.CONFIDENCE_THRESHOLD) {
    // final PointF midPoint = new PointF();
    // faces[0].getMidPoint(midPoint);
    // focusX = (int) midPoint.x;
    // focusY = (int) midPoint.y;
    // }

    // Crop to thumbnail aspect ratio biased towards the focus point.
    int cropX;
    int cropY;
    int cropWidth;
    int cropHeight;
    float scaleFactor;
    if (thumbnailWidth * height < thumbnailHeight * width) {
      // Vertically constrained.
      cropWidth = thumbnailWidth * height / thumbnailHeight;
      cropX = Math.max(0, Math.min(focusX - cropWidth / 2, width - cropWidth));
      cropY = 0;
      cropHeight = height;
      scaleFactor = (float) thumbnailHeight / height;
    } else {
      // Horizontally constrained.
      cropHeight = thumbnailHeight * width / thumbnailWidth;
      cropY = Math.max(0, Math.min(focusY - cropHeight / 2, height - cropHeight));
      cropX = 0;
      cropWidth = width;
      scaleFactor = (float) thumbnailWidth / width;
    }
    final Bitmap finalBitmap =
        Bitmap.createBitmap(thumbnailWidth, thumbnailHeight, Bitmap.Config.RGB_565);
    final Canvas canvas = new Canvas(finalBitmap);
    final Paint paint = new Paint();
    paint.setFilterBitmap(true);
    canvas.drawColor(0);
    canvas.drawBitmap(
        bitmap,
        new Rect(cropX, cropY, cropX + cropWidth, cropY + cropHeight),
        new Rect(0, 0, thumbnailWidth, thumbnailHeight),
        paint);
    bitmap.recycle();

    return finalBitmap;
  }
Ejemplo n.º 17
0
  public static Bitmap getCroppedBitmap(Bitmap bmp, int radius) {
    Bitmap sbmp;

    if (bmp.getWidth() != radius || bmp.getHeight() != radius) {
      float smallest = Math.min(bmp.getWidth(), bmp.getHeight());
      float factor = smallest / radius;
      sbmp =
          Bitmap.createScaledBitmap(
              bmp, (int) (bmp.getWidth() / factor), (int) (bmp.getHeight() / factor), false);
    } else {
      sbmp = bmp;
    }

    Bitmap output = Bitmap.createBitmap(radius, radius, Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    final int color = 0xffa19774;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0, 0, radius, radius);

    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(Color.parseColor("#FFFFFF"));
    canvas.drawCircle(radius / 2, radius / 2, radius / 2 + 0.1f, paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(sbmp, rect, rect, paint);

    return output;
  }
Ejemplo n.º 18
0
  @Override
  protected void onDraw(Canvas canvas) {
    if (mImage != null) {
      // Switch the current animation if needed.
      if (mCurrentAnim == null || mCurrentAnim.hasEnded()) switchAnimation(canvas);

      // Animate and draw
      mCurrentAnim.getTransformation(AnimationUtils.currentAnimationTimeMillis(), mTrans);
      mStartPos[0] = 0;
      mStartPos[1] = 0;
      mTrans.getMatrix().mapPoints(mStartPos);

      mSrc.set(0, 0, mImage.getWidth(), mImage.getHeight());
      mDst.set(
          (int) mStartPos[0],
          (int) mStartPos[1],
          (int) mStartPos[0] + mScaledImageWidth,
          (int) mStartPos[1] + mScaledImageHeight);
      mPaint.setFilterBitmap(true);
      canvas.drawBitmap(mImage, mSrc, mDst, mPaint);
      super.onDraw(canvas);

      // Request another draw operation until time is up.
      invalidate();
    }
  }
 public ClippingImageView(Context context) {
   super(context);
   paint = new Paint();
   paint.setFilterBitmap(true);
   matrix = new Matrix();
   drawRect = new RectF();
   bitmapRect = new RectF();
 }
Ejemplo n.º 20
0
 @Override
 protected void drawShape(Canvas canvas, Bitmap image) {
   gPaint.setAntiAlias(true);
   gPaint.setFilterBitmap(true);
   gPaint.setDither(true);
   gPaint.setARGB(255, 255, 255, 255);
   drawTransformedCropped(canvas, image, gPaint);
 }
Ejemplo n.º 21
0
  /**
   * 获取裁剪后的圆形图片
   *
   * @param radius 半径
   */
  public Bitmap getCroppedRoundBitmap(Bitmap bmp, int radius) {
    Bitmap scaledSrcBmp;
    int diameter = radius * 2;

    // 为了防止宽高不相等,造成圆形图片变形,因此截取长方形中处于中间位置最大的正方形图片
    int bmpWidth = bmp.getWidth();
    int bmpHeight = bmp.getHeight();
    int squareWidth = 0, squareHeight = 0;
    int x = 0, y = 0;
    Bitmap squareBitmap;
    if (bmpHeight > bmpWidth) { // 高大于宽
      squareWidth = squareHeight = bmpWidth;
      x = 0;
      y = (bmpHeight - bmpWidth) / 2;
      // 截取正方形图片
      squareBitmap = Bitmap.createBitmap(bmp, x, y, squareWidth, squareHeight);
    } else if (bmpHeight < bmpWidth) { // 宽大于高
      squareWidth = squareHeight = bmpHeight;
      x = (bmpWidth - bmpHeight) / 2;
      y = 0;
      squareBitmap = Bitmap.createBitmap(bmp, x, y, squareWidth, squareHeight);
    } else {
      squareBitmap = bmp;
    }

    if (squareBitmap.getWidth() != diameter || squareBitmap.getHeight() != diameter) {
      scaledSrcBmp = Bitmap.createScaledBitmap(squareBitmap, diameter, diameter, true);

    } else {
      scaledSrcBmp = squareBitmap;
    }
    Bitmap output =
        Bitmap.createBitmap(scaledSrcBmp.getWidth(), scaledSrcBmp.getHeight(), Config.ARGB_8888);
    Canvas canvas = new Canvas(output);

    Paint paint = new Paint();
    Rect rect = new Rect(0, 0, scaledSrcBmp.getWidth(), scaledSrcBmp.getHeight());

    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);
    paint.setDither(true);
    canvas.drawARGB(0, 0, 0, 0);
    canvas.drawCircle(
        scaledSrcBmp.getWidth() / 2,
        scaledSrcBmp.getHeight() / 2,
        scaledSrcBmp.getWidth() / 2,
        paint);
    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
    canvas.drawBitmap(scaledSrcBmp, rect, rect, paint);
    // bitmap回收(recycle导致在布局文件XML看不到效果)
    // bmp.recycle();
    // squareBitmap.recycle();
    // scaledSrcBmp.recycle();
    bmp = null;
    squareBitmap = null;
    scaledSrcBmp = null;
    return output;
  }
Ejemplo n.º 22
0
    /** set graph line color */
    private void setPaint() {
      p = new Paint();
      p.setFlags(Paint.ANTI_ALIAS_FLAG);
      p.setAntiAlias(true); // text anti alias
      p.setFilterBitmap(true); // bitmap anti alias
      p.setColor(Color.BLUE);
      p.setStrokeWidth(3);
      p.setStyle(Style.STROKE);

      pCircle = new Paint();
      pCircle.setFlags(Paint.ANTI_ALIAS_FLAG);
      pCircle.setAntiAlias(true); // text anti alias
      pCircle.setFilterBitmap(true); // bitmap anti alias
      pCircle.setColor(Color.BLUE);
      pCircle.setStrokeWidth(3);
      pCircle.setStyle(Style.FILL_AND_STROKE);

      pLine = new Paint();
      pLine.setFlags(Paint.ANTI_ALIAS_FLAG);
      pLine.setAntiAlias(true); // text anti alias
      pLine.setFilterBitmap(true); // bitmap anti alias
      pLine.setShader(
          new LinearGradient(0, 300f, 0, 0f, Color.BLACK, Color.WHITE, Shader.TileMode.MIRROR));

      pBaseLine = new Paint();
      pBaseLine.setFlags(Paint.ANTI_ALIAS_FLAG);
      pBaseLine.setAntiAlias(true); // text anti alias
      pBaseLine.setFilterBitmap(true); // bitmap anti alias
      pBaseLine.setColor(Color.GRAY);
      pBaseLine.setStrokeWidth(3);

      pBaseLineX = new Paint();
      pBaseLineX.setFlags(Paint.ANTI_ALIAS_FLAG);
      pBaseLineX.setAntiAlias(true); // text anti alias
      pBaseLineX.setFilterBitmap(true); // bitmap anti alias
      pBaseLineX.setColor(0xffcccccc);
      pBaseLineX.setStrokeWidth(3);
      pBaseLineX.setStyle(Style.STROKE);
      pBaseLineX.setPathEffect(new DashPathEffect(new float[] {10, 5}, 0));

      pMarkText = new Paint();
      pMarkText.setFlags(Paint.ANTI_ALIAS_FLAG);
      pMarkText.setAntiAlias(true); // text anti alias
      pMarkText.setColor(Color.BLACK);
    }
Ejemplo n.º 23
0
 public static void setFrameFiltering(boolean value) {
   frameFiltering = value;
   if (value) {
     emuPaint = new Paint();
     emuPaint.setFilterBitmap(true);
   } else {
     emuPaint = null;
   }
 }
Ejemplo n.º 24
0
  public SimpleGraphView(final Context context, final AttributeSet attrs, final int defStyle) {
    super(context, attrs, defStyle);

    final Resources res = context.getResources();

    bitmapPaint = new Paint();
    bitmapPaint.setFilterBitmap(true);

    final Bitmap backgroundBitmap = BitmapFactory.decodeResource(res, R.drawable.test_box_small);
    width = backgroundBitmap.getWidth();
    height = backgroundBitmap.getHeight();
    genBackgroundBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    final Canvas canvas = new Canvas(genBackgroundBitmap);
    // canvas.drawBitmap(backgroundBitmap, 0, 0, bitmapPaint);

    if (!isInEditMode()) backgroundBitmap.recycle();

    final Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setTextSize(coordFH(15, relH));
    paint.setColor(Color.parseColor("#C8ffffff"));
    paint.setTextAlign(Align.LEFT);
    canvas.drawText("0", coordFW(88, relW), coordFH(220, relH), paint);
    paint.setTextAlign(Align.RIGHT);
    canvas.drawText("8", coordFW(567, relW), coordFH(220, relH), paint);
    paint.setTextAlign(Align.CENTER);
    canvas.drawText("sec", coordFW(326, relW), coordFH(220, relH), paint);

    paint.setTextAlign(Align.LEFT);
    paint.setColor(Color.parseColor("#C800f940"));
    canvas.drawText(
        String.format("– %s", res.getString(R.string.test_mbps)),
        coordFW(9, relW),
        coordFH(110, relH),
        paint);
    paint.setTextAlign(Align.RIGHT);
    canvas.drawText("0", coordFW(72, relW), coordFH(220, relH), paint);
    canvas.drawText("100", coordFW(72, relW), coordFH(38, relH), paint);

    gridBitmap = BitmapFactory.decodeResource(res, R.drawable.test_grid);
    gridX = coordFW(55, relW);
    gridY = coordFH(16, relH);
    graphX = coordFW(80, relW);
    graphY = coordFH(16, relH);
    graphWidth = coordW(493, relW);
    graphHeight = coordH(183, relH);
    graphStrokeWidth = coordFW(4, relW);

    signalTextPaint = new Paint();
    signalTextPaint.setAntiAlias(true);
    signalTextPaint.setTypeface(Typeface.DEFAULT_BOLD);
    signalTextPaint.setTextSize(coordFH(15, relH));
    signalTextPaint.setColor(Color.parseColor("#C8f8a000"));

    signalText = res.getString(R.string.test_dbm);
  }
Ejemplo n.º 25
0
 public static Paint createFillPaint(int color) {
   Paint paint = new Paint();
   paint.setStyle(Paint.Style.FILL);
   paint.setAntiAlias(true);
   paint.setFilterBitmap(false);
   paint.setColor(color);
   paint.setDither(true);
   return paint;
 }
Ejemplo n.º 26
0
 public void paintBitmap(Context context, Canvas c, Rect dest) {
   if (bitmap == null) {
     bitmap = getResBitmap(context.getResources(), R.drawable.skull);
     paint = new Paint();
     paint.setAntiAlias(false);
     paint.setFilterBitmap(true);
   }
   c.drawBitmap(bitmap, null, dest, paint);
 }
Ejemplo n.º 27
0
    /** draw graph without animation */
    private void drawGraphRegionWithoutAnimation(GraphCanvasWrapper graphCanvas) {

      boolean isDrawRegion = mLineGraphVO.isDrawRegion();

      for (int i = 0; i < mLineGraphVO.getArrGraph().size(); i++) {
        GraphPath regionPath =
            new GraphPath(
                width, height, mLineGraphVO.getPaddingLeft(), mLineGraphVO.getPaddingBottom());
        boolean firstSet = false;
        float x = 0;
        float y = 0;
        p.setColor(mLineGraphVO.getArrGraph().get(i).getColor());
        pCircle.setColor(mLineGraphVO.getArrGraph().get(i).getColor());
        float xGap = xLength / (mLineGraphVO.getArrGraph().get(i).getCoordinateArr().length - 1);

        for (int j = 0; j < mLineGraphVO.getArrGraph().get(i).getCoordinateArr().length; j++) {
          if (j < mLineGraphVO.getArrGraph().get(i).getCoordinateArr().length) {

            if (!firstSet) {

              x = xGap * j;
              y =
                  yLength
                      * mLineGraphVO.getArrGraph().get(i).getCoordinateArr()[j]
                      / mLineGraphVO.getMaxValue();

              regionPath.moveTo(x, 0);
              regionPath.lineTo(x, y);

              firstSet = true;
            } else {
              x = xGap * j;
              y =
                  yLength
                      * mLineGraphVO.getArrGraph().get(i).getCoordinateArr()[j]
                      / mLineGraphVO.getMaxValue();

              regionPath.lineTo(x, y);
            }
          }
        }

        if (isDrawRegion) {
          regionPath.lineTo(x, 0);
          regionPath.lineTo(0, 0);

          Paint pBg = new Paint();
          pBg.setFlags(Paint.ANTI_ALIAS_FLAG);
          pBg.setAntiAlias(true); // text anti alias
          pBg.setFilterBitmap(true); // bitmap anti alias
          pBg.setStyle(Style.FILL);
          pBg.setColor(mLineGraphVO.getArrGraph().get(i).getColor());
          graphCanvas.getCanvas().drawPath(regionPath, pBg);
        }
      }
    }
Ejemplo n.º 28
0
 private void drawCircleBorder(Canvas canvas, int radius, int color) {
   Paint paint = new Paint();
   paint.setAntiAlias(true);
   paint.setFilterBitmap(true);
   paint.setDither(true);
   paint.setColor(color);
   paint.setStyle(Paint.Style.STROKE);
   paint.setStrokeWidth(mBorderThickness);
   canvas.drawCircle(defaultWidth / 2, defaultHeight / 2, radius, paint);
 }
Ejemplo n.º 29
0
  @SuppressLint("DrawAllocation")
  @Override
  protected void onDraw(Canvas canvas) {
    if (!isInEditMode()) {
      int i = canvas.saveLayer(0.0f, 0.0f, getWidth(), getHeight(), null, Canvas.ALL_SAVE_FLAG);
      try {
        Bitmap bitmap = mWeakBitmap != null ? mWeakBitmap.get() : null;
        // Bitmap not loaded.
        if (bitmap == null || bitmap.isRecycled()) {
          Drawable drawable = getDrawable();
          if (drawable != null) {
            // Allocation onDraw but it's ok because it will not always be called.
            bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888);
            Canvas bitmapCanvas = new Canvas(bitmap);
            drawable.setBounds(0, 0, getWidth(), getHeight());
            drawable.draw(bitmapCanvas);

            // If mask is already set, skip and use cached mask.
            if (mMaskBitmap == null || mMaskBitmap.isRecycled()) {
              mMaskBitmap = getBitmap();
            }

            // Draw Bitmap.
            mPaint.reset();
            mPaint.setFilterBitmap(false);
            mPaint.setXfermode(sXfermode);
            //                        mBitmapShader = new BitmapShader(mMaskBitmap,
            //                                Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
            //                        mPaint.setShader(mBitmapShader);
            bitmapCanvas.drawBitmap(mMaskBitmap, 0.0f, 0.0f, mPaint);

            mWeakBitmap = new WeakReference<Bitmap>(bitmap);
          }
        }

        // Bitmap already loaded.
        if (bitmap != null) {
          mPaint.setXfermode(null);
          //                    mPaint.setShader(null);
          canvas.drawBitmap(bitmap, 0.0f, 0.0f, mPaint);
          return;
        }
      } catch (Exception e) {
        System.gc();

        LogUtil.e(
            TAG,
            String.format("Failed to draw, Id :: %s. Error occurred :: %s", getId(), e.toString()));
      } finally {
        canvas.restoreToCount(i);
      }
    } else {
      super.onDraw(canvas);
    }
  }
 public SelectionShapeDrawController(Context context, float f1, RectF rectf, Rect rect)
 {
     w = new CornerPathEffect(3F);
     x = new DashPathEffect(u, 0.0F);
     y = new DashPathEffect(v, 1.0F);
     z = new ComposePathEffect(w, x);
     A = new ComposePathEffect(w, y);
     d = new Path();
     e = null;
     i = false;
     j = false;
     k = false;
     p = new Matrix();
     q = new RectF();
     r = new RectF();
     a = f1;
     b = rectf;
     c = rect;
     f = new Paint();
     f.setFilterBitmap(true);
     f1 = (Utils.a(1.0F, context) * 2.0F) / 3F;
     g = new Paint();
     g.setAntiAlias(true);
     g.setStyle(android.graphics.Paint.Style.STROKE);
     g.setStrokeJoin(android.graphics.Paint.Join.ROUND);
     g.setStrokeCap(android.graphics.Paint.Cap.ROUND);
     g.setStrokeWidth(f1);
     g.setFilterBitmap(true);
     g.setColor(-1);
     g.setPathEffect(z);
     h = new Paint();
     h.setAntiAlias(true);
     h.setStyle(android.graphics.Paint.Style.STROKE);
     h.setStrokeJoin(android.graphics.Paint.Join.ROUND);
     h.setStrokeCap(android.graphics.Paint.Cap.ROUND);
     h.setStrokeWidth(f1);
     h.setFilterBitmap(true);
     h.setColor(0xff000000);
     h.setPathEffect(A);
     a(SelectionShapeType.RECTANGLE);
 }