Bitmap Drawable相互转换
16lz
2021-01-26
drawable,bitmap转换[转载]
2011-04-19 09:47:09|分类: 工作 |标签:android |字号大中小订阅
转载两篇文章,以前自己做东西的时候碰到的问题。 很多朋友表示,不知道Android的Drawable和Bitmap之间如何相关转换。下面eoe给大家两种比较简单高效的方法。 一、Bitmap转Drawable Bitmap bm=xxx; //xxx根据你的情况获取 BitmapDrawable bd=BitmapDrawable(bm); 复制代码 eoe提示因为BtimapDrawable是Drawable的子类,最终直接使用bd对象即可。二、 Drawable转Bitmap
转成Bitmap对象后,可以将Drawable对象通过Android的SK库存成一个字节输出流,最终还可以保存成为jpg和png的文件。
Drawable d=xxx; //xxx根据自己的情况获取drawable BitmapDrawable bd = (BitmapDrawable) d; Bitmap bm = bd.getBitmap();
复制代码 最终bm就是我们需要的Bitmap对象了。 http://www.eoeandroid.com/forum-viewthread-tid-69363-extra-page%3D1%26orderby%3Ddateline.html
如何完全关闭应用程序 之前做东西的时候发现虽然程序退出了,但是可以在eclipse中看到进程还在。不知道其原因,看到一篇文章转载下。 (没试过) 工作过程序中遇到一个需要完全关闭应用程序的问题,每篇都是用System.exit(0)或者android.os.Process.killProcess(android.os.Process.myPid())这两种方法,但是我试过了,System.exit(0)这个根本不行,而android.os.Process.killProcess(android.os.Process.myPid())这个只能关闭当前的Activity,也就是对于一个只有单个Activity 的应用程序有效,如果对于有多外Activity的应用程序它就无能为力了。 下面我介绍一下对于多个Activity的应用程序的完全关闭方法: Java代码: /** * Have the system perform a force stop of everything associated with * the given application package. All processes that share its uid * will be killed, all services it has running stopped, all activities * removed, etc. In addition, a {@link Intent#ACTION_PACKAGE_RESTARTED} * broadcast will be sent, so that any of its registered alarms can * be stopped, notifications removed, etc. * * You must hold the permission * {@link android.Manifest.permission#RESTART_PACKAGES} to be able to * call this method. * * @param packageName The name of the package to be stopped. */
public void restartPackage(String packageName) { try { ActivityManagerNative.getDefault().restartPackage(packageName); } catch (RemoteException e) { } }
所以如果要关闭整个应用程序的话只需要运行以下两行代码就行:
Java代码: ActivityManager activityMgr= (ActivityManager) this.getSystemService(ACTIVITY_SERVICE); activityMgr.restartPackage(getPackageName());
现在我们已经成功到一半了,那么还有一半是什么那,那就是我们老爱忘记的权限,下面看看权限代码:
Java代码: <!-- 关闭应用程序的权限 --> <uses-permission android:name="android.permission.RESTART_PACKAGES" />
更多相关文章
- Android(安卓)---Check System Version at Runtime(在软件运行时
- Android对话框实现
- Android中跨包访问Preferences
- adb and App
- Android(安卓)SDK 实例代码分析---Accelerometer Play(一)
- Android中WebView用法实例分析
- android帐号管理token问题
- Android(安卓)关闭应用程序的6种方法
- Decompiled .class file bytecode version:52.0(java8),Sources f