@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();
}
java类android.graphics.PixelFormat的实例源码
ScreenFilterService.java 文件源码
项目:Crimson
阅读 28
收藏 0
点赞 0
评论 0
BorderDrawableTest.java 文件源码
项目:ucar-weex-core
阅读 34
收藏 0
点赞 0
评论 0
@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));
}
MaskWindowUtils.java 文件源码
项目:Keyguard
阅读 40
收藏 0
点赞 0
评论 0
@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;
}
BitmapUtils.java 文件源码
项目:rongyunDemo
阅读 49
收藏 0
点赞 0
评论 0
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;
}
CameraManager.java 文件源码
项目:GitHub
阅读 38
收藏 0
点赞 0
评论 0
/**
* 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);
}
CacheUtils.java 文件源码
项目:AndroidUtilCode-master
阅读 38
收藏 0
点赞 0
评论 0
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;
}
SurfaceViewTemplate.java 文件源码
项目:decoy
阅读 34
收藏 0
点赞 0
评论 0
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);
}
SpanUtils.java 文件源码
项目:HeadlineNews
阅读 39
收藏 0
点赞 0
评论 0
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;
}
ACache.java 文件源码
项目:CoolApk-Console
阅读 37
收藏 0
点赞 0
评论 0
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;
}
ImageUtils.java 文件源码
项目:BBSSDK-for-Android
阅读 62
收藏 0
点赞 0
评论 0
/**
* 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;
}
MediaRecorderBase.java 文件源码
项目:meipai-Android
阅读 37
收藏 0
点赞 0
评论 0
/** 设置回调 */
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);
}
}
ACache.java 文件源码
项目:AndroidBasicLibs
阅读 43
收藏 0
点赞 0
评论 0
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;
}
CameraInterface.java 文件源码
项目:FaceRecognition
阅读 37
收藏 0
点赞 0
评论 0
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;
}
TooltipPopup.java 文件源码
项目:cwac-crossport
阅读 38
收藏 0
点赞 0
评论 0
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;
}
OverlayView.java 文件源码
项目:BuildNumberOverlay
阅读 33
收藏 0
点赞 0
评论 0
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);
}
BaseCameraView.java 文件源码
项目:mao-android
阅读 40
收藏 0
点赞 0
评论 0
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);
}
CameraManager.java 文件源码
项目:Mobike
阅读 42
收藏 0
点赞 0
评论 0
/**
* 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);
}
ERecorderActivity.java 文件源码
项目:EVideoRecorder
阅读 36
收藏 0
点赞 0
评论 0
@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加入回调接口
}
BmpUtil.java 文件源码
项目:RLibrary
阅读 42
收藏 0
点赞 0
评论 0
/**
* 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;
}
}
CustomMapView.java 文件源码
项目:RoadLab-Pro
阅读 34
收藏 0
点赞 0
评论 0
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
}
}
LightAndVolumeController.java 文件源码
项目:XposedNavigationBar
阅读 42
收藏 0
点赞 0
评论 0
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);
}
ImageUtils.java 文件源码
项目:AndroidUtilCode-master
阅读 46
收藏 0
点赞 0
评论 0
/**
* 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;
}
KJDragGridView.java 文件源码
项目:OSchina_resources_android
阅读 33
收藏 0
点赞 0
评论 0
/**
* 创建拖动的镜像
*
* @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);
}
ACache.java 文件源码
项目:MyFire
阅读 42
收藏 0
点赞 0
评论 0
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;
}
ACache.java 文件源码
项目:RLibrary
阅读 36
收藏 0
点赞 0
评论 0
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;
}
BitmapUtils.java 文件源码
项目:Accessibility
阅读 43
收藏 0
点赞 0
评论 0
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;
}
}
WXViewUtils.java 文件源码
项目:ucar-weex-core
阅读 40
收藏 0
点赞 0
评论 0
@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;
}
}
SquareImageView.java 文件源码
项目:Widgets
阅读 76
收藏 0
点赞 0
评论 0
/**
* 将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;
}
CameraManager.java 文件源码
项目:Zxing
阅读 32
收藏 0
点赞 0
评论 0
/**
* 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);
}
ResideLayout.java 文件源码
项目:RX_Demo
阅读 31
收藏 0
点赞 0
评论 0
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;
}