Java 类android.graphics.PixelFormat 实例源码

项目:Crimson    文件:ScreenFilterService.java   
@Override
public void onCreate() {

    myView = new MyFilterView(this);

    mParams = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                    | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                    | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
            PixelFormat.TRANSLUCENT);

    mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
    mWindowManager.addView(myView, mParams);

    super.onCreate();
}
项目:ucar-weex-core    文件:BorderDrawableTest.java   
@Test
public void testGetOpacity() throws Exception {
  BorderDrawable opaque = new BorderDrawable();
  opaque.setColor(Color.GREEN);
  assertThat(opaque.getOpacity(), is(PixelFormat.OPAQUE));

  BorderDrawable transparent = new BorderDrawable();
  transparent.setColor(WXResourceUtils.getColor("#00ff0000"));
  assertThat(transparent.getOpacity(), is(PixelFormat.TRANSPARENT));

  BorderDrawable half = new BorderDrawable();
  half.setColor(WXResourceUtils.getColor("#aaff0000"));
  assertThat(half.getOpacity(), is(PixelFormat.TRANSLUCENT));

  BorderDrawable changeAlpha = new BorderDrawable();
  changeAlpha.setColor(Color.RED);
  changeAlpha.setAlpha(15);
  assertThat(changeAlpha.getOpacity(), is(PixelFormat.TRANSLUCENT));
}
项目:Keyguard    文件:MaskWindowUtils.java   
@Nullable
private View showKeyguardView (boolean showSettings) {
    if (Build.VERSION.SDK_INT >= 23) {
        if (!Settings.canDrawOverlays(mContext)) {
            if (!showSettings)
                return null;
            Intent i = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
            mContext.startActivity(i);
            return null;
        }
    }
    View keyguardView = LayoutInflater.from(mContext).inflate(R.layout.layout_keyguard, null);
    WindowManager.LayoutParams wmParams = new WindowManager.LayoutParams();
    wmParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
    wmParams.format = PixelFormat.TRANSPARENT;
    wmParams.flags=WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
            | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
            | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR;
    wmParams.width=WindowManager.LayoutParams.MATCH_PARENT;
    wmParams.height= WindowManager.LayoutParams.MATCH_PARENT;
    mManager.addView(keyguardView, wmParams);
    mContext.startActivity(new Intent(mContext, KeyguardLiveActivity.class));
    return keyguardView;
}
项目:rongyunDemo    文件:BitmapUtils.java   
public static Bitmap drawableToBitmap(Drawable drawable) {

        Bitmap bitmap = Bitmap
                        .createBitmap(
                            drawable.getIntrinsicWidth(),
                            drawable.getIntrinsicHeight(),
                            drawable.getOpacity() != PixelFormat.OPAQUE ? Config.ARGB_8888
                            : Config.RGB_565);
        Canvas canvas = new Canvas(bitmap);

        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
                           drawable.getIntrinsicHeight());
        drawable.draw(canvas);

        return bitmap;

    }
项目:GitHub    文件:CameraManager.java   
/**
 * A factory method to build the appropriate LuminanceSource object based on the format
 * of the preview buffers, as described by Camera.Parameters.
 *
 * @param data A preview frame.
 * @param width The width of the image.
 * @param height The height of the image.
 * @return A PlanarYUVLuminanceSource instance.
 */
public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) {
    Rect rect = getFramingRectInPreview();
    int previewFormat = configManager.getPreviewFormat();
    String previewFormatString = configManager.getPreviewFormatString();
    switch (previewFormat) {
    // This is the standard Android format which all devices are REQUIRED to support.
    // In theory, it's the only one we should ever care about.
    case PixelFormat.YCbCr_420_SP:
        // This format has never been seen in the wild, but is compatible as we only care
        // about the Y channel, so allow it.
    case PixelFormat.YCbCr_422_SP:
        return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top,
                rect.width(), rect.height());
    default:
        // The Samsung Moment incorrectly uses this variant instead of the 'sp' version.
        // Fortunately, it too has all the Y data up front, so we can read it.
        if ("yuv420p".equals(previewFormatString)) {
            return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top,
                    rect.width(), rect.height());
        }
    }
    throw new IllegalArgumentException("Unsupported picture format: " +
            previewFormat + '/' + previewFormatString);
}
项目:AndroidUtilCode-master    文件:CacheUtils.java   
private static Bitmap drawable2Bitmap(Drawable drawable) {
    if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        if (bitmapDrawable.getBitmap() != null) {
            return bitmapDrawable.getBitmap();
        }
    }
    Bitmap bitmap;
    if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
        bitmap = Bitmap.createBitmap(1, 1,
                drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
    } else {
        bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
    }
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
    return bitmap;
}
项目:decoy    文件:SurfaceViewTemplate.java   
public SurfaceViewTemplate(Context context, AttributeSet attrs) {
    super(context, attrs);

    mHolder = getHolder();
    mHolder.addCallback(this);

    // 设置Surface在Window(普通视图架构)之上
    setZOrderOnTop(true);
    // 设置色彩格式,半透明
    mHolder.setFormat(PixelFormat.TRANSLUCENT);

    // 设置可获得焦点
    setFocusable(true);
    setFocusableInTouchMode(true);

    // 设置保持屏幕亮
    this.setKeepScreenOn(true);
}
项目:HeadlineNews    文件:SpanUtils.java   
private Bitmap drawable2Bitmap(final Drawable drawable) {
    if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        if (bitmapDrawable.getBitmap() != null) {
            return bitmapDrawable.getBitmap();
        }
    }
    Bitmap bitmap;
    if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
        bitmap = Bitmap.createBitmap(1, 1,
                drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
    } else {
        bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
    }
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
    return bitmap;
}
项目:CoolApk-Console    文件:ACache.java   
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;
}
项目:BBSSDK-for-Android    文件:ImageUtils.java   
/**
 * drawable转bitmap
 *
 * @param drawable drawable对象
 * @return bitmap
 */
public static Bitmap drawable2Bitmap(final Drawable drawable) {
    if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        if (bitmapDrawable.getBitmap() != null) {
            return bitmapDrawable.getBitmap();
        }
    }
    Bitmap bitmap;
    if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
        bitmap = Bitmap.createBitmap(1, 1,
                drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
    } else {
        bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
    }
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
    return bitmap;
}
项目:meipai-Android    文件:MediaRecorderBase.java   
/** 设置回调 */
protected void setPreviewCallback() {
    Size size = mParameters.getPreviewSize();
    if (size != null) {
        PixelFormat pf = new PixelFormat();
        PixelFormat.getPixelFormatInfo(mParameters.getPreviewFormat(), pf);
        int buffSize = size.width * size.height * pf.bitsPerPixel / 8;
        try {
            camera.addCallbackBuffer(new byte[buffSize]);
            camera.addCallbackBuffer(new byte[buffSize]);
            camera.addCallbackBuffer(new byte[buffSize]);
            camera.setPreviewCallbackWithBuffer(this);
        } catch (OutOfMemoryError e) {
            Log.e("Yixia", "startPreview...setPreviewCallback...", e);
        }
        Log.e("Yixia", "startPreview...setPreviewCallbackWithBuffer...width:" + size.width + " height:" + size.height);
    } else {
        camera.setPreviewCallback(this);
    }
}
项目:AndroidBasicLibs    文件:ACache.java   
private static Bitmap drawable2Bitmap(Drawable drawable) {
    if (drawable == null) {
        return null;
    }

    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;
}
项目:FaceRecognition    文件:CameraInterface.java   
public boolean startCameraPreview(){
    try {
        Camera.Parameters parameters = camera.getParameters();
        parameters.setPictureFormat(PixelFormat.JPEG);
        //parameters.setPictureSize(surfaceView.getWidth(), surfaceView.getHeight());  // 部分定制手机,无法正常识别该方法。
        parameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
        parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);//1连续对焦
        setDispaly(parameters, camera);
        camera.setParameters(parameters);
        camera.startPreview();
        camera.cancelAutoFocus();//只有加上了这一句,才会自动对焦。
    }catch (RuntimeException e){
        Toast.makeText(context, "该手机不支持参数设定", Toast.LENGTH_LONG).show();
    }
    return true;
}
项目:cwac-crossport    文件:TooltipPopup.java   
TooltipPopup(Context context) {
    mContext = context;

    mContentView = LayoutInflater.from(mContext).inflate(R.layout.appcompat_tooltip, null);
    mMessageView = (TextView) mContentView.findViewById(R.id.message);

    mLayoutParams.setTitle(getClass().getSimpleName());
    mLayoutParams.packageName = mContext.getPackageName();
    mLayoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_SUB_PANEL;
    mLayoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
    mLayoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
    mLayoutParams.format = PixelFormat.TRANSLUCENT;
    mLayoutParams.windowAnimations = R.style.Animation_CrossPort_Tooltip;
    mLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
            | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
}
项目:BuildNumberOverlay    文件:OverlayView.java   
public void addToWindowManager() {
    WindowManager.LayoutParams windowLayoutParams = new WindowManager.LayoutParams(
            CANVAS_WIDTH,
            CANVAS_HEIGHT,
            WindowManager.LayoutParams.TYPE_PHONE,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
            PixelFormat.TRANSLUCENT);
    windowLayoutParams.gravity = Gravity.BOTTOM | Gravity.END;

    mLinearLayout = new LinearLayout(mContext);
    mLinearLayout.setBackgroundColor(Color.BLACK);
    mWindowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    mWindowManager.addView(mLinearLayout, windowLayoutParams);

    TextView textView = new TextView(mContext);
    textView.setTextColor(Color.RED);
    textView.setText(
            String.format("Name: %s \n Code: %s",
                    mPackageInfo.versionName,
                    mPackageInfo.versionCode)
    );
    mLinearLayout.addView(textView);
}
项目:mao-android    文件:BaseCameraView.java   
private void init() {
    setEGLContextClientVersion(2);
    setEGLConfigChooser(8, 8, 8, 8, 16, 0);
    getHolder().setFormat(PixelFormat.RGBA_8888);
    setRenderer(this);
    setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

    float[] cube = OpenGLUtils.CUBE;
    mCubeBuffer = ByteBuffer.allocateDirect(cube.length * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
    mCubeBuffer.put(cube);

    float[] textureCords = OpenGLUtils.getTextureCords(90, mCameraId == CameraInfo.CAMERA_FACING_FRONT, true);
    mTextureBuffer = ByteBuffer.allocateDirect(textureCords.length * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
    mTextureBuffer.put(textureCords);

    List<CameraFilter> filters = new ArrayList<>();
    filters.add(mCameraInputFilter);
    filters.addAll(initFilters());
    mCameraFilterGroup = new CameraFilterGroup(filters);
}
项目:Mobike    文件:CameraManager.java   
/**
 * A factory method to build the appropriate LuminanceSource object based on the format
 * of the preview buffers, as described by Camera.Parameters.
 *
 * @param data   A preview frame.
 * @param width  The width of the image.
 * @param height The height of the image.
 * @return A PlanarYUVLuminanceSource instance.
 */
public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data, int width, int height) {
    Rect rect = getFramingRectInPreview();
    int previewFormat = configManager.getPreviewFormat();
    String previewFormatString = configManager.getPreviewFormatString();
    switch (previewFormat) {
        // This is the standard Android format which all devices are REQUIRED to support.
        // In theory, it's the only one we should ever care about.
        case PixelFormat.YCbCr_420_SP:
            // This format has never been seen in the wild, but is compatible as we only care
            // about the Y channel, so allow it.
        case PixelFormat.YCbCr_422_SP:
            return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top,
                    rect.width(), rect.height());
        default:
            // The Samsung Moment incorrectly uses this variant instead of the 'sp' version.
            // Fortunately, it too has all the Y data up front, so we can read it.
            if ("yuv420p".equals(previewFormatString)) {
                return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top,
                        rect.width(), rect.height());
            }
    }
    throw new IllegalArgumentException("Unsupported picture format: " +
            previewFormat + '/' + previewFormatString);
}
项目:EVideoRecorder    文件:ERecorderActivity.java   
@Override
protected void initView() {

    mSurfaceview = (SurfaceView) findViewById(R.id.surfaceview);
    mRlTakeVedio = (RelativeLayout) findViewById(R.id.rl_take_vedio);
    mIvCancel = (ImageView) findViewById(R.id.iv_cancel);
    mTrpbController = (TimeRoundProgressBar) findViewById(R.id.trpb_controller);
    mRlConfrmVedio = (RelativeLayout) findViewById(R.id.rl_confrm_vedio);
    mIvDelete = (ImageView) findViewById(R.id.iv_delete);
    mIvConfirm = (ImageView) findViewById(R.id.iv_confirm);


    mDialog = ERecorderActivityImpl.getCreateVedioDialog(getActivity());
    mTrpbController.setMax(mRecordTime);

    SurfaceHolder holder = mSurfaceview.getHolder();// 取得holder
    holder.setFormat(PixelFormat.TRANSPARENT);
    holder.setKeepScreenOn(true);
    holder.addCallback(this); // holder加入回调接口
}
项目:RLibrary    文件:BmpUtil.java   
/**
 * Drawable转换为Bitmap
 *
 * @param drawable the drawable
 * @return bitmap
 */
public static Bitmap getBitmap(Drawable drawable) {
    if (drawable == null)
        return null;

    if (drawable instanceof BitmapDrawable) {
        return ((BitmapDrawable) drawable).getBitmap();
    } else {
        Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        drawable.draw(canvas);
        return bitmap;
    }
}
项目:RoadLab-Pro    文件:CustomMapView.java   
private int detectBestPixelFormat() {

        //Skip check if this is a new device as it will be RGBA_8888 by default.
        if (isRGBA_8888ByDefault) {
            return PixelFormat.RGBA_8888;
        }

        Context context = getContext();
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();

        //Get display pixel format
        int displayFormat = display.getPixelFormat();

        if ( PixelFormat.formatHasAlpha(displayFormat) ) {
            return displayFormat;
        } else {
            return PixelFormat.RGB_565;//Fallback for those who don't support Alpha
        }
    }
项目:XposedNavigationBar    文件:LightAndVolumeController.java   
protected void showDialog(Context context) {
    final WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    int h = getNavbarHeight(context);
    int w = WindowManager.LayoutParams.MATCH_PARENT;
    WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(w, h, WindowManager.LayoutParams.TYPE_TOAST, 0, PixelFormat.TRANSLUCENT);
    layoutParams.gravity = Gravity.BOTTOM;

    ViewGroup viewGroup;
    if (mType == LIGHT) {
        viewGroup = getLightPanel(context);
    } else {
        viewGroup = getVolumePanel(context);
    }

    if (lightPanel != null && lightPanel.isAttachedToWindow()) {
        wm.removeView(lightPanel);
    }
    if (volumePanel != null && volumePanel.isAttachedToWindow()) {
        wm.removeView(volumePanel);
    }

    wm.addView(viewGroup, layoutParams);
}
项目:AndroidUtilCode-master    文件:ImageUtils.java   
/**
 * drawable转bitmap
 *
 * @param drawable drawable对象
 * @return bitmap
 */
public static Bitmap drawable2Bitmap(Drawable drawable) {
    if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
        if (bitmapDrawable.getBitmap() != null) {
            return bitmapDrawable.getBitmap();
        }
    }
    Bitmap bitmap;
    if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
        bitmap = Bitmap.createBitmap(1, 1,
                drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
    } else {
        bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
    }
    Canvas canvas = new Canvas(bitmap);
    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
    drawable.draw(canvas);
    return bitmap;
}
项目:OSchina_resources_android    文件:KJDragGridView.java   
/**
 * 创建拖动的镜像
 *
 * @param bitmap
 * @param downX  按下的点相对父控件的X坐标
 * @param downY  按下的点相对父控件的X坐标
 */
private void createDragImage(Bitmap bitmap, int downX, int downY) {
    mWindowLayoutParams = new WindowManager.LayoutParams();
    mWindowLayoutParams.format = PixelFormat.TRANSLUCENT; // 图片之外的其他地方透明

    mWindowLayoutParams.gravity = Gravity.TOP | Gravity.LEFT;
    mWindowLayoutParams.x = downX - mPoint2ItemLeft + mOffset2Left;
    mWindowLayoutParams.y = downY - mPoint2ItemTop + mOffset2Top
            - mStatusHeight;
    mWindowLayoutParams.alpha = 0.55f; // 透明度

    mWindowLayoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
    mWindowLayoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
    mWindowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
            | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;

    mDragImageView = new ImageView(getContext());
    mDragImageView.setImageBitmap(bitmap);
    mWindowManager.addView(mDragImageView, mWindowLayoutParams);
}
项目:MyFire    文件:ACache.java   
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;
}
项目:RLibrary    文件:ACache.java   
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;
}
项目:Accessibility    文件:BitmapUtils.java   
public static Bitmap drawableToBitamp(Drawable drawable) {
    if (drawable instanceof BitmapDrawable) {
        BitmapDrawable bitmapDrawable = ((BitmapDrawable) drawable);
        return bitmapDrawable.getBitmap();
    } else {
        Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
                drawable.getOpacity() != PixelFormat.OPAQUE ? Config.ARGB_8888 : Config.RGB_565);

        Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        drawable.draw(canvas);
        return bitmap;
    }
}
项目:ucar-weex-core    文件:WXViewUtils.java   
@Opacity
public static int getOpacityFromColor(int color) {
  int colorAlpha = color >>> 24;
  if (colorAlpha == 255) {
    return PixelFormat.OPAQUE;
  } else if (colorAlpha == 0) {
    return PixelFormat.TRANSPARENT;
  } else {
    return PixelFormat.TRANSLUCENT;
  }
}
项目:Widgets    文件:SquareImageView.java   
/**
 * 将Drawable转换为Bitmap
 *
 * @param drawable 要转换的Drawable
 * @return 转换后的Bitmap
 */
private Bitmap d2b(Drawable drawable) {
    if (null != drawable) {
        if (drawable instanceof BitmapDrawable) {
            return ((BitmapDrawable) drawable).getBitmap();
        } else {
            Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565);
            Canvas canvas = new Canvas(bitmap);
            drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
            drawable.draw(canvas);
            return bitmap;
        }
    }
    return null;
}
项目:Zxing    文件:CameraManager.java   
/**
 * A factory method to build the appropriate LuminanceSource object based on
 * the format of the preview buffers, as described by Camera.Parameters.
 * 
 * @param data
 *            A preview frame.
 * @param width
 *            The width of the image.
 * @param height
 *            The height of the image.
 * @return A PlanarYUVLuminanceSource instance.
 */
@SuppressWarnings("deprecation")
public PlanarYUVLuminanceSource buildLuminanceSource(byte[] data,
                                                     int width, int height) {
    Rect rect = getFramingRectInPreview();
    int previewFormat = configManager.getPreviewFormat();
    String previewFormatString = configManager.getPreviewFormatString();
    switch (previewFormat) {
    // This is the standard Android format which all devices are REQUIRED to
    // support.
    // In theory, it's the only one we should ever care about.
    case PixelFormat.YCbCr_420_SP:
        // This format has never been seen in the wild, but is compatible as
        // we only care
        // about the Y channel, so allow it.
    case PixelFormat.YCbCr_422_SP:
        return new PlanarYUVLuminanceSource(data, width, height, rect.left,
                rect.top, rect.width(), rect.height());
    default:
        // The Samsung Moment incorrectly uses this variant instead of the
        // 'sp' version.
        // Fortunately, it too has all the Y data up front, so we can read
        // it.
        if ("yuv420p".equals(previewFormatString)) {
            return new PlanarYUVLuminanceSource(data, width, height,
                    rect.left, rect.top, rect.width(), rect.height());
        }
    }
    throw new IllegalArgumentException("Unsupported picture format: "
            + previewFormat + '/' + previewFormatString);
}
项目:RX_Demo    文件:ResideLayout.java   
private static boolean viewIsOpaque(View v) {
    if (ViewCompat.isOpaque(v)) return true;

    // View#isOpaque didn't take all valid opaque scrollbar modes into account
    // before API 18 (JB-MR2). On newer devices rely solely on isOpaque above and return false
    // here. On older devices, check the view's background drawable directly as a fallback.
    if (Build.VERSION.SDK_INT >= 18) return false;

    final Drawable bg = v.getBackground();
    if (bg != null) {
        return bg.getOpacity() == PixelFormat.OPAQUE;
    }
    return false;
}
项目:tvConnect_android    文件:ImageSurfaceView.java   
public ImageSurfaceView(Context context, AttributeSet attrs) {
    super(context, attrs);
    mSurHolder = getHolder();
    mSurHolder.addCallback(this);
    this.setOnTouchListener(this);
    setZOrderOnTop(true);//使surfaceview放到最顶层
    getHolder().setFormat(PixelFormat.TRANSLUCENT);
}
项目:trascendentAR    文件:ARLauncher.java   
@Override
public void initialize(ApplicationListener listener, AndroidApplicationConfiguration config){
    //Las siguientes dos lines son necesaria para poder añadir markers de la manera que ARToolKit lo maneja
    AssetHelper assetHelper = new AssetHelper(getAssets());
    assetHelper.cacheAssetFolder(this, "Data");

    mainLayout = new FrameLayout(this);
    config.r = 8;
    config.g = 8;
    config.b = 8;
    config.a = 8;

    //Configuraciones basicas
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().setFormat(PixelFormat.TRANSLUCENT);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    gameView = initializeForView(listener, config);

    if(graphics.getView() instanceof SurfaceView){
        SurfaceView glView = (SurfaceView)graphics.getView();
        glView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
    }

    setContentView(mainLayout);
}
项目:screenfilter    文件:PopupIndicator.java   
private WindowManager.LayoutParams createPopupLayout(IBinder token) {
    WindowManager.LayoutParams p = new WindowManager.LayoutParams();
    p.gravity = Gravity.START | Gravity.TOP;
    p.width = ViewGroup.LayoutParams.MATCH_PARENT;
    p.height = ViewGroup.LayoutParams.MATCH_PARENT;
    p.format = PixelFormat.TRANSLUCENT;
    p.flags = computeFlags(p.flags);
    p.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
    p.token = token;
    p.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN;
    p.setTitle("DiscreteSeekBar Indicator:" + Integer.toHexString(hashCode()));

    return p;
}
项目:GitHub    文件:DrawableUtilsTest.java   
@Test
public void testGetOpacityFromColor() {
  assertEquals(PixelFormat.TRANSPARENT, DrawableUtils.getOpacityFromColor(0x00000000));
  assertEquals(PixelFormat.TRANSPARENT, DrawableUtils.getOpacityFromColor(0x00123456));
  assertEquals(PixelFormat.TRANSPARENT, DrawableUtils.getOpacityFromColor(0x00FFFFFF));
  assertEquals(PixelFormat.TRANSLUCENT, DrawableUtils.getOpacityFromColor(0xC0000000));
  assertEquals(PixelFormat.TRANSLUCENT, DrawableUtils.getOpacityFromColor(0xC0123456));
  assertEquals(PixelFormat.TRANSLUCENT, DrawableUtils.getOpacityFromColor(0xC0FFFFFF));
  assertEquals(PixelFormat.OPAQUE, DrawableUtils.getOpacityFromColor(0xFF000000));
  assertEquals(PixelFormat.OPAQUE, DrawableUtils.getOpacityFromColor(0xFF123456));
  assertEquals(PixelFormat.OPAQUE, DrawableUtils.getOpacityFromColor(0xFFFFFFFF));
}
项目:RLibrary    文件:StyleActivity.java   
@Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        L.e(getClass().getSimpleName() + " 任务栈:" + getTaskId());
        getWindow().setFormat(PixelFormat.TRANSLUCENT);//TBS X5

        loadActivityStyle();
        initWindow();
        initUIActivity();

//        onCreateView();
    }
项目:EasyOne    文件:OverlayService.java   
@Override
public void onCreate() {
    super.onCreate();

    FrameLayout frameLayout = new FrameLayout(this);

    frameLayout.setBackgroundColor(getResources().getColor(R.color.colorPhoneDark, getTheme()));
    WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);


    //change this through preferences
    int dragWidth = 20;

    WindowManager.LayoutParams params = new WindowManager.LayoutParams(dragWidth, WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, PixelFormat.TRANSLUCENT);

    //change this through preferences
    params.gravity = Gravity.START;

    params.x = 0;
    params.y = 0;

    frameLayout.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            Toast.makeText(OverlayService.this, "yo", Toast.LENGTH_SHORT)
                    .show();
            return false;
        }
    });

    if (windowManager != null) {
        windowManager.addView(frameLayout, params);
    }
}
项目:grafika    文件:ColorBarActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_color_bar);

    mSurfaceView = (SurfaceView) findViewById(R.id.colorBarSurfaceView);
    mSurfaceView.getHolder().addCallback(this);
    mSurfaceView.getHolder().setFormat(PixelFormat.RGBA_8888);
}
项目:Markwon    文件:AsyncDrawable.java   
@Override
public int getOpacity() {
    final int opacity;
    if (hasResult()) {
        opacity = result.getOpacity();
    } else {
        opacity = PixelFormat.TRANSPARENT;
    }
    return opacity;
}
项目:accelerator-core-android    文件:ScreenSharingFragment.java   
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void setUpVirtualDisplay() {

    mScreen = (ViewGroup) getActivity().getWindow().getDecorView().getRootView();

    // display metrics
    DisplayMetrics metrics = getResources().getDisplayMetrics();
    mDensity = metrics.densityDpi;
    Display mDisplay = getActivity().getWindowManager().getDefaultDisplay();

    Point size = new Point();
    mDisplay.getRealSize(size);
    mWidth = size.x;
    mHeight = size.y;

    // start capture reader
    mImageReader = ImageReader.newInstance(mWidth, mHeight, PixelFormat.RGBA_8888, 2);
    int flags = DisplayManager.VIRTUAL_DISPLAY_FLAG_AUTO_MIRROR;

    mVirtualDisplay = mMediaProjection.createVirtualDisplay("ScreenCapture", mWidth, mHeight, mDensity, flags, mImageReader.getSurface(), null, null);

    size.set(mWidth, mHeight);

    //create ScreenCapturer
    mScreenCapturer = new ScreenSharingCapturer(getActivity(), mScreen, mImageReader);

    mListener.onScreenCapturerReady();
}
项目:FloatingWidget    文件:FloatingWidgetService.java   
private void initPosition() {
    mParams = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.TYPE_PHONE,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
            PixelFormat.TRANSLUCENT);

    mParams.gravity = Gravity.TOP | Gravity.LEFT;
    mParams.x = 0;
    mParams.y = 150;

    mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
    mWindowManager.addView(mFloatingView, mParams);
}