多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > 綜合技術 > Android 圖片工具ImageUtil

Android 圖片工具ImageUtil

來源:程序員人生   發布時間:2016-03-18 18:42:53 閱讀次數:3104次

24.Android 圖片工具ImageUtil



  • Android 圖片工具ImageUtil
    • 裁圖
    • Bitmap圓角
    • 縮略圖
    • 視頻縮略圖
    • 各種類型轉換
    • ImageUtil全部源碼






裁圖

/** * 調用系統自帶裁圖工具 * * @param activity * @param size * @param uri * @param action * @param cropFile */ public static void cropPicture(Activity activity, int size, Uri uri, int action, File cropFile) { try { Intent intent = new Intent("com.android.camera.action.CROP"); intent.setDataAndType(uri, "image/*"); // 返回格式 intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString()); intent.putExtra("crop", true); intent.putExtra("aspectX", 1); intent.putExtra("aspectY", 1); intent.putExtra("outputX", size); intent.putExtra("outputY", size); intent.putExtra("scale", true); intent.putExtra("scaleUpIfNeeded", true); intent.putExtra("cropIfNeeded", true); intent.putExtra("return-data", false); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(cropFile)); activity.startActivityForResult(intent, action); } catch (Exception e) { e.printStackTrace(); } } /** * 調用系統自帶裁圖工具 * outputX = 250 * outputY = 250 * * @param activity * @param uri * @param action * @param cropFile */ public static void cropPicture(Activity activity, Uri uri, int action, File cropFile) { cropPicture(activity, 250, uri, action, cropFile); } /** * 調用系統自帶裁圖工具 * 并保存文件 * outputX = 250 * outputY = 250 * * @param activity * @param uri * @param action * @param appName * @param application * @return */ public static File cropPicture(Activity activity, Uri uri, int action, String appName, Application application) { File resultFile = createImageFile(appName, application); cropPicture(activity, 250, uri, action, resultFile); return resultFile; } /** * 創建圖片文件 * * @param appName * @param application * @return */ @SuppressLint("SimpleDateFormat") public static File createImageFile(String appName, Application application) { File folder = createImageFileInCameraFolder(appName, application); String filename = new SimpleDateFormat("yyyyMMddHHmmss").format(System.currentTimeMillis()); return new File(folder, filename + ".jpg"); } /** * 創建圖片文件夾 * * @param appName * @param application * @return */ public static File createImageFileInCameraFolder(String appName, Application application) { String folder = ImageUtil.createAPPFolder(appName, application); File file = new File(folder, "image"); if (!file.exists()) { file.mkdirs(); } return file; } /** * 創建App文件夾 * * @param appName * @param application * @return */ public static String createAPPFolder(String appName, Application application) { return createAPPFolder(appName, application, null); } /** * 創建App文件夾 * * @param appName * @param application * @param folderName * @return */ public static String createAPPFolder(String appName, Application application, String folderName) { File root = Environment.getExternalStorageDirectory(); File folder; /** * 如果存在SD卡 */ if (DeviceUtil.isSDCardAvailable() && root != null) { folder = new File(root, appName); if (!folder.exists()) { folder.mkdirs(); } } else { /** * 不存在SD卡,就放到緩存文件夾內 */ root = application.getCacheDir(); folder = new File(root, appName); if (!folder.exists()) { folder.mkdirs(); } } if (folderName != null) { folder = new File(folder, folderName); if (!folder.exists()) { folder.mkdirs(); } } return folder.getAbsolutePath(); }



Bitmap圓角

/** * 獲得圓角Bitmap * * @param srcBitmap * @param radius * @return */ public static Bitmap getRoundedCornerBitmap(Bitmap srcBitmap, float radius) { Bitmap resultBitmap = Bitmap.createBitmap(srcBitmap.getWidth(), srcBitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(resultBitmap); Paint paint = new Paint(); Rect rect = new Rect(0, 0, srcBitmap.getWidth(), srcBitmap.getHeight()); RectF rectF = new RectF(rect); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(0xBDBDBE); canvas.drawRoundRect(rectF, radius, radius, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(srcBitmap, rect, rect, paint); return resultBitmap; }



縮略圖

/** * 獲得縮略圖 * * @param path * @param targetWidth * @return */ public static String getThumbnailImage(String path, int targetWidth) { Bitmap scaleImage = decodeScaleImage(path, targetWidth, targetWidth); try { File file = File.createTempFile("image", ".jpg"); FileOutputStream fileOutputStream = new FileOutputStream(file); scaleImage.compress(Bitmap.CompressFormat.JPEG, 60, fileOutputStream); fileOutputStream.close(); return file.getAbsolutePath(); } catch (Exception e) { e.printStackTrace(); return path; } } /** * 圖片解析 * * @param context * @param resId * @param targetWidth * @param targetHeight * @return */ public static Bitmap decodeScaleImage(Context context, int resId, int targetWidth, int targetHeight) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeResource(context.getResources(), resId, options); options.inSampleSize = calculateInSampleSize(options, targetWidth, targetHeight); options.inJustDecodeBounds = false; Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resId, options); return bitmap; } /** * 計算樣本大小 * * @param options * @param targetWidth * @param targetHeight * @return */ public static int calculateInSampleSize(BitmapFactory.Options options, int targetWidth, int targetHeight) { int height = options.outHeight; int width = options.outWidth; int scale = 1; if (height > targetHeight || width > targetWidth) { int heightScale = Math.round((float) height / (float) targetHeight); int widthScale = Math.round((float) width / (float) targetWidth); scale = heightScale > widthScale ? heightScale : widthScale; } return scale; } /** * 獲得BitmapFactory.Options * * @param pathName * @return */ public static BitmapFactory.Options getBitmapOptions(String pathName) { BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(pathName, opts); return opts; } /** * 獲得圖片角度 * * @param filename * @return */ public static int readPictureDegree(String filename) { short degree = 0; try { ExifInterface exifInterface = new ExifInterface(filename); int anInt = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); switch (anInt) { case ExifInterface.ORIENTATION_ROTATE_180: degree = 180; case ExifInterface.ORIENTATION_FLIP_VERTICAL: case ExifInterface.ORIENTATION_TRANSPOSE: case ExifInterface.ORIENTATION_TRANSVERSE: default: break; case ExifInterface.ORIENTATION_ROTATE_90: degree = 90; break; case ExifInterface.ORIENTATION_ROTATE_270: degree = 270; } } catch (IOException e) { e.printStackTrace(); } return degree; } /** * 旋轉ImageView * * @param degree * @param source * @return */ public static Bitmap rotatingImageView(int degree, Bitmap source) { Matrix matrix = new Matrix(); matrix.postRotate((float) degree); return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true); }



視頻縮略圖

/** * 保存視頻縮略圖 * * @param file * @param width * @param height * @param kind * @return */ public static String saveVideoThumbnail(File file, int width, int height, int kind) { Bitmap videoThumbnail = getVideoThumbnail(file.getAbsolutePath(), width, height, kind); File thumbFile = new File(PathUtil.getInstance().getVideoPath(), "th" + file.getName()); try { thumbFile.createNewFile(); } catch (IOException e) { e.printStackTrace(); } FileOutputStream fileOutputStream = null; try { fileOutputStream = new FileOutputStream(thumbFile); } catch (FileNotFoundException var10) { var10.printStackTrace(); } videoThumbnail.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream); try { fileOutputStream.flush(); } catch (IOException e) { e.printStackTrace(); } try { fileOutputStream.close(); } catch (IOException var8) { var8.printStackTrace(); } return thumbFile.getAbsolutePath(); }



各種類型轉換

/** * Image resource ID was converted into a byte [] data * 圖片資源ID 轉換 為 圖片 byte[] 數據 * * @param context * @param imageResourceId * @return */ public static byte[] toByteArray(Context context, int imageResourceId) { Bitmap bitmap = ImageUtil.toBitmap(context, imageResourceId); if (bitmap != null) { return ImageUtil.toByteArray(bitmap); } else { return null; } } /** * ImageView getDrawable () into a byte [] data * ImageView的getDrawable() 轉換為 byte[] 數據 * * @param imageView * @return */ public static byte[] toByteArray(ImageView imageView) { Bitmap bitmap = ImageUtil.toBitmap(imageView); if (bitmap != null) return ImageUtil.toByteArray(bitmap); else { Log.w(ImageUtil.TAG, "the ImageView imageView content was invalid"); return null; } } /** * byte [] data type conversion for Bitmap data types * byte[]數據類型轉換為 Bitmap數據類型 * * @param imageData * @return */ public static Bitmap toBitmap(byte[] imageData) { if ((imageData != null) && (imageData.length != 0)) { Bitmap bitmap = BitmapFactory.decodeByteArray(imageData, 0, imageData.length); return bitmap; } else { Log.w(ImageUtil.TAG, "the byte[] imageData content was invalid"); return null; } } /** * Image resource ID is converted to Bitmap type data * 資源ID 轉換為 Bitmap類型數據 * * @param context * @param imageResourceId * @return */ public static Bitmap toBitmap(Context context, int imageResourceId) { // 將圖片轉化為位圖 Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), imageResourceId); if (bitmap != null) { return bitmap; } else { Log.w(ImageUtil.TAG, "the int imageResourceId content was invalid"); return null; } } /** * ImageView types into a Bitmap * ImageView類型轉換為Bitmap * * @param imageView * @return */ public static Bitmap toBitmap(ImageView imageView) { if (imageView.getDrawable() != null) { Bitmap bitmap = ImageUtil.toBitmap(imageView.getDrawable()); return bitmap; } else { return null; } } /** * Bitmap type is converted into a image byte [] data * Bitmap類型 轉換 為圖片 byte[] 數據 * * @param bitmap * @return */ public static byte[] toByteArray(Bitmap bitmap) { if (bitmap != null) { int size = bitmap.getWidth() * bitmap.getHeight() * 4; // 創建1個字節數組輸出流,流的大小為size ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream( size); // 設置位圖的緊縮格式,質量為100%,并放入字節數組輸出流中 bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream); // 將字節數組輸出流轉化為字節數組byte[] byte[] imageData = byteArrayOutputStream.toByteArray(); return imageData; } else { Log.w(ImageUtil.TAG, "the Bitmap bitmap content was invalid"); return null; } } /** * Drawable type into a Bitmap * Drawable 類型轉換為 Bitmap類型 * * @param drawable * @return */ public static Bitmap toBitmap(Drawable drawable) { if (drawable != null) { BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; Bitmap bitmap = bitmapDrawable.getBitmap(); return bitmap; } else { Log.w(ImageUtil.TAG, "the Drawable drawable content was invalid"); return null; } } /** * Bitmap type into a Drawable * Bitmap 類型轉換為 Drawable類型 * * @param bitmap * @return */ public static Drawable toDrawable(Bitmap bitmap) { if (bitmap != null) { Drawable drawable = new BitmapDrawable(bitmap); return drawable; } else { Log.w(ImageUtil.TAG, "the Bitmap bitmap content was invalid"); return null; } }



ImageUtil全部源碼

public class ImageUtil { private static final String TAG = "ImageUtil"; public static final int ACTION_SET_AVATAR = 260; public static final int ACTION_SET_COVER = 261; public static final int ACTION_TAKE_PIC = 262; public static final int ACTION_TAKE_PIC_FOR_GRIDVIEW = 263; public static final int ACTION_PICK_PIC = 264; public static final int ACTION_ACTION_CROP = 265; /** * 調用系統自帶裁圖工具 * * @param activity * @param size * @param uri * @param action * @param cropFile */ public static void cropPicture(Activity activity, int size, Uri uri, int action, File cropFile) { try { Intent intent = new Intent("com.android.camera.action.CROP"); intent.setDataAndType(uri, "image/*"); // 返回格式 intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString()); intent.putExtra("crop", true); intent.putExtra("aspectX", 1); intent.putExtra("aspectY", 1); intent.putExtra("outputX", size); intent.putExtra("outputY", size); intent.putExtra("scale", true); intent.putExtra("scaleUpIfNeeded", true); intent.putExtra("cropIfNeeded", true); intent.putExtra("return-data", false); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(cropFile)); activity.startActivityForResult(intent, action); } catch (Exception e) { e.printStackTrace(); } } /** * 調用系統自帶裁圖工具 * outputX = 250 * outputY = 250 * * @param activity * @param uri * @param action * @param cropFile */ public static void cropPicture(Activity activity, Uri uri, int action, File cropFile) { cropPicture(activity, 250, uri, action, cropFile); } /** * 調用系統自帶裁圖工具 * 并保存文件 * outputX = 250 * outputY = 250 * * @param activity * @param uri * @param action * @param appName * @param application * @return */ public static File cropPicture(Activity activity, Uri uri, int action, String appName, Application application) { File resultFile = createImageFile(appName, application); cropPicture(activity, 250, uri, action, resultFile); return resultFile; } /** * 創建圖片文件 * * @param appName * @param application * @return */ @SuppressLint("SimpleDateFormat") public static File createImageFile(String appName, Application application) { File folder = createImageFileInCameraFolder(appName, application); String filename = new SimpleDateFormat("yyyyMMddHHmmss").format(System.currentTimeMillis()); return new File(folder, filename + ".jpg"); } /** * 創建圖片文件夾 * * @param appName * @param application * @return */ public static File createImageFileInCameraFolder(String appName, Application application) { String folder = ImageUtil.createAPPFolder(appName, application); File file = new File(folder, "image"); if (!file.exists()) { file.mkdirs(); } return file; } /** * 創建App文件夾 * * @param appName * @param application * @return */ public static String createAPPFolder(String appName, Application application) { return createAPPFolder(appName, application, null); } /** * 創建App文件夾 * * @param appName * @param application * @param folderName * @return */ public static String createAPPFolder(String appName, Application application, String folderName) { File root = Environment.getExternalStorageDirectory(); File folder; /** * 如果存在SD卡 */ if (DeviceUtil.isSDCardAvailable() && root != null) { folder = new File(root, appName); if (!folder.exists()) { folder.mkdirs(); } } else { /** * 不存在SD卡,就放到緩存文件夾內 */ root = application.getCacheDir(); folder = new File(root, appName); if (!folder.exists()) { folder.mkdirs(); } } if (folderName != null) { folder = new File(folder, folderName); if (!folder.exists()) { folder.mkdirs(); } } return folder.getAbsolutePath(); } /** * 獲得圓角Bitmap * * @param srcBitmap * @param radius * @return */ public static Bitmap getRoundedCornerBitmap(Bitmap srcBitmap, float radius) { Bitmap resultBitmap = Bitmap.createBitmap(srcBitmap.getWidth(), srcBitmap.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(resultBitmap); Paint paint = new Paint(); Rect rect = new Rect(0, 0, srcBitmap.getWidth(), srcBitmap.getHeight()); RectF rectF = new RectF(rect); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(0xBDBDBE); canvas.drawRoundRect(rectF, radius, radius, paint); paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); canvas.drawBitmap(srcBitmap, rect, rect, paint); return resultBitmap; } /** * 圖片解析 * * @param path * @param targetWidth * @param targetHeight * @return */ public static Bitmap decodeScaleImage(String path, int targetWidth, int targetHeight) { BitmapFactory.Options bitmapOptions = getBitmapOptions(path); bitmapOptions.inSampleSize = calculateInSampleSize(bitmapOptions, targetWidth, targetHeight); bitmapOptions.inJustDecodeBounds = false; Bitmap noRotatingBitmap = BitmapFactory.decodeFile(path, bitmapOptions); int degree = readPictureDegree(path); Bitmap rotatingBitmap; if (noRotatingBitmap != null && degree != 0) { rotatingBitmap = rotatingImageView(degree, noRotatingBitmap); noRotatingBitmap.recycle(); return rotatingBitmap; } else { return noRotatingBitmap; } } /** * 獲得縮略圖 * * @param path * @param targetWidth * @return */ public static String getThumbnailImage(String path, int targetWidth) { Bitmap scaleImage = decodeScaleImage(path, targetWidth, targetWidth); try { File file = File.createTempFile("image", ".jpg"); FileOutputStream fileOutputStream = new FileOutputStream(file); scaleImage.compress(Bitmap.CompressFormat.JPEG, 60, fileOutputStream); fileOutputStream.close(); return file.getAbsolutePath(); } catch (Exception e) { e.printStackTrace(); return path; } } /** * 圖片解析 * * @param context * @param resId * @param targetWidth * @param targetHeight * @return */ public static Bitmap decodeScaleImage(Context context, int resId, int targetWidth, int targetHeight) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeResource(context.getResources(), resId, options); options.inSampleSize = calculateInSampleSize(options, targetWidth, targetHeight); options.inJustDecodeBounds = false; Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resId, options); return bitmap; } /** * 計算樣本大小 * * @param options * @param targetWidth * @param targetHeight * @return */ public static int calculateInSampleSize(BitmapFactory.Options options, int targetWidth, int targetHeight) { int height = options.outHeight; int width = options.outWidth; int scale = 1; if (height > targetHeight || width > targetWidth) { int heightScale = Math.round((float) height / (float) targetHeight); int widthScale = Math.round((float) width / (float) targetWidth); scale = heightScale > widthScale ? heightScale : widthScale; } return scale; } /** * 獲得BitmapFactory.Options * * @param pathName * @return */ public static BitmapFactory.Options getBitmapOptions(String pathName) { BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inJustDecodeBounds = true; BitmapFactory.decodeFile(pathName, opts); return opts; } /** * 獲得圖片角度 * * @param filename * @return */ public static int readPictureDegree(String filename) { short degree = 0; try { ExifInterface exifInterface = new ExifInterface(filename); int anInt = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1); switch (anInt) { case ExifInterface.ORIENTATION_ROTATE_180: degree = 180; case ExifInterface.ORIENTATION_FLIP_VERTICAL: case ExifInterface.ORIENTATION_TRANSPOSE: case ExifInterface.ORIENTATION_TRANSVERSE: default: break; case ExifInterface.ORIENTATION_ROTATE_90: degree = 90; break; case ExifInterface.ORIENTATION_ROTATE_270: degree = 270; } } catch (IOException e) { e.printStackTrace(); } return degree; } /** * 旋轉ImageView * * @param degree * @param source * @return */ public static Bitmap rotatingImageView(int degree, Bitmap source) { Matrix matrix = new Matrix(); matrix.postRotate((float) degree); return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true); } /** * 獲得視頻縮略圖 * * @param filePath * @param width * @param height * @param kind * @return */ public static Bitmap getVideoThumbnail(String filePath, int width, int height, int kind) { Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(filePath, kind); bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height, ThumbnailUtils.OPTIONS_RECYCLE_INPUT); return bitmap; } /** * 保存視頻縮略圖 * * @param file * @param width * @param height * @param kind * @return */ public static String saveVideoThumbnail(File file, int width, int height, int kind) { Bitmap videoThumbnail = getVideoThumbnail(file.getAbsolutePath(), width, height, kind); File thumbFile = new File(PathUtil.getInstance().getVideoPath(), "th" + file.getName()); try { thumbFile.createNewFile(); } catch (IOException e) { e.printStackTrace(); } FileOutputStream fileOutputStream = null; try { fileOutputStream = new FileOutputStream(thumbFile); } catch (FileNotFoundException var10) { var10.printStackTrace(); } videoThumbnail.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream); try { fileOutputStream.flush(); } catch (IOException e) { e.printStackTrace(); } try { fileOutputStream.close(); } catch (IOException var8) { var8.printStackTrace(); } return thumbFile.getAbsolutePath(); } /** * Image resource ID was converted into a byte [] data * 圖片資源ID 轉換 為 圖片 byte[] 數據 * * @param context * @param imageResourceId * @return */ public static byte[] toByteArray(Context context, int imageResourceId) { Bitmap bitmap = ImageUtil.toBitmap(context, imageResourceId); if (bitmap != null) { return ImageUtil.toByteArray(bitmap); } else { return null; } } /** * ImageView getDrawable () into a byte [] data * ImageView的getDrawable() 轉換為 byte[] 數據 * * @param imageView * @return */ public static byte[] toByteArray(ImageView imageView) { Bitmap bitmap = ImageUtil.toBitmap(imageView); if (bitmap != null) return ImageUtil.toByteArray(bitmap); else { Log.w(ImageUtil.TAG, "the ImageView imageView content was invalid"); return null; } } /** * byte [] data type conversion for Bitmap data types * byte[]數據類型轉換為 Bitmap數據類型 * * @param imageData * @return */ public static Bitmap toBitmap(byte[] imageData) { if ((imageData != null) && (imageData.length != 0)) { Bitmap bitmap = BitmapFactory.decodeByteArray(imageData, 0, imageData.length); return bitmap; } else { Log.w(ImageUtil.TAG, "the byte[] imageData content was invalid"); return null; } } /** * Image resource ID is converted to Bitmap type data * 資源ID 轉換為 Bitmap類型數據 * * @param context * @param imageResourceId * @return */ public static Bitmap toBitmap(Context context, int imageResourceId) { // 將圖片轉化為位圖 Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), imageResourceId); if (bitmap != null) { return bitmap; } else { Log.w(ImageUtil.TAG, "the int imageResourceId content was invalid"); return null; } } /** * ImageView types into a Bitmap * ImageView類型轉換為Bitmap * * @param imageView * @return */ public static Bitmap toBitmap(ImageView imageView) { if (imageView.getDrawable() != null) { Bitmap bitmap = ImageUtil.toBitmap(imageView.getDrawable()); return bitmap; } else { return null; } } /** * Bitmap type is converted into a image byte [] data * Bitmap類型 轉換 為圖片 byte[] 數據 * * @param bitmap * @return */ public static byte[] toByteArray(Bitmap bitmap) { if (bitmap != null) { int size = bitmap.getWidth() * bitmap.getHeight() * 4; // 創建1個字節數組輸出流,流的大小為size ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream( size); // 設置位圖的緊縮格式,質量為100%,并放入字節數組輸出流中 bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream); // 將字節數組輸出流轉化為字節數組byte[] byte[] imageData = byteArrayOutputStream.toByteArray(); return imageData; } else { Log.w(ImageUtil.TAG, "the Bitmap bitmap content was invalid"); return null; } } /** * Drawable type into a Bitmap * Drawable 類型轉換為 Bitmap類型 * * @param drawable * @return */ public static Bitmap toBitmap(Drawable drawable) { if (drawable != null) { BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable; Bitmap bitmap = bitmapDrawable.getBitmap(); return bitmap; } else { Log.w(ImageUtil.TAG, "the Drawable drawable content was invalid"); return null; } } /** * Bitmap type into a Drawable * Bitmap 類型轉換為 Drawable類型 * * @param bitmap * @return */ public static Drawable toDrawable(Bitmap bitmap) { if (bitmap != null) { Drawable drawable = new BitmapDrawable(bitmap); return drawable; } else { Log.w(ImageUtil.TAG, "the Bitmap bitmap content was invalid"); return null; } } 


生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 在线视频亚洲欧美 | 农村女人的一级毛片 | 久久精品国产亚洲a | 亚洲日本视频 | 国内精品视频在线播放一区 | 欧美日韩一区二区三区免费不卡 | 中国做爰国产精品视频 | 天天做天天爱天天综合网 | 免费一级肉体全黄毛片高清 | 久草视频在线网 | 精品国产片 | 亚洲精品欧美综合 | 图片区小说区激情区偷拍区 | 亚洲精品第一综合99久久 | 一级一级特黄女人精品毛片视频 | haodiaose在线精品免费视频 | 亚洲精品网站在线观看不卡无广告 | 午夜免费视频观看在线播放 | 一区二区三区中文国产亚洲 | 边摸边吃奶边做娇喘视频 | 偷自拍第一页 | 国产产一区二区三区久久毛片国语 | 亚洲精品一区二区三区在线播放 | 欧美性猛交黑人xxxx | 日本xxxx黑人 | 欧美综合精品 | 在线a级| 亚洲国产高清在线精品一区 | 校园 春色 欧美 另类 小说 | 黑人性受xxxx黑人xyx性爽 | 国产精品第1页在线播放 | 欧美日本激情 | 亚洲永久| 国产激情一区二区三区在线观看 | 一级性爱视频 | 亚洲综合站 | 午夜免费体验 | 免费v片在线看 | 久久久久日韩精品免费观看网 | 日本久操 | 国产欧美久久一区二区 |