java类android.graphics.LightingColorFilter的实例源码

Timber4.java 文件源码 项目:Muzesto 阅读 26 收藏 0 点赞 0 评论 0
private Bitmap changeBitmapColor(Bitmap sourceBitmap, int color) {

        Bitmap resultBitmap = Bitmap.createBitmap(sourceBitmap, 0, 0,
                sourceBitmap.getWidth() - 1, sourceBitmap.getHeight() - 1);
        Paint p = new Paint();
        ColorFilter filter = new LightingColorFilter(color, 1);
        p.setColorFilter(filter);
        Canvas canvas = new Canvas(resultBitmap);
        canvas.drawBitmap(resultBitmap, 0, 0, p);
        return resultBitmap;
    }
ImageHelper.java 文件源码 项目:FrostyBackgroundTestApp 阅读 25 收藏 0 点赞 0 评论 0
public static Bitmap getRoundedCornerAndLightenBitmap(Bitmap bitmap, int cornerRadiusInPixels, boolean captureCircle) {
    Bitmap output = Bitmap.createBitmap(
            bitmap.getWidth(),
            bitmap.getHeight(),
            Bitmap.Config.ARGB_4444);
    Canvas canvas = new Canvas(output);

    final int color = 0xffffffff;
    final Paint paint = new Paint();
    final Rect rect = new Rect(0,
            0,
            bitmap.getWidth(),
            bitmap.getHeight());
    final RectF rectF = new RectF(rect);
    final float roundPx = cornerRadiusInPixels;

    paint.setAntiAlias(true);
    canvas.drawARGB(0, 0, 0, 0);
    paint.setColor(color);
    if (captureCircle) {
        canvas.drawCircle(rectF.centerX(),
                rectF.centerY(),
                bitmap.getWidth() / 2,
                paint);
    } else {
        canvas.drawRoundRect(rectF,
                roundPx,
                roundPx,
                paint);
    }

    paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    ColorFilter filter = new LightingColorFilter(0xFFFFFFFF, 0x00222222); // lighten
    //ColorFilter filter = new LightingColorFilter(0xFF7F7F7F, 0x00000000);    // darken
    paint.setColorFilter(filter);
    canvas.drawBitmap(bitmap, rect, rect, paint);

    return output;
}
MarkerWithText.java 文件源码 项目:Tower-develop 阅读 21 收藏 0 点赞 0 评论 0
/**
 * Copied from:
 * http://stackoverflow.com/questions/18335642/how-to-draw-text-
 * in-default-marker-of-google-map-v2?lq=1
 */
private static Bitmap drawTextToBitmap(Context gContext, int gResId, int color, String gText) {
    Resources resources = gContext.getResources();
    float scale = resources.getDisplayMetrics().density;
    Bitmap bitmap = BitmapFactory.decodeResource(resources, gResId);

    android.graphics.Bitmap.Config bitmapConfig = bitmap.getConfig();
    if (bitmapConfig == null) {
        bitmapConfig = android.graphics.Bitmap.Config.ARGB_8888;
    }
    bitmap = bitmap.copy(bitmapConfig, true);

    // copy bitmap to canvas, replace white with colour
    Paint paint = new Paint();
    paint.setColorFilter(new LightingColorFilter(0x000000, color));
    Canvas canvas = new Canvas(bitmap);
    canvas.drawBitmap(bitmap, 0, 0, paint);

    paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(Color.BLACK);
    paint.setTextSize((int) (15 * scale));
    paint.setShadowLayer(1f, 0f, 1f, Color.WHITE);

    Rect bounds = new Rect();
    paint.getTextBounds(gText, 0, gText.length(), bounds);
    int x = (bitmap.getWidth() - bounds.width()) / 2;
    int y = (bitmap.getHeight() + bounds.height()) * 5 / 12; // At 5/12 from
                                                                // the top
                                                                // so it
                                                                // stays on
                                                                // the
                                                                // center

    canvas.drawText(gText, x, y, paint);

    return bitmap;
}
RecyclerViewFragment.java 文件源码 项目:deathly_adiutor_free 阅读 23 收藏 0 点赞 0 评论 0
public void setProgressBar(ProgressBar progressBar) {
    progressBar.getIndeterminateDrawable().setColorFilter(new LightingColorFilter(0xFF000000,
            getResources().getColor(android.R.color.white)));
    ActionBar actionBar;
    if ((actionBar = getActionBar()) != null) {
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM);
        actionBar.setCustomView(progressBar, new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
                ActionBar.LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL | Gravity.END));
    }
}
StarRatingView.java 文件源码 项目:AndroidStudyDemo 阅读 24 收藏 0 点赞 0 评论 0
private void init() {
    starBitmap = BitmapFactory.decodeResource(getContext().getResources(), R.mipmap.star);

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

    grayPaint = new Paint();
    grayPaint.setColorFilter(new LightingColorFilter(0xff111122, 0xffcccccc));
    grayPaint.setFilterBitmap(true);

    setModel(new StarRatingModel());
}
ImageLightingFilterView.java 文件源码 项目:AyoSunny 阅读 21 收藏 0 点赞 0 评论 0
public ImageLightingFilterView(Context context, AttributeSet attrs) {
    super(context, attrs);
    mContext = context;

    // 初始化画笔
    initPaint();

    // 初始化资源
    initRes(context);

    setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            /*
             * 判断控件是否被点击过
             */
            if (isClick) {
                // 如果已经被点击了则点击时设置颜色过滤为空还原本色
                mPaint.setColorFilter(null);
                isClick = false;
            } else {
                // 如果未被点击则点击时设置颜色过滤后为黄色
                mPaint.setColorFilter(new LightingColorFilter(0xFFFFFFFF, 0X00FFFF00));
                isClick = true;
            }

            // 记得重绘
            invalidate();
        }
    });
}
RecyclerViewFragment.java 文件源码 项目:KA27 阅读 24 收藏 0 点赞 0 评论 0
public void setProgressBar(ProgressBar progressBar) {
    progressBar.getIndeterminateDrawable().setColorFilter(new LightingColorFilter(0xFF000000,
        ContextCompat.getColor(getActivity(), android.R.color.white)));
    ActionBar actionBar;
    if ((actionBar = getActionBar()) != null) {
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM);
        actionBar.setCustomView(progressBar, new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
            ActionBar.LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL | Gravity.END));
    }
}
TintedBitmapDrawable.java 文件源码 项目:droidddle 阅读 25 收藏 0 点赞 0 评论 0
@Override
public void draw(final Canvas canvas) {
    final Paint paint = getPaint();
    if (paint.getColorFilter() == null) {
        paint.setColorFilter(new LightingColorFilter(tint, 0));
        paint.setAlpha(alpha);
    }
    super.draw(canvas);
}
WifiQrView.java 文件源码 项目:AppHub 阅读 23 收藏 0 点赞 0 评论 0
@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    setUIFromWifi();

    ImageView qrImage = (ImageView) findViewById(R.id.wifi_qr_code);

    // Replace all blacks with the background blue.
    qrImage.setColorFilter(new LightingColorFilter(0xffffffff, getResources().getColor(R.color.swap_blue)));

    Button openQr = (Button) findViewById(R.id.btn_qr_scanner);
    openQr.setOnClickListener(new Button.OnClickListener() {
        @Override
        public void onClick(View v) {
            getActivity().initiateQrScan();
        }
    });

    // TODO: Unregister this receiver properly.
    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(
            new BroadcastReceiver() {
                @Override
                public void onReceive(Context context, Intent intent) {
                    setUIFromWifi();
                }
            },
            new IntentFilter(WifiStateChangeService.BROADCAST)
    );
}
RecyclerViewFragment.java 文件源码 项目:kernel_adiutor 阅读 40 收藏 0 点赞 0 评论 0
public void setProgressBar(ProgressBar progressBar) {
    progressBar.getIndeterminateDrawable().setColorFilter(new LightingColorFilter(0xFF000000,
            getResources().getColor(android.R.color.white)));
    ActionBar actionBar;
    if ((actionBar = getActionBar()) != null) {
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM);
        actionBar.setCustomView(progressBar, new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
                ActionBar.LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL | Gravity.END));
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号