本文整理匯總了Java中android.graphics.drawable.Drawable.getOpacity方法的典型用法代碼示例。如果您正苦於以下問題:Java Drawable.getOpacity方法的具體用法?Java Drawable.getOpacity怎麽用?Java Drawable.getOpacity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.graphics.drawable.Drawable
的用法示例。
在下文中一共展示了Drawable.getOpacity方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: drawable2Bitmap
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
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;
}
示例2: drawable2Bitmap
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
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;
}
示例3: createBitmapFromDrawable
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private Bitmap createBitmapFromDrawable(final Drawable drawable) {
if (drawable == null) {
return null;
}
Bitmap bitmap = null;
final int intrinsicWidth = drawable.getIntrinsicWidth();
final int intrinsicHeight = drawable.getIntrinsicHeight();
try {
Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
: Bitmap.Config.RGB_565;
bitmap = Bitmap.createBitmap(intrinsicWidth, intrinsicHeight,
config);
} catch (OutOfMemoryError e) {
return null;
}
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, intrinsicWidth, intrinsicHeight);
drawable.draw(canvas);
canvas = null;
return bitmap;
}
示例4: drawable2Bitmap
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
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;
}
示例5: drawable2Bitmap
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
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;
}
示例6: drawable2Bitmap
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
* Drawable → Bitmap
*/
private static Bitmap drawable2Bitmap(Drawable drawable) {
if (drawable == null) {
return null;
}
// Take the length and width of drawable
int w = drawable.getIntrinsicWidth();
int h = drawable.getIntrinsicHeight();
// Take the color format for drawable
Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;
// Establishing corresponding bitmap
Bitmap bitmap = Bitmap.createBitmap(w, h, config);
// Create a canvas corresponding to bitmap
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, w, h);
// The content of the drawable to the canvas
drawable.draw(canvas);
return bitmap;
}
示例7: toBitmap2
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
* drawable 轉換為 Bitmap.
*
* @param drawable Drawable
* @return Bitmap
*/
private static Bitmap toBitmap2(Drawable drawable)
{
Bitmap bitmap;
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.createBitmap(w, h, config);
//注意,下麵三行代碼要用到,否在在View或者surfaceview裏的canvas.drawBitmap會看不到圖
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, w, h);
drawable.draw(canvas);
return bitmap;
}
示例8: viewIsOpaque
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private static boolean viewIsOpaque(View v) {
if (ViewCompat.isOpaque(v)) {
return true;
}
if (VERSION.SDK_INT >= 18) {
return false;
}
Drawable bg = v.getBackground();
if (bg == null) {
return false;
}
if (bg.getOpacity() != -1) {
return false;
}
return true;
}
示例9: drawableToBitmap
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
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;
}
示例10: drawableToBitamp
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private static Bitmap drawableToBitamp(Drawable drawable) {
Bitmap bitmap;
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.createBitmap(w, h, config);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, w, h);
drawable.draw(canvas);
return bitmap;
}
示例11: drawableToBitmap
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
static Bitmap drawableToBitmap(Drawable drawable) // drawable 轉換成bitmap
{
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;
}
示例12: viewIsOpaque
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
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;
}
示例13: drawable2Bitmap
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
/**
* Drawable 轉 Bitmap
*
* @param drawable Drawable
* @return Bitmap
*/
private Bitmap drawable2Bitmap(Drawable drawable) {
// 取 drawable 的長寬
int width = drawable.getIntrinsicWidth();
int height = drawable.getIntrinsicHeight();
// 取 drawable 的顏色格式
Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;
// 建立對應 bitmap
Bitmap bitmap = Bitmap.createBitmap(width, height, config);
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, width, height);
drawable.draw(canvas);
return bitmap;
}
示例14: hasOpaqueBackground
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private static boolean hasOpaqueBackground(View v) {
final Drawable bg = v.getBackground();
return bg != null && bg.getOpacity() == PixelFormat.OPAQUE;
}
示例15: hasOpaqueBackground
import android.graphics.drawable.Drawable; //導入方法依賴的package包/類
private static boolean hasOpaqueBackground(View v) {
final Drawable bg = v.getBackground();
return bg != null && bg.getOpacity() == PixelFormat.OPAQUE;
}