Android笔记:bitmap转换与处理相关工具类,Bitmap与DrawAble与byte[]与InputStream之间的转换

简介:

1.将view转为bitmap

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// 将view转为bitmap
public  static  Bitmap getBitmapFromView(View view)
{
     // Define a bitmap with the same size as the view
     Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
     // Bind a canvas to it
     Canvas canvas =  new  Canvas(returnedBitmap);
     // Get the view's background
     Drawable bgDrawable = view.getBackground();
     if  (bgDrawable !=  null )
         // has background drawable, then draw it on the canvas
         bgDrawable.draw(canvas);
     else
         // does not have background drawable, then draw white background on
         // the canvas
         canvas.drawColor(Color.WHITE);
     // draw the view on the canvas
     view.draw(canvas);
     // return the bitmap
     return  returnedBitmap;
}



2.将view转为bitmap

1
2
3
4
5
6
7
8
// 将view转为bitmap
public  static  Bitmap viewToBitmap(View view)
{
     view.setDrawingCacheEnabled( true );
     view.buildDrawingCache();
     Bitmap bm = view.getDrawingCache();
     return  bm;
}




3.将xml转为bitmap

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// 将xml转为bitmap
public  static  Bitmap convertBitmapFromXML(Context context, String clusterSize, Bitmap bm)
{
                                                                                                                                                                                                                                                                                                                                                                                        
     View layout = LayoutInflater.from(context).inflate(R.layout.estatecartlist_item,  null );
     View bitmapView = layout.findViewById(R.id.estatecartlist_item_bitmap);
     TextView xml_text = (TextView) layout.findViewById(R.id.item_estatecart_tv_name);
     ImageView image = (ImageView) layout.findViewById(R.id.item_estatecart_iv_main);
     image.setImageBitmap(bm);
     xml_text.setText(clusterSize);
                                                                                                                                                                                                                                                                                                                                                                                        
     bitmapView.measure(MeasureSpec.makeMeasureSpec( 0 , MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec( 0 , MeasureSpec.UNSPECIFIED));
                                                                                                                                                                                                                                                                                                                                                                                        
     bitmapView.layout( 0 0 , bitmapView.getMeasuredWidth(), bitmapView.getMeasuredHeight());
                                                                                                                                                                                                                                                                                                                                                                                        
     final  Bitmap clusterBitmap = Bitmap.createBitmap(bitmapView.getMeasuredWidth(), bitmapView.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
                                                                                                                                                                                                                                                                                                                                                                                        
     Canvas canvas =  new  Canvas(clusterBitmap);
     bitmapView.draw(canvas);
     return  clusterBitmap;
}



==============参考资料===================

* 1.http://stackoverflow.com/questions/7200535/how-to-convert-views-to-bitmap

* 2.http://stackoverflow.com/questions/5536066/convert-view-to-bitmap-on-android/9595919#9595919

* 3.http://stackoverflow.com/questions/12402392/android-converting-xml-view-to-bitmap-without-showing-it






4.图片缩放与压缩

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// 按大小缩放
private  Bitmap getimage(String srcPath)
{
     BitmapFactory.Options newOpts =  new  BitmapFactory.Options();
     // 开始读入图片,此时把options.inJustDecodeBounds 设回true了
     newOpts.inJustDecodeBounds =  true ;
     Bitmap bitmap = BitmapFactory.decodeFile(srcPath, newOpts); // 此时返回bm为空
                                                                                                                                                                                                                                                                                                                                                                               
     newOpts.inJustDecodeBounds =  false ;
     int  w = newOpts.outWidth;
     int  h = newOpts.outHeight;
     // 现在主流手机比较多是800*480分辨率,所以高和宽我们设置为
     float  hh = 800f; // 这里设置高度为800f
     float  ww = 480f; // 这里设置宽度为480f
     // 缩放比。由于是固定比例缩放,只用高或者宽其中一个数据进行计算即可
     int  be =  1 ; // be=1表示不缩放
     if  (w > h && w > ww)
     { // 如果宽度大的话根据宽度固定大小缩放
         be = ( int ) (newOpts.outWidth / ww);
     }
     else  if  (w < h && h > hh)
     { // 如果高度高的话根据宽度固定大小缩放
         be = ( int ) (newOpts.outHeight / hh);
     }
     if  (be <=  0 )
         be =  1 ;
     newOpts.inSampleSize = be; // 设置缩放比例
     // 重新读入图片,注意此时已经把options.inJustDecodeBounds 设回false了
     bitmap = BitmapFactory.decodeFile(srcPath, newOpts);
     return  compressImage(bitmap); // 压缩好比例大小后再进行质量压缩
}
// 图片质量压缩
private  static  Bitmap compressImage(Bitmap image)
{
     ByteArrayOutputStream baos =  new  ByteArrayOutputStream();
     image.compress(Bitmap.CompressFormat.JPEG,  100 , baos); // 质量压缩方法,这里100表示不压缩,把压缩后的数据存放到baos中
     int  options =  100 ;
     while  (baos.toByteArray().length /  1024  100 )
     // 循环判断如果压缩后图片是否大于100kb,大于继续压缩
         baos.reset(); // 重置baos即清空baos
         image.compress(Bitmap.CompressFormat.JPEG, options, baos); // 这里压缩options%,把压缩后的数据存放到baos中
         options -=  10 ; // 每次都减少10
     }
     ByteArrayInputStream isBm =  new  ByteArrayInputStream(baos.toByteArray()); // 把压缩后的数据baos存放到ByteArrayInputStream中
     Bitmap bitmap = BitmapFactory.decodeStream(isBm,  null null ); // 把ByteArrayInputStream数据生成图片
     return  bitmap;
}
// 图片按比例大小压缩
private  static  Bitmap comp(Bitmap image)
{
                                                                                                                                                                                                                                                                                                                                                                               
     ByteArrayOutputStream baos =  new  ByteArrayOutputStream();
     image.compress(Bitmap.CompressFormat.JPEG,  100 , baos);
     if  (baos.toByteArray().length /  1024  1024 )
     { // 判断如果图片大于1M,进行压缩避免在生成图片(BitmapFactory.decodeStream)时溢出
         baos.reset(); // 重置baos即清空baos
         image.compress(Bitmap.CompressFormat.JPEG,  50 , baos); // 这里压缩50%,把压缩后的数据存放到baos中
     }
     ByteArrayInputStream isBm =  new  ByteArrayInputStream(baos.toByteArray());
     BitmapFactory.Options newOpts =  new  BitmapFactory.Options();
     // 开始读入图片,此时把options.inJustDecodeBounds 设回true了
     newOpts.inJustDecodeBounds =  true ;
     Bitmap bitmap = BitmapFactory.decodeStream(isBm,  null , newOpts);
     newOpts.inJustDecodeBounds =  false ;
     int  w = newOpts.outWidth;
     int  h = newOpts.outHeight;
     // 现在主流手机比较多是800*480分辨率,所以高和宽我们设置为
     float  hh = 800f; // 这里设置高度为800f
     float  ww = 480f; // 这里设置宽度为480f
     // 缩放比。由于是固定比例缩放,只用高或者宽其中一个数据进行计算即可
     int  be =  1 ; // be=1表示不缩放
     if  (w > h && w > ww)
     { // 如果宽度大的话根据宽度固定大小缩放
         be = ( int ) (newOpts.outWidth / ww);
     }
     else  if  (w < h && h > hh)
     { // 如果高度高的话根据宽度固定大小缩放
         be = ( int ) (newOpts.outHeight / hh);
     }
     if  (be <=  0 )
         be =  1 ;
     newOpts.inSampleSize = be; // 设置缩放比例
     // 重新读入图片,注意此时已经把options.inJustDecodeBounds 设回false了
     isBm =  new  ByteArrayInputStream(baos.toByteArray());
     bitmap = BitmapFactory.decodeStream(isBm,  null , newOpts);
     return  compressImage(bitmap); // 压缩好比例大小后再进行质量压缩
}




5.图片转为文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// 图片转为文件
public  static  boolean  saveBitmap2file(Bitmap bmp, String filename)
{
     CompressFormat format = Bitmap.CompressFormat.JPEG;
     int  quality =  100 ;
     OutputStream stream =  null ;
     try
     {
         stream =  new  FileOutputStream( "/sdcard/"  + filename);
     }
     catch  (FileNotFoundException e)
     {
         e.printStackTrace();
     }
                                                                                                                                                                                                                                                                                                                                                                      
     return  bmp.compress(format, quality, stream);
}



6.屏幕截屏方法

1
2
3
4
5
6
7
8
9
// 屏幕截屏方法 获取当前屏幕bitmap,转换成bytes[] 调用 UI分享方法
public  void  printscreen_share(View v)
{
     View view1 = getWindow().getDecorView();
     Display display = getWindowManager().getDefaultDisplay();
     view1.layout( 0 0 , display.getWidth(), display.getHeight());
     view1.setDrawingCacheEnabled( true );
     Bitmap bitmap = Bitmap.createBitmap(view1.getDrawingCache());
}



7.把Bitmap 转成 Byte

1
2
3
4
5
6
7
// 把Bitmap 转成 Byte
public  static  byte [] Bitmap2Bytes(Bitmap bm)
{
     ByteArrayOutputStream baos =  new  ByteArrayOutputStream();
     bm.compress(Bitmap.CompressFormat.PNG,  100 , baos);
     return  baos.toByteArray();
}


8.图片转为文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// 图片转为文件
public  static  boolean  saveBitmap2file(Bitmap bmp)
{
     CompressFormat format = Bitmap.CompressFormat.PNG;
     int  quality =  100 ;
     OutputStream stream =  null ;
     try
     {
         // 判断SDcard状态
         if  (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
         {
             // 错误提示
             return  false ;
         }
                                                                                                                                                                                                                                                                                                        
         // 检查SDcard空间
         File SDCardRoot = Environment.getExternalStorageDirectory();
         if  (SDCardRoot.getFreeSpace() <  10000 )
         {
             // 弹出对话框提示用户空间不够
             Log.e( "Utils" "存储空间不够" );
             return  false ;
         }
                                                                                                                                                                                                                                                                                                        
         // 在SDcard创建文件夹及文件
         File bitmapFile =  new  File(SDCardRoot.getPath() + FILE_PATH);
         bitmapFile.getParentFile().mkdirs(); // 创建文件夹
         stream =  new  FileOutputStream(SDCardRoot.getPath() + FILE_PATH); // "/sdcard/"
     }
     catch  (FileNotFoundException e)
     {
         e.printStackTrace();
     }
     return  bmp.compress(format, quality, stream);
}



9.下载图片

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// 下载图片
public  static  Bitmap loadImage(String... params)
{
     InputStream is =  null ;
     Bitmap bitmap =  null ;
     try
     {
         URL url =  new  URL(params[ 0 ]);
         HttpURLConnection conn = (HttpURLConnection) url.openConnection();
         conn.setReadTimeout( 5000 );
         conn.setConnectTimeout( 5000 );
         if  (HttpURLConnection.HTTP_OK != conn.getResponseCode())
         {
             // 网络连接异常
             Log.e( "" "loadImage连接异常" );
             return  null ;
         }
                                                                                                                                                                                                                                                                           
         is = conn.getInputStream();
         bitmap = BitmapFactory.decodeStream(is);
                                                                                                                                                                                                                                                                           
     }
     catch  (MalformedURLException e)
     {
         e.printStackTrace();
     }
     catch  (IOException e)
     {
         e.printStackTrace();
     }
     finally
     {
         if  ( null  != is)
         {
             try
             {
                 is.close();
             }
             catch  (IOException e)
             {
                 e.printStackTrace();
             }
         }
     }
     return  bitmap;
}


10.byte[]转换成Bitmap

1
2
3
4
5
6
7
8
9
// byte[]转换成Bitmap
public  static  Bitmap Bytes2Bitmap( byte [] b)
{
     if  (b.length !=  0 )
     {
         return  BitmapFactory.decodeByteArray(b,  0 , b.length);
     }
     return  null ;
}


11.将字符串转换成Bitmap类型

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public  static  Bitmap stringtoBitmap(String string)
{
     // 将字符串转换成Bitmap类型
     Bitmap bitmap =  null ;
     try
     {
         byte [] bitmapArray;
         bitmapArray = Base64.decode(string, Base64.DEFAULT);
         bitmap = BitmapFactory.decodeByteArray(bitmapArray,  0 , bitmapArray.length);
     }
     catch  (Exception e)
     {
         e.printStackTrace();
     }
                                                                                                                                                                                                                                             
     return  bitmap;
}



12.将Bitmap转换成字符串

1
2
3
4
5
6
7
8
9
10
public  static  String bitmaptoString(Bitmap bitmap)
{
     // 将Bitmap转换成字符串
     String string =  null ;
     ByteArrayOutputStream bStream =  new  ByteArrayOutputStream();
     bitmap.compress(CompressFormat.PNG,  100 , bStream);
     byte [] bytes = bStream.toByteArray();
     string = Base64.encodeToString(bytes, Base64.DEFAULT);
     return  string;
}




13.byte[]转为文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//byte[]转为文件
public  static  File getFileFromBytes( byte [] b)
{
     BufferedOutputStream stream =  null ;
     File file =  null ;
     try
     {
         // 判断SDcard状态
         if  (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()))
         {
             // 错误提示
             return  null ;
         }
                                                                                                                                                                                                                       
         // 检查SDcard空间
         File SDCardRoot = Environment.getExternalStorageDirectory();
         if  (SDCardRoot.getFreeSpace() <  10000 )
         {
             // 弹出对话框提示用户空间不够
             Log.e( "Utils" "存储空间不够" );
             return  null ;
         }
                                                                                                                                                                                                                       
         // 在SDcard创建文件夹及文件
         File bitmapFile =  new  File(SDCardRoot.getPath() + FILE_PATH);
         bitmapFile.getParentFile().mkdirs(); // 创建文件夹
                                                                                                                                                                                                                       
         FileOutputStream fstream =  new  FileOutputStream(bitmapFile);
         stream =  new  BufferedOutputStream(fstream);
         stream.write(b);
     }
     catch  (Exception e)
     {
         e.printStackTrace();
     }
     finally
     {
         if  (stream !=  null )
         {
             try
             {
                 stream.close();
             }
             catch  (IOException e1)
             {
                 e1.printStackTrace();
             }
         }
     }
     return  file;
}




14.图片压缩

1
2
3
4
5
6
7
8
9
10
11
12
13
//图片缩放
public  static  Bitmap scaleDownBitmap(Bitmap photo,  int  newHeight, Context context)
{
                                                                                                                                                                                                        
     final  float  densityMultiplier = context.getResources().getDisplayMetrics().density;
                                                                                                                                                                                                        
     int  h = ( int ) (newHeight * densityMultiplier);
     int  w = ( int ) (h * photo.getWidth() / (( double ) photo.getHeight()));
                                                                                                                                                                                                        
     photo = Bitmap.createScaledBitmap(photo, w, h,  true );
                                                                                                                                                                                                        
     return  photo;
}


15.将byte[]转换成InputStream

1
2
3
4
5
6
// 将byte[]转换成InputStream
public  InputStream Byte2InputStream( byte [] b)
{
     ByteArrayInputStream bais =  new  ByteArrayInputStream(b);
     return  bais;
}



16.将InputStream转换成byte[]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// 将InputStream转换成byte[]
public  byte [] InputStream2Bytes(InputStream is)
{
     String str =  "" ;
     byte [] readByte =  new  byte [ 1024 ];
     int  readCount = - 1 ;
     try
     {
         while  ((readCount = is.read(readByte,  0 1024 )) != - 1 )
         {
             str +=  new  String(readByte).trim();
         }
         return  str.getBytes();
     }
     catch  (Exception e)
     {
         e.printStackTrace();
     }
     return  null ;
}



17.将Bitmap转换成InputStream

1
2
3
4
5
6
7
8
// 将Bitmap转换成InputStream
public  InputStream Bitmap2InputStream(Bitmap bm)
{
     ByteArrayOutputStream baos =  new  ByteArrayOutputStream();
     bm.compress(Bitmap.CompressFormat.JPEG,  100 , baos);
     InputStream is =  new  ByteArrayInputStream(baos.toByteArray());
     return  is;
}



18.将Bitmap转换成InputStream

1
2
3
4
5
6
7
8
// 将Bitmap转换成InputStream
public  InputStream Bitmap2InputStream(Bitmap bm,  int  quality)
{
     ByteArrayOutputStream baos =  new  ByteArrayOutputStream();
     bm.compress(Bitmap.CompressFormat.PNG, quality, baos);
     InputStream is =  new  ByteArrayInputStream(baos.toByteArray());
     return  is;
}



19.将InputStream转换成Bitmap

1
2
3
4
5
// 将InputStream转换成Bitmap
public  Bitmap InputStream2Bitmap(InputStream is)
{
     return  BitmapFactory.decodeStream(is);
}


20.Drawable转换成InputStream

1
2
3
4
5
6
// Drawable转换成InputStream
public  InputStream Drawable2InputStream(Drawable d)
{
     Bitmap bitmap =  this .drawable2Bitmap(d);
     return  this .Bitmap2InputStream(bitmap);
}




21.InputStream转换成Drawable

1
2
3
4
5
6
// InputStream转换成Drawable
public  Drawable InputStream2Drawable(InputStream is)
{
     Bitmap bitmap =  this .InputStream2Bitmap(is);
     return  this .bitmap2Drawable(bitmap);
}


22.Drawable转换成byte[]

1
2
3
4
5
6
// Drawable转换成byte[]
public  byte [] Drawable2Bytes(Drawable d)
{
     Bitmap bitmap =  this .drawable2Bitmap(d);
     return  this .Bitmap2Bytes(bitmap);
}




23.byte[]转换成Drawable

1
2
3
4
5
6
// byte[]转换成Drawable
public  Drawable Bytes2Drawable( byte [] b)
{
     Bitmap bitmap =  this .Bytes2Bitmap(b);
     return  this .bitmap2Drawable(bitmap);
}



24.Drawable转换成Bitmap

1
2
3
4
5
6
7
8
9
10
// Drawable转换成Bitmap
public  Bitmap drawable2Bitmap(Drawable drawable)
{
     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;
}



25.Bitmap转换成Drawable

1
2
3
4
5
6
7
// Bitmap转换成Drawable
public  Drawable bitmap2Drawable(Bitmap bitmap)
{
     BitmapDrawable bd =  new  BitmapDrawable(bitmap);
     Drawable d = (Drawable) bd;
     return  d;
}






本文转自 glblong 51CTO博客,原文链接:http://blog.51cto.com/glblong/1304090,如需转载请自行联系原作者

目录
相关文章
|
22天前
|
XML 前端开发 Android开发
Android:UI:Drawable:View/ImageView与Drawable
通过本文的介绍,我们详细探讨了Android中Drawable、View和ImageView的使用方法及其相互关系。Drawable作为图像和图形的抽象表示,提供了丰富的子类和自定义能力,使得开发者能够灵活地实现各种UI效果。View和ImageView则通过使用Drawable实现了各种图像和图形的显示需求。希望本文能为您在Android开发中使用Drawable提供有价值的参考和指导。
34 2
|
2月前
|
Web App开发 安全 程序员
FFmpeg开发笔记(五十五)寒冬里的安卓程序员可进阶修炼的几种姿势
多年的互联网寒冬在今年尤为凛冽,坚守安卓开发愈发不易。面对是否转行或学习新技术的迷茫,安卓程序员可从三个方向进阶:1)钻研谷歌新技术,如Kotlin、Flutter、Jetpack等;2)拓展新功能应用,掌握Socket、OpenGL、WebRTC等专业领域技能;3)结合其他行业,如汽车、游戏、安全等,拓宽职业道路。这三个方向各有学习难度和保饭碗指数,助你在安卓开发领域持续成长。
81 1
FFmpeg开发笔记(五十五)寒冬里的安卓程序员可进阶修炼的几种姿势
|
3月前
|
存储 缓存 编解码
Android经典面试题之图片Bitmap怎么做优化
本文介绍了图片相关的内存优化方法,包括分辨率适配、图片压缩与缓存。文中详细讲解了如何根据不同分辨率放置图片资源,避免图片拉伸变形;并通过示例代码展示了使用`BitmapFactory.Options`进行图片压缩的具体步骤。此外,还介绍了Glide等第三方库如何利用LRU算法实现高效图片缓存。
71 20
Android经典面试题之图片Bitmap怎么做优化
|
2月前
|
Linux API 开发工具
FFmpeg开发笔记(五十九)Linux编译ijkplayer的Android平台so库
ijkplayer是由B站研发的移动端播放器,基于FFmpeg 3.4,支持Android和iOS。其源码托管于GitHub,截至2024年9月15日,获得了3.24万星标和0.81万分支,尽管已停止更新6年。本文档介绍了如何在Linux环境下编译ijkplayer的so库,以便在较新的开发环境中使用。首先需安装编译工具并调整/tmp分区大小,接着下载并安装Android SDK和NDK,最后下载ijkplayer源码并编译。详细步骤包括环境准备、工具安装及库编译等。更多FFmpeg开发知识可参考相关书籍。
106 0
FFmpeg开发笔记(五十九)Linux编译ijkplayer的Android平台so库
|
4月前
|
JavaScript 前端开发 Java
FFmpeg开发笔记(四十七)寒冬下安卓程序员的几个技术转型发展方向
IT寒冬使APP开发门槛提升,安卓程序员需转型。选项包括:深化Android开发,跟进Google新技术如Kotlin、Jetpack、Flutter及Compose;研究Android底层框架,掌握AOSP;转型Java后端开发,学习Spring Boot等框架;拓展大前端技能,掌握JavaScript、Node.js、Vue.js及特定框架如微信小程序、HarmonyOS;或转向C/C++底层开发,通过音视频项目如FFmpeg积累经验。每条路径都有相应的书籍和技术栈推荐,助你顺利过渡。
114 3
FFmpeg开发笔记(四十七)寒冬下安卓程序员的几个技术转型发展方向
|
4月前
|
编解码 安全 Ubuntu
Android Selinux 问题处理笔记
这篇文章是关于处理Android系统中SELinux权限问题的笔记,介绍了如何通过分析SELinux拒绝的日志、修改SELinux策略文件,并重新编译部署来解决权限问题,同时提供了一些SELinux的背景知识和实用工具。
101 0
|
4月前
|
XML Android开发 数据格式
"探秘Android Drawable魔法:一篇文章教你玩转StateListDrawable与AnimationDrawable!"
【8月更文挑战第18天】Drawable是Android中用于屏幕绘制的图形对象,StateListDrawable与AnimationDrawable是两种实用类型。StateListDrawable可根据控件状态变化显示不同图形,如按钮的点击反馈;AnimationDrawable则用于实现帧动画效果,常用于加载提示或动态图标。两者均可通过XML定义或代码创建,并轻松应用于View的背景中,有效增强应用的交互性和视觉体验。
63 0
|
6月前
|
存储 Java Android开发
Android上在两个Activity之间传递Bitmap对象
Android上在两个Activity之间传递Bitmap对象
44 2
|
6月前
|
XML API 开发工具
Android Bitmap 加载与像素操作
Android Bitmap 加载与像素操作
51 2
|
6月前
|
XML 前端开发 API
Android中实现Bitmap在自定义View中的放大与拖动
Android中实现Bitmap在自定义View中的放大与拖动
154 1