Java Code Examples for android.graphics.Paint#FILTER_BITMAP_FLAG

The following examples show how to use android.graphics.Paint#FILTER_BITMAP_FLAG . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CircleImageView.java    From AndroidDemo with MIT License 6 votes vote down vote up
private void init() {
//        paint = new Paint(Paint.ANTI_ALIAS_FLAG);
//        Xfermode xfermode = new PorterDuffXfermode(PorterDuff.Mode.SRC_IN);
//        paint.setXfermode(xfermode);
//        paint.setStrokeWidth(50);
//        paint.setColor(0x000000);

        paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setAntiAlias(true);
        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(0xFF303F9F);
        paint.setStrokeWidth(50);

        path = new Path();
        paintFlagsDrawFilter = new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
//        setLayerType(View.LAYER_TYPE_HARDWARE, null);

    }
 
Example 2
Source File: BitmapUtils.java    From iBeebo with GNU General Public License v3.0 6 votes vote down vote up
public static Bitmap resizeAndCropCenter(Bitmap bitmap, int size, boolean recycle) {
    int w = bitmap.getWidth();
    int h = bitmap.getHeight();
    if (w == size && h == size)
        return bitmap;

    // scale the image so that the shorter side equals to the target;
    // the longer side will be center-cropped.
    float scale = (float) size / Math.min(w, h);

    Bitmap target = Bitmap.createBitmap(size, size, getConfig(bitmap));
    int width = Math.round(scale * bitmap.getWidth());
    int height = Math.round(scale * bitmap.getHeight());
    Canvas canvas = new Canvas(target);
    canvas.translate((size - width) / 2f, (size - height) / 2f);
    canvas.scale(scale, scale);
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG);
    canvas.drawBitmap(bitmap, 0, 0, paint);
    if (recycle)
        bitmap.recycle();
    return target;
}
 
Example 3
Source File: IconCache.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
public IconCache(Context context, InvariantDeviceProfile inv) {
    mContext = context;
    mPackageManager = context.getPackageManager();
    mUserManager = UserManagerCompat.getInstance(mContext);
    mLauncherApps = LauncherAppsCompat.getInstance(mContext);
    mIconDpi = inv.fillResIconDpi;
    mIconDb = new IconDB(context, inv.iconBitmapSize);
    mLowResCanvas = new Canvas();
    mLowResPaint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG);

    mIconProvider = IconThemer.loadByName(context.getString(R.string.icon_provider_class), context);

    mWorkerHandler = new Handler(LauncherModel.getWorkerLooper());

    mActivityBgColor = ThemeUtils.getColorPrimary(context, R.style.BaseLauncherTheme);
    mPackageBgColor = ThemeUtils.getColorPrimary(context, R.style.WidgetContainerTheme);

    mLowResOptions = new BitmapFactory.Options();
    // Always prefer RGB_565 config for low res. If the bitmap has transparency, it will
    // automatically be loaded as ALPHA_8888.
    mLowResOptions.inPreferredConfig = Bitmap.Config.RGB_565;
}
 
Example 4
Source File: BookmarkUtils.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Draw document icon to canvas.
 * @param context     Context used to get bitmap resources.
 * @param canvas      Canvas that holds the document icon.
 * @param iconDensity Density information to get bitmap resources.
 * @param color       Color for the document icon's folding and the bottom strip.
 */
private static void drawWidgetBackgroundToCanvas(
        Context context, Canvas canvas, int iconDensity, int color) {
    Rect iconBounds = new Rect(0, 0, canvas.getWidth(), canvas.getHeight());
    Bitmap bookmark_widget_bg =
            getBitmapFromResourceId(context, R.mipmap.bookmark_widget_bg, iconDensity);
    Bitmap bookmark_widget_bg_highlights = getBitmapFromResourceId(context,
            R.mipmap.bookmark_widget_bg_highlights, iconDensity);
    if (bookmark_widget_bg == null || bookmark_widget_bg_highlights == null) {
        Log.w(TAG, "Can't load R.mipmap.bookmark_widget_bg or " +
                "R.mipmap.bookmark_widget_bg_highlights.");
        return;
    }
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(bookmark_widget_bg, null, iconBounds, paint);

    // The following color filter will convert bookmark_widget_bg_highlights' white color to
    // the 'color' variable when it is painted to 'canvas'.
    paint.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN));
    canvas.drawBitmap(bookmark_widget_bg_highlights, null, iconBounds, paint);
}
 
Example 5
Source File: CircleTransform.java    From ZhihuDaily with Apache License 2.0 6 votes vote down vote up
private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {
    if (source == null) return null;

    int size = Math.min(source.getWidth(), source.getHeight());
    int x = (source.getWidth() - size) / 2;
    int y = (source.getHeight() - size) / 2;

    // TODO this could be acquired from the pool too
    Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);

    Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);
    if (result == null) {
        result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);
    }

    Canvas canvas = new Canvas(result);
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG | Paint
            .ANTI_ALIAS_FLAG);
    paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader
            .TileMode.CLAMP));
    float r = size / 2f;
    canvas.drawCircle(r, r, r, paint);
    return result;
}
 
Example 6
Source File: BitmapUtils.java    From iBeebo with GNU General Public License v3.0 6 votes vote down vote up
public static Bitmap resizeAndCropCenter(Bitmap bitmap, int size, boolean recycle) {
    int w = bitmap.getWidth();
    int h = bitmap.getHeight();
    if (w == size && h == size)
        return bitmap;

    // scale the image so that the shorter side equals to the target;
    // the longer side will be center-cropped.
    float scale = (float) size / Math.min(w, h);

    Bitmap target = Bitmap.createBitmap(size, size, getConfig(bitmap));
    int width = Math.round(scale * bitmap.getWidth());
    int height = Math.round(scale * bitmap.getHeight());
    Canvas canvas = new Canvas(target);
    canvas.translate((size - width) / 2f, (size - height) / 2f);
    canvas.scale(scale, scale);
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG);
    canvas.drawBitmap(bitmap, 0, 0, paint);
    if (recycle)
        bitmap.recycle();
    return target;
}
 
Example 7
Source File: RotateImageProcessor.java    From sketch with Apache License 2.0 6 votes vote down vote up
public static Bitmap rotate(@NonNull Bitmap bitmap, int degrees, @NonNull BitmapPool bitmapPool) {
    Matrix matrix = new Matrix();
    matrix.setRotate(degrees);

    // 根据旋转角度计算新的图片的尺寸
    RectF newRect = new RectF(0, 0, bitmap.getWidth(), bitmap.getHeight());
    matrix.mapRect(newRect);
    int newWidth = (int) newRect.width();
    int newHeight = (int) newRect.height();

    // 角度不能整除90°时新图片会是斜的,因此要支持透明度,这样倾斜导致露出的部分就不会是黑的
    Bitmap.Config config = bitmap.getConfig() != null ? bitmap.getConfig() : Bitmap.Config.ARGB_8888;
    if (degrees % 90 != 0 && config != Bitmap.Config.ARGB_8888) {
        config = Bitmap.Config.ARGB_8888;
    }

    Bitmap result = bitmapPool.getOrMake(newWidth, newHeight, config);

    matrix.postTranslate(-newRect.left, -newRect.top);

    final Canvas canvas = new Canvas(result);
    final Paint paint = new Paint(Paint.DITHER_FLAG | Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(bitmap, matrix, paint);

    return result;
}
 
Example 8
Source File: SunLineView.java    From BitkyShop with MIT License 6 votes vote down vote up
private void init() {
    Log.i(Tag, "init");

    mLineWidth = changeDp(1);
    mLineHeight = changeDp(3);
    mFixLineHeight = changeDp(6);
    mSunRadius = changeDp(12);
    mLineColor = Color.RED;
    mLineLevel = 30;

    //线的配置
    mLinePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mLinePaint.setColor(mLineColor);
    mLinePaint.setStyle(Paint.Style.FILL_AND_STROKE);
    // 设置画笔宽度
    mLinePaint.setStrokeWidth(mLineWidth);
    mDrawFilter = new PaintFlagsDrawFilter(0, Paint.ANTI_ALIAS_FLAG
            | Paint.FILTER_BITMAP_FLAG);
    debugRect = new Rect();
    mouthRect = new RectF();
}
 
Example 9
Source File: DoodleView.java    From Nimingban with Apache License 2.0 6 votes vote down vote up
private void init(Context context) {
    mBitmapPaint = new Paint(Paint.DITHER_FLAG | Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);

    mBgColor = ResourcesUtils.getAttrColor(context, R.attr.colorPure);

    mColor = ResourcesUtils.getAttrColor(context, R.attr.colorPureInverse);
    mWidth = LayoutUtils.dp2pix(context, 4);

    mPath = new Path();

    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setDither(true);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeJoin(Paint.Join.ROUND);
    mPaint.setStrokeCap(Paint.Cap.ROUND);

    mRecycler = new Recycler();
}
 
Example 10
Source File: BitmapUtils.java    From medialibrary with Apache License 2.0 5 votes vote down vote up
public static Bitmap resizeBitmapByScale(
        Bitmap bitmap, float scale, boolean recycle) {
    int width = Math.round(bitmap.getWidth() * scale);
    int height = Math.round(bitmap.getHeight() * scale);
    if (width == bitmap.getWidth()
            && height == bitmap.getHeight()) return bitmap;
    Bitmap target = Bitmap.createBitmap(width, height, getConfig(bitmap));
    Canvas canvas = new Canvas(target);
    canvas.scale(scale, scale);
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG);
    canvas.drawBitmap(bitmap, 0, 0, paint);
    if (recycle) bitmap.recycle();
    return target;
}
 
Example 11
Source File: ShortcutHelper.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * Generates a generic icon to be used in the launcher. This is just a rounded rectangle with
 * a letter in the middle taken from the website's domain name.
 *
 * @param url URL of the shortcut.
 * @param red Red component of the dominant icon color.
 * @param green Green component of the dominant icon color.
 * @param blue Blue component of the dominant icon color.
 * @return Bitmap Either the touch-icon or the newly created favicon.
 */
@CalledByNative
public static Bitmap generateHomeScreenIcon(String url, int red, int green, int blue) {
    Context context = ContextUtils.getApplicationContext();
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    final int outerSize = am.getLauncherLargeIconSize();
    final int iconDensity = am.getLauncherLargeIconDensity();

    Bitmap bitmap = null;
    try {
        bitmap = Bitmap.createBitmap(outerSize, outerSize, Bitmap.Config.ARGB_8888);
    } catch (OutOfMemoryError e) {
        Log.w(TAG, "OutOfMemoryError while trying to draw bitmap on canvas.");
        return null;
    }

    Canvas canvas = new Canvas(bitmap);

    // Draw the drop shadow.
    int padding = (int) (GENERATED_ICON_PADDING_RATIO * outerSize);
    Rect outerBounds = new Rect(0, 0, outerSize, outerSize);
    Bitmap iconShadow =
            getBitmapFromResourceId(context, R.mipmap.shortcut_icon_shadow, iconDensity);
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(iconShadow, null, outerBounds, paint);

    // Draw the rounded rectangle and letter.
    int innerSize = outerSize - 2 * padding;
    int cornerRadius = Math.round(ICON_CORNER_RADIUS_RATIO * outerSize);
    int fontSize = Math.round(GENERATED_ICON_FONT_SIZE_RATIO * outerSize);
    int color = Color.rgb(red, green, blue);
    RoundedIconGenerator generator = new RoundedIconGenerator(
            innerSize, innerSize, cornerRadius, color, fontSize);
    Bitmap icon = generator.generateIconForUrl(url);
    if (icon == null) return null; // Bookmark URL does not have a domain.
    canvas.drawBitmap(icon, padding, padding, null);

    return bitmap;
}
 
Example 12
Source File: ImageDrawable.java    From Nimingban with Apache License 2.0 5 votes vote down vote up
public ImageDrawable(@NonNull ImageWrapper imageWrapper) {
    mImageWrapper = imageWrapper;
    mPaint = new Paint(Paint.FILTER_BITMAP_FLAG);
    mTileList = createTileArray();

    // Render first frame
    render();

    // Add callback
    imageWrapper.addCallback(this);
}
 
Example 13
Source File: PorterDuffXfermodePostProcessor.java    From react-native-image-filter-kit with MIT License 5 votes vote down vote up
@Override
protected CloseableReference<Bitmap> processComposition(
  Bitmap dstImage,
  Bitmap srcImage,
  PlatformBitmapFactory bitmapFactory
) {
  final CloseableReference<Bitmap> outRef = bitmapFactory.createBitmap(
    canvasExtent(dstImage.getWidth(), srcImage.getWidth(), mWidth),
    canvasExtent(dstImage.getHeight(), srcImage.getHeight(), mHeight)
  );

  try {
    final Canvas canvas = new Canvas(outRef.get());
    final int flags = Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG | Paint.FILTER_BITMAP_FLAG;
    final Paint paint = new Paint(flags);

    if (mSwapImages) {
      drawSrc(canvas, srcImage, paint);

    } else {
      drawDst(canvas, dstImage, paint);
    }

    paint.setXfermode(new PorterDuffXfermode(mMode));

    if (mSwapImages) {
      drawDst(canvas, dstImage, paint);

    } else {
      drawSrc(canvas, srcImage, paint);
    }

    return CloseableReference.cloneOrNull(outRef);
  } finally {
    CloseableReference.closeSafely(outRef);
  }
}
 
Example 14
Source File: BitmapUtils.java    From iBeebo with GNU General Public License v3.0 5 votes vote down vote up
public static Bitmap resizeBitmapByScale(Bitmap bitmap, float scale, boolean recycle) {
    int width = Math.round(bitmap.getWidth() * scale);
    int height = Math.round(bitmap.getHeight() * scale);
    if (width == bitmap.getWidth() && height == bitmap.getHeight())
        return bitmap;
    Bitmap target = Bitmap.createBitmap(width, height, getConfig(bitmap));
    Canvas canvas = new Canvas(target);
    canvas.scale(scale, scale);
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG);
    canvas.drawBitmap(bitmap, 0, 0, paint);
    if (recycle)
        bitmap.recycle();
    return target;
}
 
Example 15
Source File: RainbowGraphics2D.java    From rainbow with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void initPaints() {
    fillPaint = new Paint();
    fillPaint.setStyle(Style.FILL);
    strokePaint = new Paint();
    strokePaint.setStrokeCap(Paint.Cap.ROUND);
    strokePaint.setStyle(Style.STROKE);
    tintPaint = new Paint(Paint.FILTER_BITMAP_FLAG);
}
 
Example 16
Source File: ClickShadowView.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
public ClickShadowView(Context context) {
    super(context);
    mPaint = new Paint(Paint.FILTER_BITMAP_FLAG);
    mPaint.setColor(Color.BLACK);

    mShadowPadding = getResources().getDimension(R.dimen.blur_size_click_shadow);
    mShadowOffset = getResources().getDimension(R.dimen.click_shadow_high_shift);
}
 
Example 17
Source File: ShortcutHelper.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Generates a generic icon to be used in the launcher. This is just a rounded rectangle with
 * a letter in the middle taken from the website's domain name.
 *
 * @param url   URL of the shortcut.
 * @param red   Red component of the dominant icon color.
 * @param green Green component of the dominant icon color.
 * @param blue  Blue component of the dominant icon color.
 * @return Bitmap Either the touch-icon or the newly created favicon.
 */
@CalledByNative
public static Bitmap generateHomeScreenIcon(String url, int red, int green, int blue) {
    Context context = ContextUtils.getApplicationContext();
    ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    final int outerSize = am.getLauncherLargeIconSize();
    final int iconDensity = am.getLauncherLargeIconDensity();

    Bitmap bitmap = null;
    try {
        bitmap = Bitmap.createBitmap(outerSize, outerSize, Bitmap.Config.ARGB_8888);
    } catch (OutOfMemoryError e) {
        Log.w(TAG, "OutOfMemoryError while trying to draw bitmap on canvas.");
        return null;
    }

    Canvas canvas = new Canvas(bitmap);

    // Draw the drop shadow.
    int padding = (int) (GENERATED_ICON_PADDING_RATIO * outerSize);
    Rect outerBounds = new Rect(0, 0, outerSize, outerSize);
    Bitmap iconShadow =
            getBitmapFromResourceId(context, R.mipmap.shortcut_icon_shadow, iconDensity);
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(iconShadow, null, outerBounds, paint);

    // Draw the rounded rectangle and letter.
    int innerSize = outerSize - 2 * padding;
    int cornerRadius = Math.round(ICON_CORNER_RADIUS_RATIO * outerSize);
    int fontSize = Math.round(GENERATED_ICON_FONT_SIZE_RATIO * outerSize);
    int color = Color.rgb(red, green, blue);
    RoundedIconGenerator generator = new RoundedIconGenerator(
            innerSize, innerSize, cornerRadius, color, fontSize);
    Bitmap icon = generator.generateIconForUrl(url);
    if (icon == null) return null; // Bookmark URL does not have a domain.
    canvas.drawBitmap(icon, padding, padding, null);

    return bitmap;
}
 
Example 18
Source File: ColorPickerView.java    From libcommon with Apache License 2.0 5 votes vote down vote up
public ColorPickerView(final Context context, final AttributeSet attrs, final int defStyleAttr) {
		super(context, attrs, defStyleAttr);
//		if (DEBUG) Log.v(TAG, "ColorPickerView:");
		DENSITY = context.getResources().getDisplayMetrics().density;
		RECTANGLE_TRACKER_OFFSET = RECTANGLE_TRACKER_OFFSET_DP * DENSITY;
		SELECTED_RADIUS = DEFAULT_SELECTED_RADIUS * DENSITY;

		mAlphaShader = new BitmapShader(BitmapHelper.makeCheckBitmap(), TileMode.REPEAT, TileMode.REPEAT);
		mAlphaDrawable = new ShaderDrawable(Paint.FILTER_BITMAP_FLAG | Paint.DITHER_FLAG, 0);
		mAlphaDrawable.setShader(mAlphaShader);

		radius = 0;
		internalSetColor(mColor, false);

		// 色相円用
		setHueColorArray(mAlpha, COLORS);
		mPaint.setShader(new SweepGradient(0, 0, COLORS, null));
		mPaint.setStyle(Paint.Style.FILL);
		mPaint.setStrokeWidth(0);

		// 選択色用
		mSelectionPaint.setColor(mColor);
		mSelectionPaint.setStrokeWidth(5);

		// スライダーのトラッカー表示用
		mTrackerPaint.setColor(TRACKER_COLOR);
		mTrackerPaint.setStyle(Paint.Style.STROKE);
		mTrackerPaint.setStrokeWidth(2f * DENSITY);
		mTrackerPaint.setAntiAlias(true);
	}
 
Example 19
Source File: ClippingImageView.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public ClippingImageView(Context context) {
    super(context);
    paint = new Paint(Paint.FILTER_BITMAP_FLAG);
    paint.setFilterBitmap(true);
    matrix = new Matrix();
    drawRect = new RectF();
    bitmapRect = new RectF();
    roundPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);

    roundRect = new RectF();
    shaderMatrix = new Matrix();
}
 
Example 20
Source File: CoreAnimation.java    From tilt-game-android with MIT License 4 votes vote down vote up
public CoreAnimation() {
	_paint = new Paint(Paint.FILTER_BITMAP_FLAG);
	_frameListeners = new SparseArray<>();
}