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. 实战经验:MySQL 构建高并发网站性能优化
  2. python导入数据画多列直方图_在python datafram中使用两列(值、计数)绘制直方图...
  3. 非洲儿童(南阳oj1036)(馋)
  4. 如何禁止使用bottomsheetdialogfragment拖动?
  5. bootstrap 黑边框表格样式_Excel表格如何添加绘制边框?
  6. ExtJS Panel主要配置列表
  7. gittrack_Git 追踪分支
  8. 软件外包相关职业规划
  9. java统计空格代码_java算法大全之统计出其中英文字母、空格、数字和其它字符的个数...
  10. Mac OS用Anaconda安装Jupyter Notebook
  11. webUploader大文件断点续传学习心得 多文件
  12. iconv字符编码转换
  13. C#微信公众号与订阅号接口开发示例代码
  14. ui文件转换为py文件方法
  15. Win11 连接不上NAS
  16. android 官方ui库,腾讯出品的一个超棒的 Android UI 库
  17. 原创教程:下载和安装“图形化积木Python编程”海龟编辑器
  18. win10子系统ubuntu18安装到其他盘
  19. PyCharm 中的 ___jb_bak___ 和 ___jb_old___ 文件的处理方法
  20. Visual Studio Code(VSCODE)修改字体、字号

热门文章

  1. Spring in Action 入门之面向切面编程AOP
  2. 推荐两个Firefox插件
  3. XHTML基础问答-给初学者
  4. 在用数据绑定的时候我为什么不能把焦点移出(Tab out)我的控件?(译)
  5. HDU3338 Kakuro Extension(最大流+思维构图)
  6. Nginx配置反向代理与负载均衡
  7. IE浏览器上传文件时本地路径变成”C:\fakepath\”的问题
  8. 现在不坚持,以后都会放弃
  9. 编写多线程Java应用程序常见问题
  10. 北海市卫生学校计算机教室,北海卫校2021年招生简章_北海市卫生学校