Java Code Examples for android.graphics.PixelFormat#OPAQUE

The following examples show how to use android.graphics.PixelFormat#OPAQUE . 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: BitmapUtil.java    From ZhihuDaily with MIT License 6 votes vote down vote up
public static Bitmap drawableToBitmap(Drawable drawable) {
   // 取 drawable 的长宽
   int w = drawable.getIntrinsicWidth();
   int h = drawable.getIntrinsicHeight();

   // 取 drawable 的颜色格式
   Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
           : Bitmap.Config.RGB_565;
   // 建立对应 bitmap
    Bitmap bitmap = Bitmap.createBitmap(w, h, config);
    // 建立对应 bitmap 的画布
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, w, h);
    // 把 drawable 内容画到画布中
    drawable.draw(canvas);
    return bitmap;
}
 
Example 2
Source File: RxImageTool.java    From RxTools-master with Apache License 2.0 6 votes vote down vote up
/**
 * drawable转bitmap
 *
 * @param drawable drawable对象
 * @return bitmap对象
 */
public static Bitmap drawable2Bitmap(Drawable drawable) {
    // 取 drawable 的长宽
    int w = drawable.getIntrinsicWidth();
    int h = drawable.getIntrinsicHeight();

    // 取 drawable 的颜色格式
    Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
            : Bitmap.Config.RGB_565;
    // 建立对应 bitmap
    Bitmap bitmap = Bitmap.createBitmap(w, h, config);
    // 建立对应 bitmap 的画布
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, w, h);
    // 把 drawable 内容画到画布中
    drawable.draw(canvas);
    return bitmap;
}
 
Example 3
Source File: Utils.java    From AndroidBase with Apache License 2.0 6 votes vote down vote up
/**
 * Drawable → Bitmap
 */
public static Bitmap drawable2Bitmap(Drawable drawable) {
    if (drawable == null) {
        return null;
    }
    // 取 drawable 的长宽
    int w = drawable.getIntrinsicWidth();
    int h = drawable.getIntrinsicHeight();
    // 取 drawable 的颜色格式
    Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;
    // 建立对应 bitmap
    Bitmap bitmap = Bitmap.createBitmap(w, h, config);
    // 建立对应 bitmap 的画布
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, w, h);
    // 把 drawable 内容画到画布中
    drawable.draw(canvas);
    return bitmap;
}
 
Example 4
Source File: CacheUtils.java    From MyUtil with Apache License 2.0 6 votes vote down vote up
private static Bitmap drawable2Bitmap(Drawable drawable) {
    if (drawable == null) {
        return null;
    }
    // 取 drawable 的长宽
    int w = drawable.getIntrinsicWidth();
    int h = drawable.getIntrinsicHeight();
    // 取 drawable 的颜色格式
    Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
            : Bitmap.Config.RGB_565;
    // 建立对应 bitmap
    Bitmap bitmap = Bitmap.createBitmap(w, h, config);
    // 建立对应 bitmap 的画布
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, w, h);
    // 把 drawable 内容画到画布中
    drawable.draw(canvas);
    return bitmap;
}
 
Example 5
Source File: ACache.java    From fangzhuishushenqi with Apache License 2.0 6 votes vote down vote up
private static Bitmap drawable2Bitmap(Drawable drawable) {
    if (drawable == null) {
        return null;
    }
    // 取 drawable 的长宽
    int w = drawable.getIntrinsicWidth();
    int h = drawable.getIntrinsicHeight();
    // 取 drawable 的颜色格式
    Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE
            ? Bitmap.Config.ARGB_8888
            : Bitmap.Config.RGB_565;
    // 建立对应 bitmap
    Bitmap bitmap = Bitmap.createBitmap(w, h, config);
    // 建立对应 bitmap 的画布
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, w, h);
    // 把 drawable 内容画到画布中
    drawable.draw(canvas);
    return bitmap;
}
 
Example 6
Source File: SurfaceView.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void setFormat(int format) {
    // for backward compatibility reason, OPAQUE always
    // means 565 for SurfaceView
    if (format == PixelFormat.OPAQUE)
        format = PixelFormat.RGB_565;

    mRequestedFormat = format;
    if (mSurfaceControl != null) {
        updateSurface();
    }
}
 
Example 7
Source File: DrawableUtil.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
public static Bitmap drawableToBitmap(Drawable drawable) {
    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    } else {
        int width = drawable.getIntrinsicWidth();// 取drawable的长宽
        int height = drawable.getIntrinsicHeight();
        Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;// 取drawable的颜色格式
        Bitmap bitmap = Bitmap.createBitmap(width, height, config);// 建立对应bitmap
        Canvas canvas = new Canvas(bitmap);// 建立对应bitmap的画布
        drawable.setBounds(0, 0, width, height);
        drawable.draw(canvas);// 把drawable内容画到画布中
        return bitmap;
    }
}
 
Example 8
Source File: RLImgUtil.java    From Roid-Library with Apache License 2.0 5 votes vote down vote up
/**
 * @param drawable
 * @return
 */
public static Bitmap drawableToBitmap(Drawable drawable) {
    int w = drawable.getIntrinsicWidth();
    int h = drawable.getIntrinsicHeight();
    Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
            : Bitmap.Config.RGB_565;
    Bitmap bitmap = Bitmap.createBitmap(w, h, config);
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, w, h);
    drawable.draw(canvas);
    return bitmap;
}
 
Example 9
Source File: DebugDrawerLayout.java    From debugdrawer with Apache License 2.0 5 votes vote down vote up
private static boolean hasOpaqueBackground(View v) {
	final Drawable bg = v.getBackground();
	if (bg != null) {
		return bg.getOpacity() == PixelFormat.OPAQUE;
	}
	return false;
}
 
Example 10
Source File: ImageView.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isOpaque() {
    return super.isOpaque() || mDrawable != null && mXfermode == null
            && mDrawable.getOpacity() == PixelFormat.OPAQUE
            && mAlpha * mViewAlphaScale >> 8 == 255
            && isFilledByImage();
}
 
Example 11
Source File: RefreshNowProgressIndicator.java    From RefreshNow with Apache License 2.0 5 votes vote down vote up
@Override
public int getOpacity() {
	final int alpha = paint.getAlpha();
	if (alpha == 0) return PixelFormat.TRANSPARENT;
	if (alpha == 0xff) return PixelFormat.OPAQUE;
	return PixelFormat.TRANSLUCENT;
}
 
Example 12
Source File: ZrcListView.java    From ZrcListView with MIT License 5 votes vote down vote up
public void setDivider(Drawable divider) {
    if (divider != null) {
        mDividerHeight = divider.getIntrinsicHeight();
    } else {
        mDividerHeight = 0;
    }
    mDivider = divider;
    mDividerIsOpaque = divider == null || divider.getOpacity() == PixelFormat.OPAQUE;
    requestLayout();
    invalidate();
}
 
Example 13
Source File: MountainSceneDrawable.java    From FlyRefresh with MIT License 4 votes vote down vote up
@Override
public int getOpacity() {
    return PixelFormat.OPAQUE;
}
 
Example 14
Source File: SlidingUpPanelLayout.java    From BlackLight with GNU General Public License v3.0 4 votes vote down vote up
private static boolean hasOpaqueBackground(View v) {
    final Drawable bg = v.getBackground();
    return bg != null && bg.getOpacity() == PixelFormat.OPAQUE;
}
 
Example 15
Source File: SlidingUpPanelLayout.java    From toktok-android with GNU General Public License v3.0 4 votes vote down vote up
private static boolean hasOpaqueBackground(@NonNull View v) {
    final Drawable bg = v.getBackground();
    return bg != null && bg.getOpacity() == PixelFormat.OPAQUE;
}
 
Example 16
Source File: DefaultHeaderTransformer.java    From Bitocle with Apache License 2.0 4 votes vote down vote up
private void setupViewsFromStyles(Activity activity, View headerView) {
    final TypedArray styleAttrs = obtainStyledAttrsFromThemeAttr(activity,
            R.attr.ptrHeaderStyle, R.styleable.PullToRefreshHeader);

    // Retrieve the Action Bar size from the app theme or the Action Bar's style
    if (mContentLayout != null) {
        final int height = styleAttrs.getDimensionPixelSize(
                R.styleable.PullToRefreshHeader_ptrHeaderHeight, getActionBarSize(activity));
        mContentLayout.getLayoutParams().height = height;
        mContentLayout.requestLayout();
    }

    // Retrieve the Action Bar background from the app theme or the Action Bar's style (see #93)
    Drawable bg = styleAttrs.hasValue(R.styleable.PullToRefreshHeader_ptrHeaderBackground)
            ? styleAttrs.getDrawable(R.styleable.PullToRefreshHeader_ptrHeaderBackground)
            : getActionBarBackground(activity);
    if (bg != null) {
        mHeaderTextView.setBackgroundDrawable(bg);

        // If we have an opaque background we can remove the background from the content layout
        if (mContentLayout != null && bg.getOpacity() == PixelFormat.OPAQUE) {
            mContentLayout.setBackgroundResource(0);
        }
    }

    // Retrieve the Action Bar Title Style from the app theme or the Action Bar's style
    Context abContext = headerView.getContext();
    final int titleTextStyle = styleAttrs
            .getResourceId(R.styleable.PullToRefreshHeader_ptrHeaderTitleTextAppearance,
                    getActionBarTitleStyle(abContext));
    if (titleTextStyle != 0) {
        mHeaderTextView.setTextAppearance(abContext, titleTextStyle);
    }

    // Retrieve the Progress Bar Color the style
    if (styleAttrs.hasValue(R.styleable.PullToRefreshHeader_ptrProgressBarColor)) {
        mProgressDrawableColor = styleAttrs.getColor(
                R.styleable.PullToRefreshHeader_ptrProgressBarColor, mProgressDrawableColor);
    }

    mProgressBarStyle = styleAttrs.getInt(
            R.styleable.PullToRefreshHeader_ptrProgressBarStyle, PROGRESS_BAR_STYLE_OUTSIDE);

    if (styleAttrs.hasValue(R.styleable.PullToRefreshHeader_ptrProgressBarHeight)) {
        mProgressBarHeight = styleAttrs.getDimensionPixelSize(
                R.styleable.PullToRefreshHeader_ptrProgressBarHeight, mProgressBarHeight);
    }

    // Retrieve the text strings from the style (if they're set)
    if (styleAttrs.hasValue(R.styleable.PullToRefreshHeader_ptrPullText)) {
        mPullRefreshLabel = styleAttrs.getString(R.styleable.PullToRefreshHeader_ptrPullText);
    }
    if (styleAttrs.hasValue(R.styleable.PullToRefreshHeader_ptrRefreshingText)) {
        mRefreshingLabel = styleAttrs
                .getString(R.styleable.PullToRefreshHeader_ptrRefreshingText);
    }
    if (styleAttrs.hasValue(R.styleable.PullToRefreshHeader_ptrReleaseText)) {
        mReleaseLabel = styleAttrs.getString(R.styleable.PullToRefreshHeader_ptrReleaseText);
    }

    //SmoothProgressBar Style
    if (styleAttrs.hasValue(R.styleable.PullToRefreshHeader_ptrSmoothProgressBarStyle)) {
        int spbStyleRes = styleAttrs.getResourceId(R.styleable.PullToRefreshHeader_ptrSmoothProgressBarStyle, 0);
        if (spbStyleRes != 0)
            mHeaderProgressBar.applyStyle(spbStyleRes);

    }

    styleAttrs.recycle();
}
 
Example 17
Source File: DefaultHeaderTransformer.java    From ALLGO with Apache License 2.0 4 votes vote down vote up
private void setupViewsFromStyles(Activity activity, View headerView) {
    final TypedArray styleAttrs = obtainStyledAttrsFromThemeAttr(activity,
            R.attr.ptrHeaderStyle, R.styleable.PullToRefreshHeader);

    // Retrieve the Action Bar size from the app theme or the Action Bar's style
    if (mContentLayout != null) {
        final int height = styleAttrs
                .getDimensionPixelSize(R.styleable.PullToRefreshHeader_ptrHeaderHeight,
                        getActionBarSize(activity));
        mContentLayout.getLayoutParams().height = height;
        mContentLayout.requestLayout();
    }

    // Retrieve the Action Bar background from the app theme or the Action Bar's style (see #93)
    Drawable bg = styleAttrs.hasValue(R.styleable.PullToRefreshHeader_ptrHeaderBackground)
            ? styleAttrs.getDrawable(R.styleable.PullToRefreshHeader_ptrHeaderBackground)
            : getActionBarBackground(activity);
    if (bg != null) {
        mHeaderTextView.setBackgroundDrawable(bg);

        // If we have an opaque background we can remove the background from the content layout
        if (mContentLayout != null && bg.getOpacity() == PixelFormat.OPAQUE) {
            mContentLayout.setBackgroundResource(0);
        }
    }

    // Retrieve the Action Bar Title Style from the app theme or the Action Bar's style
    Context abContext = headerView.getContext();
    final int titleTextStyle = styleAttrs
            .getResourceId(R.styleable.PullToRefreshHeader_ptrHeaderTitleTextAppearance,
                    getActionBarTitleStyle(abContext));
    if (titleTextStyle != 0) {
        mHeaderTextView.setTextAppearance(abContext, titleTextStyle);
    }

    // Retrieve the Progress Bar Color the style
    if (styleAttrs.hasValue(R.styleable.PullToRefreshHeader_ptrProgressBarColor)) {
        mUseCustomProgressColor = true;
        mProgressDrawableColor = styleAttrs
                .getColor(R.styleable.PullToRefreshHeader_ptrProgressBarColor, 0);
    }

    // Retrieve the text strings from the style (if they're set)
    if (styleAttrs.hasValue(R.styleable.PullToRefreshHeader_ptrPullText)) {
        mPullRefreshLabel = styleAttrs.getString(R.styleable.PullToRefreshHeader_ptrPullText);
    }
    if (styleAttrs.hasValue(R.styleable.PullToRefreshHeader_ptrRefreshingText)) {
        mRefreshingLabel = styleAttrs
                .getString(R.styleable.PullToRefreshHeader_ptrRefreshingText);
    }
    if (styleAttrs.hasValue(R.styleable.PullToRefreshHeader_ptrReleaseText)) {
        mReleaseLabel = styleAttrs.getString(R.styleable.PullToRefreshHeader_ptrReleaseText);
    }

    styleAttrs.recycle();
}
 
Example 18
Source File: SlidingUpPanelLayout.java    From AndroidSlidingUpPanel with Apache License 2.0 4 votes vote down vote up
private static boolean hasOpaqueBackground(View v) {
    final Drawable bg = v.getBackground();
    return bg != null && bg.getOpacity() == PixelFormat.OPAQUE;
}
 
Example 19
Source File: BitmapUtil.java    From FileManager with Apache License 2.0 4 votes vote down vote up
public static Bitmap drawableToBitmap(Drawable drawable) {

        int w = drawable.getIntrinsicWidth();
        int h = drawable.getIntrinsicHeight();

        Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;

        Bitmap bitmap = Bitmap.createBitmap(w, h, config);

        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, w, h);

        drawable.draw(canvas);
        return bitmap;

    }
 
Example 20
Source File: ReplaceableBitmapDrawable.java    From recent-images with MIT License 4 votes vote down vote up
@Override
public int getOpacity() {
	return PixelFormat.OPAQUE;
}