Java Code Examples for android.graphics.Paint.setFlags()

The following are Jave code examples for showing how to use setFlags() of the android.graphics.Paint class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: PicShow-zhaipin   File: FastBlur.java   View Source Code Vote up 6 votes
public static void blur(Context context,Bitmap bkg, View view) {
    long startMs = System.currentTimeMillis();
    float radius = 15;
    float scaleFactor = 8;
    //放大到整个view的大小
    bkg = DrawableProvider.getReSizeBitmap(bkg, view.getMeasuredWidth(), view.getMeasuredHeight());

    Bitmap overlay = Bitmap.createBitmap((int) (view.getMeasuredWidth() / scaleFactor)
            , (int) (view.getMeasuredHeight() / scaleFactor), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(overlay);
    canvas.translate(-view.getLeft() / scaleFactor, -view.getTop() / scaleFactor);
    canvas.scale(1 / scaleFactor, 1 / scaleFactor);
    Paint paint = new Paint();
    paint.setFlags(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(bkg, 0, 0, paint);
    overlay = FastBlur.doBlur(overlay, (int) radius, true);
    view.setBackgroundDrawable(new BitmapDrawable(context.getResources(), overlay));
    Log.w("test", "cost " + (System.currentTimeMillis() - startMs) + "ms");
}
 
Example 2
Project: letv   File: BlurUtils.java   View Source Code Vote up 6 votes
@SuppressLint({"NewApi"})
public static void blur_3(Context context, Bitmap bkg, View view) {
    long startMs = System.currentTimeMillis();
    Display d = ((Activity) context).getWindowManager().getDefaultDisplay();
    Bitmap overlay = Bitmap.createBitmap((int) (((float) d.getWidth()) / 1.0f), (int) (((float) d.getHeight()) / 1.0f), Config.ARGB_8888);
    Canvas canvas = new Canvas(overlay);
    canvas.scale(1.0f / 1.0f, 1.0f / 1.0f);
    Paint paint = new Paint();
    paint.setFlags(2);
    canvas.drawBitmap(bkg, 0.0f, 0.0f, paint);
    overlay = FastBlur.doBlur(overlay, (int) 100.0f, true);
    if (LetvUtils.getSDKVersion() >= 16) {
        view.setBackground(new BitmapDrawable(context.getResources(), overlay));
    } else {
        view.setBackgroundDrawable(new BitmapDrawable(context.getResources(), overlay));
    }
}
 
Example 3
Project: GitHub   File: FastBlur.java   View Source Code Vote up 6 votes
public static void blur(Bitmap bkg, View view) {
    long startMs = System.currentTimeMillis();
    float radius = 15;
    float scaleFactor = 8;
    //放大到整个view的大小
    bkg = DrawableProvider.getReSizeBitmap(bkg, view.getMeasuredWidth(), view.getMeasuredHeight());

    Bitmap overlay = Bitmap.createBitmap((int) (view.getMeasuredWidth() / scaleFactor)
            , (int) (view.getMeasuredHeight() / scaleFactor), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(overlay);
    canvas.translate(-view.getLeft() / scaleFactor, -view.getTop() / scaleFactor);
    canvas.scale(1 / scaleFactor, 1 / scaleFactor);
    Paint paint = new Paint();
    paint.setFlags(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(bkg, 0, 0, paint);
    overlay = FastBlur.doBlur(overlay, (int) radius, true);
    view.setBackgroundDrawable(new BitmapDrawable(UiUtils.getResources(), overlay));
    Log.w("test", "cost " + (System.currentTimeMillis() - startMs) + "ms");
}
 
Example 4
Project: yyox   File: FastBlur.java   View Source Code Vote up 6 votes
public static void blur(Context context,Bitmap bkg, View view) {
    long startMs = System.currentTimeMillis();
    float radius = 15;
    float scaleFactor = 8;
    //放大到整个view的大小
    bkg = DrawableProvider.getReSizeBitmap(bkg, view.getMeasuredWidth(), view.getMeasuredHeight());

    Bitmap overlay = Bitmap.createBitmap((int) (view.getMeasuredWidth() / scaleFactor)
            , (int) (view.getMeasuredHeight() / scaleFactor), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(overlay);
    canvas.translate(-view.getLeft() / scaleFactor, -view.getTop() / scaleFactor);
    canvas.scale(1 / scaleFactor, 1 / scaleFactor);
    Paint paint = new Paint();
    paint.setFlags(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(bkg, 0, 0, paint);
    overlay = FastBlur.doBlur(overlay, (int) radius, true);
    view.setBackgroundDrawable(new BitmapDrawable(context.getResources(), overlay));
    Log.w("test", "cost " + (System.currentTimeMillis() - startMs) + "ms");
}
 
Example 5
Project: ChatExchange-old   File: SpotlightView.java   View Source Code Vote up 6 votes
private void init(Context context) {
    setWillNotDraw(false);
    setVisibility(INVISIBLE);

    lineStroke = Utils.dpToPx(4);
    isReady = false;
    isRevealAnimationEnabled = true;
    dismissOnTouch = false;
    isPerformClick = false;
    enableDismissAfterShown = false;
    dismissOnBackPress = false;
    handler = new Handler();
    preferencesManager = new PreferencesManager(context);
    eraser = new Paint();
    eraser.setColor(0xFFFFFFFF);
    eraser.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
    eraser.setFlags(Paint.ANTI_ALIAS_FLAG);
}
 
Example 6
Project: AppCommonFrame   File: FastBlur.java   View Source Code Vote up 6 votes
public static void blur(Bitmap bkg, View view) {
    long startMs = System.currentTimeMillis();
    float radius = 15;
    float scaleFactor = 8;
    //放大到整个view的大小
    bkg = DrawableProvider.getReSizeBitmap(bkg, view.getMeasuredWidth(), view.getMeasuredHeight());

    Bitmap overlay = Bitmap.createBitmap((int) (view.getMeasuredWidth() / scaleFactor)
            , (int) (view.getMeasuredHeight() / scaleFactor), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(overlay);
    canvas.translate(-view.getLeft() / scaleFactor, -view.getTop() / scaleFactor);
    canvas.scale(1 / scaleFactor, 1 / scaleFactor);
    Paint paint = new Paint();
    paint.setFlags(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(bkg, 0, 0, paint);
    overlay = FastBlur.doBlur(overlay, (int) radius, true);
    view.setBackgroundDrawable(new BitmapDrawable(UiUtils.getResources(), overlay));
    Log.w("test", "cost " + (System.currentTimeMillis() - startMs) + "ms");
}
 
Example 7
Project: AppCommonFrame   File: FastBlur.java   View Source Code Vote up 6 votes
public static Bitmap blurBitmap(Bitmap bkg, int width, int height) {
    long startMs = System.currentTimeMillis();
    float radius = 15;//越大模糊效果越大
    float scaleFactor = 8;
    //放大到整个view的大小
    bkg = DrawableProvider.getReSizeBitmap(bkg, width, height);
    Bitmap overlay = Bitmap.createBitmap((int) (width / scaleFactor)
            , (int) (height / scaleFactor), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(overlay);
    canvas.scale(1 / scaleFactor, 1 / scaleFactor);
    Paint paint = new Paint();
    paint.setFlags(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(bkg, 0, 0, paint);
    overlay = FastBlur.doBlur(overlay, (int) radius, true);
    Log.w("test", "cost " + (System.currentTimeMillis() - startMs) + "ms");
    return overlay;
}
 
Example 8
Project: NeiHanDuanZiTV   File: FastBlur.java   View Source Code Vote up 6 votes
public static void blur(Context context, Bitmap bkg, View view) {
    long startMs = System.currentTimeMillis();
    float radius = 15;
    float scaleFactor = 8;
    //放大到整个view的大小
    bkg = DrawableProvider.getReSizeBitmap(bkg, view.getMeasuredWidth(), view.getMeasuredHeight());

    Bitmap overlay = Bitmap.createBitmap((int) (view.getMeasuredWidth() / scaleFactor)
            , (int) (view.getMeasuredHeight() / scaleFactor), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(overlay);
    canvas.translate(-view.getLeft() / scaleFactor, -view.getTop() / scaleFactor);
    canvas.scale(1 / scaleFactor, 1 / scaleFactor);
    Paint paint = new Paint();
    paint.setFlags(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(bkg, 0, 0, paint);
    overlay = FastBlur.doBlur(overlay, (int) radius, true);
    view.setBackgroundDrawable(new BitmapDrawable(context.getResources(), overlay));
    Log.w("test", "cost " + (System.currentTimeMillis() - startMs) + "ms");
}
 
Example 9
Project: MVPArmsTest1   File: FastBlur.java   View Source Code Vote up 6 votes
public static void blur(Context context, Bitmap bkg, View view) {
    long startMs = System.currentTimeMillis();
    float radius = 15;
    float scaleFactor = 8;
    //放大到整个view的大小
    bkg = DrawableProvider.getReSizeBitmap(bkg, view.getMeasuredWidth(), view.getMeasuredHeight());

    Bitmap overlay = Bitmap.createBitmap((int) (view.getMeasuredWidth() / scaleFactor)
            , (int) (view.getMeasuredHeight() / scaleFactor), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(overlay);
    canvas.translate(-view.getLeft() / scaleFactor, -view.getTop() / scaleFactor);
    canvas.scale(1 / scaleFactor, 1 / scaleFactor);
    Paint paint = new Paint();
    paint.setFlags(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(bkg, 0, 0, paint);
    overlay = FastBlur.doBlur(overlay, (int) radius, true);
    view.setBackgroundDrawable(new BitmapDrawable(context.getResources(), overlay));
    Log.w("test", "cost " + (System.currentTimeMillis() - startMs) + "ms");
}
 
Example 10
Project: MVPArms_Fragment-fragment   File: FastBlur.java   View Source Code Vote up 6 votes
public static void blur(Context context, Bitmap bkg, View view) {
    long startMs = System.currentTimeMillis();
    float radius = 15;
    float scaleFactor = 8;
    //放大到整个view的大小
    bkg = DrawableProvider.getReSizeBitmap(bkg, view.getMeasuredWidth(), view.getMeasuredHeight());

    Bitmap overlay = Bitmap.createBitmap((int) (view.getMeasuredWidth() / scaleFactor)
            , (int) (view.getMeasuredHeight() / scaleFactor), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(overlay);
    canvas.translate(-view.getLeft() / scaleFactor, -view.getTop() / scaleFactor);
    canvas.scale(1 / scaleFactor, 1 / scaleFactor);
    Paint paint = new Paint();
    paint.setFlags(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(bkg, 0, 0, paint);
    overlay = FastBlur.doBlur(overlay, (int) radius, true);
    view.setBackgroundDrawable(new BitmapDrawable(context.getResources(), overlay));
    Log.w("test", "cost " + (System.currentTimeMillis() - startMs) + "ms");
}
 
Example 11
Project: asaf-project   File: AnimatedTastyRatingBar.java   View Source Code Vote up 5 votes
@Override
public void onFinishInflate() {
    super.onFinishInflate();

    backgroundColour = CustomApp.getInstance().getResources().getColor(R.color.colorPrimary);
    progressColour = CustomApp.getInstance().getResources().getColor(R.color.colorPrimaryDark);

    paint = new Paint();
    paint.setFlags(Paint.ANTI_ALIAS_FLAG);
    paint.setStyle(Paint.Style.FILL_AND_STROKE);
}
 
Example 12
Project: OneWeather   File: BlurTransformation.java   View Source Code Vote up 5 votes
@Override
protected Bitmap transform(@NonNull BitmapPool pool, @NonNull Bitmap toTransform, int outWidth, int outHeight) {
    int width = toTransform.getWidth();
    int height = toTransform.getHeight();
    int scaledWidth = width / sampling;
    int scaledHeight = height / sampling;

    Bitmap bitmap = pool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(bitmap);
    canvas.scale(1 / (float) sampling, 1 / (float) sampling);
    Paint paint = new Paint();
    paint.setFlags(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(toTransform, 0, 0, paint);
    // Allocate memory for Renderscript to work with
    Allocation input = Allocation.createFromBitmap(
            rs,
            bitmap,
            Allocation.MipmapControl.MIPMAP_FULL,
            Allocation.USAGE_SHARED
    );
    Allocation output = Allocation.createTyped(rs, input.getType());
    rs.setMessageHandler(new RenderScript.RSMessageHandler());

    // Load up an instance of the specific script that we want to use.
    ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
    script.setInput(input);

    // Set the blur radius
    script.setRadius(radius);

    // Start the ScriptIntrinisicBlur
    script.forEach(output);

    // Copy the output to the blurred bitmap
    output.copyTo(bitmap);


    return bitmap;
}
 
Example 13
Project: GitHub   File: Blur.java   View Source Code Vote up 5 votes
public static Bitmap of(Context context, Bitmap source, BlurFactor factor) {
  int width = factor.width / factor.sampling;
  int height = factor.height / factor.sampling;

  if (Helper.hasZero(width, height)) {
    return null;
  }

  Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);

  Canvas canvas = new Canvas(bitmap);
  canvas.scale(1 / (float) factor.sampling, 1 / (float) factor.sampling);
  Paint paint = new Paint();
  paint.setFlags(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG);
  PorterDuffColorFilter filter =
      new PorterDuffColorFilter(factor.color, PorterDuff.Mode.SRC_ATOP);
  paint.setColorFilter(filter);
  canvas.drawBitmap(source, 0, 0, paint);

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
    try {
      bitmap = Blur.rs(context, bitmap, factor.radius);
    } catch (RSRuntimeException e) {
      bitmap = Blur.stack(bitmap, factor.radius, true);
    }
  } else {
    bitmap = Blur.stack(bitmap, factor.radius, true);
  }

  if (factor.sampling == BlurFactor.DEFAULT_SAMPLING) {
    return bitmap;
  } else {
    Bitmap scaled = Bitmap.createScaledBitmap(bitmap, factor.width, factor.height, true);
    bitmap.recycle();
    return scaled;
  }
}
 
Example 14
Project: MultiContactPicker   File: RoundLetterView.java   View Source Code Vote up 5 votes
private void init(AttributeSet attrs, int defStyle) {
    final TypedArray a = getContext().obtainStyledAttributes(
            attrs, R.styleable.RoundedLetterView, defStyle, 0);

    if(a.hasValue(R.styleable.RoundedLetterView_rlv_titleText)){
        mTitleText = a.getString(R.styleable.RoundedLetterView_rlv_titleText);
    }

    mTitleColor = a.getColor(R.styleable.RoundedLetterView_rlv_titleColor,DEFAULT_TITLE_COLOR);
    mBackgroundColor = a.getColor(R.styleable.RoundedLetterView_rlv_backgroundColorValue,DEFAULT_BACKGROUND_COLOR);

    mTitleSize = a.getDimension(R.styleable.RoundedLetterView_rlv_titleSize,DEFAULT_TITLE_SIZE);
    a.recycle();

    //Title TextPaint
    mTitleTextPaint = new TextPaint();
    mTitleTextPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
    mTitleTextPaint.setTypeface(mFont);
    mTitleTextPaint.setTextAlign(Paint.Align.CENTER);
    mTitleTextPaint.setLinearText(true);
    mTitleTextPaint.setColor(mTitleColor);
    mTitleTextPaint.setTextSize(mTitleSize);

    //Background Paint
    mBackgroundPaint = new Paint();
    mBackgroundPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
    mBackgroundPaint.setStyle(Paint.Style.FILL);
    mBackgroundPaint.setColor(mBackgroundColor);

    mInnerRectF = new RectF();
}
 
Example 15
Project: GeekZone   File: BlurTransformation.java   View Source Code Vote up 5 votes
@Override
public Resource<Bitmap> transform(Resource<Bitmap> resource, int outWidth, int outHeight) {
    Bitmap source = resource.get();

    int width = source.getWidth();
    int height = source.getHeight();
    int scaledWidth = width / mSampling;
    int scaledHeight = height / mSampling;

    Bitmap bitmap = mBitmapPool.get(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
    if (bitmap == null) {
        bitmap = Bitmap.createBitmap(scaledWidth, scaledHeight, Bitmap.Config.ARGB_8888);
    }

    Canvas canvas = new Canvas(bitmap);
    canvas.scale(1 / (float) mSampling, 1 / (float) mSampling);
    Paint paint = new Paint();
    paint.setFlags(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(source, 0, 0, paint);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
        try {
            bitmap = RSBlur.blur(mContext, bitmap, mRadius);
        } catch (RSRuntimeException e) {
            bitmap = FastBlur.blur(bitmap, mRadius, true);
        }
    } else {
        bitmap = FastBlur.blur(bitmap, mRadius, true);
    }

    return BitmapResource.obtain(bitmap, mBitmapPool);
}
 
Example 16
Project: RoundChoiceView   File: RoundChoiceView.java   View Source Code Vote up 5 votes
private void init(AttributeSet attrs, int defStyle) {
    mDensity = getContext().getResources().getDisplayMetrics().density;
    scaledDensity = getContext().getResources().getDisplayMetrics().scaledDensity;

    // Load attributes
    final TypedArray a = getContext().obtainStyledAttributes(
            attrs, R.styleable.RoundChoiceView, defStyle, 0);
    mUnCheckColor = a.getColor(R.styleable.RoundChoiceView_borderColor, mUnCheckColor);
    mCheckColor = a.getColor(R.styleable.RoundChoiceView_checkedColor, mCheckColor);
    mCrossColor = a.getColor(R.styleable.RoundChoiceView_crossColor, mCrossColor);
    mBgColor = a.getColor(R.styleable.RoundChoiceView_backgroundColor, mBgColor);
    mTextSize = a.getDimension(R.styleable.RoundChoiceView_textSize, mTextSize);
    int crossType = a.getInt(R.styleable.RoundChoiceView_crossType, TYPE_CROSS_CROSS);
    if (crossType == TYPE_CROSS_NUMBER) {
        mCrossType = TYPE_CROSS_NUMBER;
    } else {
        mCrossType = TYPE_CROSS_CROSS;
    }
    mBorderWidth = a.getDimension(R.styleable.RoundChoiceView_rippleBorderWidth, dp2px(2));
    mDuration = a.getInt(R.styleable.RoundChoiceView_rippleduration, mDuration);
    mChecked = a.getBoolean(R.styleable.RoundChoiceView_checked, mChecked);
    mNumber = a.getInt(R.styleable.RoundChoiceView_number, mNumber);
    a.recycle();
    mHookDuration = (int) (mDuration * 0.3);
    mCircleDuration = mDuration - mHookDuration;
    mUncheckPaint = new Paint();
    mUncheckPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
    mUncheckPaint.setStrokeWidth(mBorderWidth);
    mUncheckPaint.setColor(mUnCheckColor);
    mUncheckPaint.setStyle(Paint.Style.STROKE);
    mCheckPaint = new Paint();
    mCheckPaint.setFlags(Paint.ANTI_ALIAS_FLAG);
    mCheckPaint.setColor(mCheckColor);
    mCheckPaint.setStyle(Paint.Style.STROKE);
    isHookShow = mChecked;
    mFraction = mChecked ? 1.0f : 0.0f;
}
 
Example 17
Project: FanChat   File: EaseImageView.java   View Source Code Vote up 5 votes
private void init(Context context, AttributeSet attrs) {
    //init the value
    borderWidth = 0;
    borderColor = 0xddffffff;
    pressAlpha = 0x42;
    pressColor = 0x42000000;
    radius = 16;
    shapeType = 0;

    // get attribute of EaseImageView
    if (attrs != null) {
        TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.EaseImageView);
        borderColor = array.getColor(R.styleable.EaseImageView_ease_border_color, borderColor);
        borderWidth = array.getDimensionPixelOffset(R.styleable.EaseImageView_ease_border_width, borderWidth);
        pressAlpha = array.getInteger(R.styleable.EaseImageView_ease_press_alpha, pressAlpha);
        pressColor = array.getColor(R.styleable.EaseImageView_ease_press_color, pressColor);
        radius = array.getDimensionPixelOffset(R.styleable.EaseImageView_ease_radius, radius);
        shapeType = array.getInteger(R.styleable.EaseImageView_ease_shape_type, shapeType);
        array.recycle();
    }

    // set paint when pressed
    pressPaint = new Paint();
    pressPaint.setAntiAlias(true);
    pressPaint.setStyle(Paint.Style.FILL);
    pressPaint.setColor(pressColor);
    pressPaint.setAlpha(0);
    pressPaint.setFlags(Paint.ANTI_ALIAS_FLAG);

    setClickable(true);
    setDrawingCacheEnabled(true);
    setWillNotDraw(false);
}
 
Example 18
Project: KTalk   File: EaseImageView.java   View Source Code Vote up 5 votes
private void init(Context context, AttributeSet attrs) {
    //init the value
    borderWidth = 0;
    borderColor = 0xddffffff;
    pressAlpha = 0x42;
    pressColor = 0x42000000;
    radius = 16;
    shapeType = 0;

    // get attribute of EaseImageView
    if (attrs != null) {
        TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.EaseImageView);
        borderColor = array.getColor(R.styleable.EaseImageView_ease_border_color, borderColor);
        borderWidth = array.getDimensionPixelOffset(R.styleable.EaseImageView_ease_border_width, borderWidth);
        pressAlpha = array.getInteger(R.styleable.EaseImageView_ease_press_alpha, pressAlpha);
        pressColor = array.getColor(R.styleable.EaseImageView_ease_press_color, pressColor);
        radius = array.getDimensionPixelOffset(R.styleable.EaseImageView_ease_radius, radius);
        shapeType = array.getInteger(R.styleable.EaseImageView_ease_shape_type, shapeType);
        array.recycle();
    }

    // set paint when pressed
    pressPaint = new Paint();
    pressPaint.setAntiAlias(true);
    pressPaint.setStyle(Paint.Style.FILL);
    pressPaint.setColor(pressColor);
    pressPaint.setAlpha(0);
    pressPaint.setFlags(Paint.ANTI_ALIAS_FLAG);

    setClickable(true);
    setDrawingCacheEnabled(true);
    setWillNotDraw(false);
}
 
Example 19
Project: letv   File: VideoShotEditActivity.java   View Source Code Vote up 5 votes
private boolean saveFileAddedVoice(String path, String voice, String savePath) {
    LogInfo.log("fornia", "voice:" + voice);
    if (!new File(path).exists()) {
        return false;
    }
    Options options = new Options();
    options.inJustDecodeBounds = false;
    Bitmap bitmap0 = BitmapFactory.decodeFile(path, options);
    int width = options.outWidth;
    int height = options.outHeight;
    Bitmap bitmapPic = Bitmap.createBitmap(width, height, Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmapPic);
    canvas.drawBitmap(bitmap0, null, new Rect(0, 0, width, height), null);
    Rect targetBgRect = new Rect(0, height - getTextBgHeight(), width, height);
    if (!isOrigPicMode) {
        Paint voiceBgPaint = new Paint();
        voiceBgPaint.setColor(getResources().getColor(2131493164));
        voiceBgPaint.setStyle(Style.FILL);
        voiceBgPaint.setFlags(2);
        canvas.drawRect(targetBgRect, voiceBgPaint);
        voiceBgPaint.setColor(-1);
        voiceBgPaint.setTextSize((float) getTextSize());
        voiceBgPaint.setTextAlign(Align.CENTER);
        FontMetricsInt fontMetrics = voiceBgPaint.getFontMetricsInt();
        String str = voice;
        canvas.drawText(str, (float) targetBgRect.centerX(), (float) ((targetBgRect.top + ((((targetBgRect.bottom - targetBgRect.top) - fontMetrics.bottom) + fontMetrics.top) / 2)) - fontMetrics.top), voiceBgPaint);
    }
    return FileUtils.saveBitmapByUser(this.mContext, bitmapPic);
}
 
Example 20
Project: QiangHongBao   File: ViewUtils.java   View Source Code Vote up 5 votes
/**
 * 子View 框取 父View的背景
 * @param root 一级父View
 * @param child 一级子View
 * @return Bitmap
 */
public Bitmap getBoxTakeBitmap(View root, View child){
    root.buildDrawingCache();
    Bitmap bmp = root.getDrawingCache();

    Bitmap bitmap = Bitmap.createBitmap(child.getWidth(),
            child.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    canvas.translate(-child.getLeft(), -child.getTop());
    canvas.scale(1, 1);
    Paint paint = new Paint();
    paint.setFlags(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(bmp, 0, 0, paint);
    return bitmap;
}