Android --- 图片处理的方法

转换 -  drawable To  bitmap

缩放 -  Zoom

圆角 -  Round Corner

倒影 -  Reflected


bitmapPrcess  code:

package com.learn.games; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.LinearGradient; import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.PixelFormat; import android.graphics.PorterDuffXfermode; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.Bitmap.Config; import android.graphics.PorterDuff.Mode; import android.graphics.Shader.TileMode; import android.graphics.drawable.Drawable; public class bitmapProcess { // zoom public static Bitmap zoomBitmap(Bitmap bitmap, int w, int h){ int width = bitmap.getWidth(); int height = bitmap.getHeight(); Matrix matrix = new Matrix(); float scaleWidth = w/(float)width; float scaleHeight = h/(float)height; matrix.postScale(scaleWidth, scaleHeight); Bitmap bitmap2 = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); return bitmap2; } // drawable to bitmap public static Bitmap drawable2Bitmap(Drawable drawable){ int width = drawable.getIntrinsicHeight(); int height = drawable.getIntrinsicHeight(); Bitmap bitmap = Bitmap.createBitmap(width, height, drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565); Canvas canvas = new Canvas(bitmap); drawable.setBounds(0, 0, width, height); drawable.draw(canvas); return bitmap; } // Round Corner Bitmap public static Bitmap getRoundCornerBitmap(Bitmap bitmap, float roundPX){ int width = bitmap.getWidth(); int height = bitmap.getHeight(); Bitmap bitmap2 = Bitmap.createBitmap(width, height, Config.ARGB_8888); Canvas canvas = new Canvas(bitmap2); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, width, height); final RectF rectF = new RectF(rect); paint.setColor(color); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); canvas.drawRoundRect(rectF, roundPX, roundPX, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return bitmap2; } // Reflect Bitmap public static Bitmap createReflectedBitmap(Bitmap bitmap){ final int reflectedGap = 4; int width = bitmap.getWidth(); int height = bitmap.getHeight(); Matrix matrix = new Matrix(); matrix.preScale(1, -1); Bitmap reflectedImage = Bitmap.createBitmap(bitmap, 0, height/2, width, height/2, matrix, false); Bitmap reflectedBitmap = Bitmap.createBitmap(width, (height + height/2), Config.ARGB_8888); Canvas canvas = new Canvas(reflectedBitmap); canvas.drawBitmap(bitmap, 0, 0, null); Paint defaultPaint = new Paint(); canvas.drawRect(0, height, width, height + reflectedGap, defaultPaint); canvas.drawBitmap(reflectedImage, 0, height + reflectedGap, null); Paint paint = new Paint(); LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0, reflectedBitmap.getHeight() + reflectedGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP); paint.setShader(shader); paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); canvas.drawRect(0, height, width, reflectedBitmap.getHeight() + reflectedGap, paint); return reflectedBitmap; } }

Java Code:

package com.learn.games; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.widget.ImageView; public class MyBitmapProcessActivity extends Activity { private ImageView imgView1; private ImageView imgView2; private ImageView imgView3; private ImageView imgView4; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); drawBitmap(); } private void drawBitmap(){ imgView1 = (ImageView)findViewById(R.id.imgView1); imgView2 = (ImageView)findViewById(R.id.imgView2); imgView3 = (ImageView)findViewById(R.id.imgView3); imgView4 = (ImageView)findViewById(R.id.imgView4); Drawable drawable = this.getWallpaper(); Bitmap bitmap = bitmapProcess.drawable2Bitmap(drawable); // drawable to bitmap Bitmap zoomBitmap = bitmapProcess.zoomBitmap(bitmap, 100, 100); // zoom Bitmap roundBitmap = bitmapProcess.getRoundCornerBitmap(zoomBitmap, 10.0f); // round corner Bitmap reflectedBitmap = bitmapProcess.createReflectedBitmap(zoomBitmap); // reflect bitmap // drawable to bitmap imgView1.setImageBitmap(bitmap); imgView2.setImageBitmap(zoomBitmap); imgView3.setImageBitmap(roundBitmap); imgView4.setImageBitmap(reflectedBitmap); // bitmap to drawable Drawable roundDrawable = new BitmapDrawable(roundBitmap); Drawable reflectedDrawable = new BitmapDrawable(reflectedBitmap); imgView1.setBackgroundDrawable(roundDrawable); imgView2.setBackgroundDrawable(reflectedDrawable); } }

XML:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ImageView android:id="@+id/imgView1" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <ImageView android:id="@+id/imgView2" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <ImageView android:id="@+id/imgView3" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <ImageView android:id="@+id/imgView4" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout>
效果图:

drawable2bitmap

zoom

round corner

reflected bitmap

转载于:https://www.cnblogs.com/wdpp/archive/2011/08/23/2386751.html

Android --- 图片的特效处理相关推荐

  1. Android 图片切换特效 AndroidImageSlider

    ※ 效果 ※简介 一款很实用的用于制作幻灯片的组件,动画效果很好,可直接加载本地图片和网络图片. ※代码 常用的几个方法,项目有更详细的注释 ※注意事项 1.如果你从网络加载图片,需要添加下面两个权限 ...

  2. Android开发笔记(九十七)图片的特效处理

    图片特效用到的函数 本文讲述的图片特效处理包括:怀旧.光照.光晕.底片.浮雕.模糊.锐化.黑白.冰冻.素描,所有这些特效都是基于一定的算法,对图像每个点的RGB值进行计算,并汇总所有点的计算结果生成新 ...

  3. android 背景磨砂效果,跨浏览器磨砂效果背景图片模糊特效

    background-blur是一款非常炫酷的跨浏览器磨砂效果背景图片模糊特效jQuery插件.它会抽取图片的主要色彩,并通过SVG过滤器来制作模糊效果.并且它还通过velocity.js来提供额外的 ...

  4. Android图片特效处理(像素处理)

    这篇博客将会通过对像素的RGB分量做一个处理,然后达到一些特效.并没有很高端大气的代码.也没用使用ImageFilter等一些库.多数参考了别人,大神勿喷. 首先看一下今天的效果图. 由于上传大小限制 ...

  5. Android 图片处理工具类汇总

    很有用的Android图片处理工具,实现各种图片处理效果 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 ...

  6. android图片处理方法(不断收集中)

    //压缩图片大小 public static Bitmap compressImage(Bitmap image) { ByteArrayOutputStream baos = new ByteArr ...

  7. Android仿直播特效之刷礼物

    一.概述 继续咱们的直播之旅,过段时间再把推流拉流写上博客,暂时还是UI特效,先上图 二.创建我们的BaseActivity和BaseFrag /*** @author 刘洋巴金* @date 201 ...

  8. 基于Threejs的jQuery 3d图片旋转木马特效插件

    这是一款基于ThreeJS的炫酷3D旋转木马图片画廊特效插件.该旋转木马特效可以设置图片预加载,带有前后导航按钮,可以使用鼠标前后旋转,并可以设置3D透视的位置. 浏览器兼容: Firefox - 3 ...

  9. Android实现雪花特效自定义view

    一.前言 这个冬天,老家一直没有下雨, 正好圣诞节,就想着制作一个下雪的特效. 圣诞祝福:平安夜,舞翩阡.雪花飘,飞满天.心与心,永相伴. 圣诞节是传统的宗教节日,对于基 督徒,那是庆祝耶稣的诞生,纪 ...

最新文章

  1. Codeforces 900D Unusual Sequences:记忆化搜索
  2. 15-07-08 数组-- 手机号抽奖、福利彩票随机生成
  3. Android Drawable 转化成 Bitmap
  4. 几则常用的BASIS技巧整理
  5. 洛谷 1351 联合权值——树形dp
  6. JDK库rt包中常用包说明
  7. 那些被.NET大厂拒绝的大佬们,究竟弱在哪里?
  8. c语言高斯白序列x,C语言程序设计程设计指导书(晓庄).doc
  9. 车载导航系统中常用物理量和单位
  10. java+getactionmap_Struts2 使用OGNL遍历map方法详解
  11. phabricator客户端使用(windows)
  12. 网络管理软件,这个市场肉很多
  13. 车牌字符识别算法原理
  14. 哲理故事三百篇[转]
  15. 名称数据联网简介的翻译(计算机网络论文翻译)
  16. android 获取快捷开关_6款快捷开关式实用安卓小插件推荐 简化Android设备操作
  17. 在虚拟机VirtualBox上安装苹果Mac OS X系统
  18. proftpd mysql_使用MySQL认证ProFTPD用户
  19. 洛谷 P1039 侦探推理 题解
  20. 2021-08-05SpringCloud升级之路2020.0.x版-5.所有项目的parent与spring-framework-common说明

热门文章

  1. 分布式系统用户登录路由
  2. Apache2 httpd.conf 配置详解(一)
  3. spring基础系列--JavaConfig配置
  4. spring和mybatis整合进行事务管理
  5. 一般处理程序使用Session报错(未将对象引用设置到对象实例)
  6. SharePoint 2007 Backup Strategies
  7. C语言-typedef与#define的区别
  8. 【Android 逆向】Android 逆向通用工具开发 ( Android 逆向通用工具组成部分 | 各模块间的关联 )
  9. 【Android 安装包优化】Android 中使用 SVG 图片 ( Android 5.0 以下的矢量图方案 | 矢量图生成为 PNG 图片 )
  10. 【RecyclerView】 六、RecyclerView.ItemDecoration 条目装饰 ( 简介 | onDraw | onDrawOver | getItemOffsets )