下面列出了android.graphics.PixelFormat#RGB_565 ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public void push(Image image, int pixelFormat) {
Image.Plane[] planes = image.getPlanes();
ByteBuffer b = planes[0].getBuffer();
if (pixelFormat == PixelFormat.RGBA_8888) {
// planes[0].getPixelStride() has to be 4 (32 bit)
jni_push_pixels_rgba_8888(b, planes[0].getRowStride());
}
else if (pixelFormat == PixelFormat.RGB_565)
{
// planes[0].getPixelStride() has to be 16 (16 bit)
jni_push_pixels_rgba_565(b, planes[0].getRowStride());
}
else
{
Log.e(TAG, "Image reader acquired unsupported image format " + pixelFormat);
}
}
@NonNull
private WindowManager.LayoutParams createLayoutParams() {
int type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
int flags = WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED
| WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
| WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
type, flags,
PixelFormat.RGB_565);
lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN;
return lp;
}
@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();
}
}
@Override public WindowManager.LayoutParams getWindowLayoutParams() {
int flags = (
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR |
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED );
WindowManager.LayoutParams WPARAMS = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0, 0,
WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, flags, PixelFormat.RGB_565);
WPARAMS.windowAnimations = android.R.style.Animation_Dialog;
WPARAMS.packageName = getContext().getPackageName();
WPARAMS.rotationAnimation = WindowManager.LayoutParams.ROTATION_ANIMATION_CROSSFADE;
WPARAMS.setTitle(TAG);
Resources res = getResources();
final int panelWidth = getNotificationPanelWidth();
final int maxWidth = ((panelWidth > 0) ? panelWidth : res.getDimensionPixelSize(R.dimen.notification_panel_width));
final int menuWidth = res.getDimensionPixelSize(R.dimen.max_menu_width);
final int screenWidth = getWindowWidth();
if (stretch || (maxWidth <= 0) || (!res.getBoolean(R.bool.isTablet) && screenWidth < menuWidth)) {
WPARAMS.gravity = (Gravity.FILL_HORIZONTAL | Gravity.TOP);
} else {
WPARAMS.gravity = (Gravity.CENTER_HORIZONTAL | Gravity.TOP);
WPARAMS.width = (maxWidth <= 0) ? menuWidth : maxWidth;
}
WPARAMS.screenBrightness = WPARAMS.buttonBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
return WPARAMS;
}
@SuppressWarnings("deprecation")
private int bitsPerComponent(int pixelFormatId) {
switch (pixelFormatId) {
case PixelFormat.RGBA_4444:
return 4;
case PixelFormat.RGBA_5551:
return 5;
case PixelFormat.RGBA_8888:
case PixelFormat.RGBX_8888:
case PixelFormat.RGB_888:
return 8;
case PixelFormat.RGB_332:
return 2;
case PixelFormat.RGB_565:
return 5;
// Non-RGB formats.
case PixelFormat.A_8:
case PixelFormat.LA_88:
case PixelFormat.L_8:
return 0;
// Unknown format. Use 8 as a sensible default.
default:
return 8;
}
}
@Override public WindowManager.LayoutParams getWindowLayoutParams() {
int flags = (
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR |
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED );
WindowManager.LayoutParams WPARAMS = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0, 0,
WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, flags, PixelFormat.RGB_565);
WPARAMS.windowAnimations = android.R.style.Animation_Dialog;
WPARAMS.packageName = getContext().getPackageName();
WPARAMS.rotationAnimation = WindowManager.LayoutParams.ROTATION_ANIMATION_CROSSFADE;
WPARAMS.setTitle(TAG);
Resources res = getResources();
final int panelWidth = getNotificationPanelWidth();
final int maxWidth = ((panelWidth > 0) ? panelWidth : res.getDimensionPixelSize(R.dimen.notification_panel_width));
final int menuWidth = res.getDimensionPixelSize(R.dimen.max_menu_width);
final int screenWidth = getWindowWidth();
if (stretch || (maxWidth <= 0) || (!res.getBoolean(R.bool.isTablet) && screenWidth < menuWidth)) {
WPARAMS.gravity = (Gravity.FILL_HORIZONTAL | Gravity.TOP);
} else {
WPARAMS.gravity = (Gravity.CENTER_HORIZONTAL | Gravity.TOP);
WPARAMS.width = (maxWidth <= 0) ? menuWidth : maxWidth;
}
WPARAMS.screenBrightness = WPARAMS.buttonBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
return WPARAMS;
}
/**
* @return Bits per component.
*/
@SuppressWarnings("deprecation")
@CalledByNative
public int getBitsPerComponent() {
int format = getPixelFormat();
switch (format) {
case PixelFormat.RGBA_4444:
return 4;
case PixelFormat.RGBA_5551:
return 5;
case PixelFormat.RGBA_8888:
case PixelFormat.RGBX_8888:
case PixelFormat.RGB_888:
return 8;
case PixelFormat.RGB_332:
return 2;
case PixelFormat.RGB_565:
return 5;
// Non-RGB formats.
case PixelFormat.A_8:
case PixelFormat.LA_88:
case PixelFormat.L_8:
return 0;
// Unknown format. Use 8 as a sensible default.
default:
return 8;
}
}
private int getPixelFormat(EGLConfig conf, EGLDisplay display, EGL10 egl)
{
int[] value = new int[1];
int result = PixelFormat.RGB_565;
egl.eglGetConfigAttrib(display, conf, EGL10.EGL_RED_SIZE, value);
if (value[0] == 8)
{
result = PixelFormat.RGBA_8888;
/*
egl.eglGetConfigAttrib(display, conf, EGL10.EGL_ALPHA_SIZE, value);
if (value[0] == 8)
{
result = PixelFormat.RGBA_8888;
}
else
{
result = PixelFormat.RGB_888;
}*/
}
if (verbose)
{
logger.info("Using PixelFormat " + result);
}
//return result; TODO Test pixelformat
return PixelFormat.TRANSPARENT;
}
/**
* @return Bits per component.
*/
@SuppressWarnings("deprecation")
@CalledByNative
public int getBitsPerComponent() {
int format = getPixelFormat();
switch (format) {
case PixelFormat.RGBA_4444:
return 4;
case PixelFormat.RGBA_5551:
return 5;
case PixelFormat.RGBA_8888:
case PixelFormat.RGBX_8888:
case PixelFormat.RGB_888:
return 8;
case PixelFormat.RGB_332:
return 2;
case PixelFormat.RGB_565:
return 5;
// Non-RGB formats.
case PixelFormat.A_8:
case PixelFormat.LA_88:
case PixelFormat.L_8:
return 0;
// Unknown format. Use 8 as a sensible default.
default:
return 8;
}
}
private String formatToString(int format) {
switch (format) {
case ImageFormat.YV12:
return "YV12";
case ImageFormat.YUV_420_888:
return "YUV_420_888";
case ImageFormat.NV21:
return "NV21";
case ImageFormat.NV16:
return "NV16";
case PixelFormat.RGB_565:
return "RGB_565";
case PixelFormat.RGBA_8888:
return "RGBA_8888";
case PixelFormat.RGBX_8888:
return "RGBX_8888";
case PixelFormat.RGB_888:
return "RGB_888";
case ImageFormat.JPEG:
return "JPEG";
case ImageFormat.YUY2:
return "YUY2";
case ImageFormat.Y8:
return "Y8";
case ImageFormat.Y16:
return "Y16";
case ImageFormat.RAW_SENSOR:
return "RAW_SENSOR";
case ImageFormat.RAW_PRIVATE:
return "RAW_PRIVATE";
case ImageFormat.RAW10:
return "RAW10";
case ImageFormat.DEPTH16:
return "DEPTH16";
case ImageFormat.DEPTH_POINT_CLOUD:
return "DEPTH_POINT_CLOUD";
case ImageFormat.RAW_DEPTH:
return "RAW_DEPTH";
case ImageFormat.PRIVATE:
return "PRIVATE";
default:
return "UNKNOWN";
}
}