- 浏览: 486548 次
- 性别:
- 来自: 北京
-
最新评论
-
fatalfeel:
Irrlicht 3d Engine is full open ...
转:Android世界的15款开源的游戏开发引擎 -
diyangxia:
BigDecimal怎么初始化全局变量呢
android如何保留小数点后x位数字 -
c1230v:
这是一个程序员应该用的方法吗?求靠谱一点
转:android WebView 控件加载本地sdcard中html文件图片的问题 -
dingbuoyi:
楼主是天才 真牛逼
转:Progressbar-设置自己的样式 -
panxiaoming2008:
记住:显示本地文件时 必须使用APK'>file:/// ...
Android使用WebView加载本地资源
原文地址:http://www.androidmi.com/Androidkaifa/jinjie/201011/1788.html
作者的联系方式:
QQ:524509159
Email:hoohbood@gmail.com
Tel:18666294230
大家好,这一节给大家分享的是Android中几种图像特效处理的小技巧,比如圆角,倒影,还有就是图片缩放,Drawable转化为Bitmap,Bitmap转化为Drawable等等.
废话少说了,直接讲解今天的实例,本例主要是先获取壁纸(getWallpaper()),然后对当前壁纸的一些特效处理.大家按步骤一步一步来:
第一步:新建一个Android工程命名为ImageDemo,工程结构如下:
第二步:新建一个.java文件,命名为ImageUtil.java,在里面定义一些图片处理方法,代码如下:
package com.android.tutor; 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 ImageUtil { //放大缩小图片 public static Bitmap zoomBitmap(Bitmap bitmap,int w,int h){ int width = bitmap.getWidth(); int height = bitmap.getHeight(); Matrix matrix = new Matrix(); float scaleWidht = ((float)w / width); float scaleHeight = ((float)h / height); matrix.postScale(scaleWidht, scaleHeight); Bitmap newbmp = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true); return newbmp; } //将Drawable转化为Bitmap public static Bitmap drawableToBitmap(Drawable drawable){ int width = drawable.getIntrinsicWidth(); 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; } //获得圆角图片的方法 public static Bitmap getRoundedCornerBitmap(Bitmap bitmap,float roundPx){ Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap .getHeight(), Config.ARGB_8888); Canvas canvas = new Canvas(output); final int color = 0xff424242; final Paint paint = new Paint(); final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); final RectF rectF = new RectF(rect); paint.setAntiAlias(true); canvas.drawARGB(0, 0, 0, 0); paint.setColor(color); canvas.drawRoundRect(rectF, roundPx, roundPx, paint); paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN)); canvas.drawBitmap(bitmap, rect, rect, paint); return output; } //获得带倒影的图片方法 public static Bitmap createReflectionImageWithOrigin(Bitmap bitmap){ final int reflectionGap = 4; int width = bitmap.getWidth(); int height = bitmap.getHeight(); Matrix matrix = new Matrix(); matrix.preScale(1, -1); Bitmap reflectionImage = Bitmap.createBitmap(bitmap, 0, height/2, width, height/2, matrix, false); Bitmap bitmapWithReflection = Bitmap.createBitmap(width, (height + height/2), Config.ARGB_8888); Canvas canvas = new Canvas(bitmapWithReflection); canvas.drawBitmap(bitmap, 0, 0, null); Paint deafalutPaint = new Paint(); canvas.drawRect(0, height,width,height + reflectionGap, deafalutPaint); canvas.drawBitmap(reflectionImage, 0, height + reflectionGap, null); Paint paint = new Paint(); LinearGradient shader = new LinearGradient(0, bitmap.getHeight(), 0, bitmapWithReflection.getHeight() + reflectionGap, 0x70ffffff, 0x00ffffff, TileMode.CLAMP); paint.setShader(shader); // Set the Transfer mode to be porter duff and destination in paint.setXfermode(new PorterDuffXfermode(Mode.DST_IN)); // Draw a rectangle using the paint with our linear gradient canvas.drawRect(0, height, width, bitmapWithReflection.getHeight() + reflectionGap, paint); return bitmapWithReflection; } }
第三步:修改main.xml布局文件,主要放了两个ImageView控件,代码如下:
<?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/image01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10px" /> <ImageView android:id="@+id/image02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10px" /> </LinearLayout> <?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/image01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10px" /> <ImageView android:id="@+id/image02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10px" /> </LinearLayout>
第四步:修改主核心程序,ImageDemo.java,代码如下:
package com.android.tutor; import android.app.Activity; import android.graphics.Bitmap; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.widget.ImageView; public class Imagedemo extends Activity { private ImageView mImageView01,mImageView02; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); setupViews(); } private void setupViews(){ mImageView01 = (ImageView)findViewById(R.id.image01); mImageView02 = (ImageView)findViewById(R.id.image02); //获取壁纸返回值是Drawable Drawable drawable = getWallpaper(); //将Drawable转化为Bitmap Bitmap bitmap = ImageUtil.drawableToBitmap(drawable); //缩放图片 Bitmap zoomBitmap = ImageUtil.zoomBitmap(bitmap, 100, 100); //获取圆角图片 Bitmap roundBitmap = ImageUtil.getRoundedCornerBitmap(zoomBitmap, 10.0f); //获取倒影图片 Bitmap reflectBitmap = ImageUtil.createReflectionImageWithOrigin(zoomBitmap); //这里可以让Bitmap再转化为Drawable // Drawable roundDrawable = new BitmapDrawable(roundBitmap); // Drawable reflectDrawable = new BitmapDrawable(reflectBitmap); // mImageView01.setBackgroundDrawable(roundDrawable); // mImageView02.setBackgroundDrawable(reflectDrawable); mImageView01.setImageBitmap(roundBitmap); mImageView02.setImageBitmap(reflectBitmap); } }
第五步:运行上述工程,查看效果如下:
OK大功告成了!!
发表评论
-
service学习
2012-05-16 00:41 903http://www.cnblogs. ... -
InputStream,String,File相互转化
2012-05-14 23:32 12901. String --> InputStream ... -
转:实现类似手机QQ的可折叠固定标题列表
2012-04-12 19:05 1406http://douzifly.cnblog ... -
转:[Android]倒影效果的ImagView
2012-04-06 23:29 1403本文源自:http://blog.csdn.net/ke ... -
转:JDK中的URLConnection参数详解
2012-04-06 23:01 1192针对JDK中的URLConnection连 ... -
转:Game Engines for Android (Android游戏引擎)
2012-03-24 13:12 2741With Google IO fast approach ... -
做Android 系统/应用开发怎么可以不懂自动化测试
2012-03-22 15:02 1168http://blog.csdn.net/yiyaaixuex ... -
让Qt应用程序跑在Android上
2012-03-22 14:55 1383http://blog.c ... -
转:在android 2.3 AVD 模拟器上安装 google market 安卓市场
2012-03-22 14:29 1097http:// ... -
增加 addDataScheme("file") 才能收到SD卡插拔事件的原因分析 -- 浅析android事件过滤策略
2012-03-22 14:26 1985... -
转:andengine中的ParticleSystem
2012-01-18 11:08 1546看ParticleSystemSimpleExample,看得 ... -
test4:腾讯
2011-12-26 20:27 2www.qq.com -
test3:Yahoo
2011-12-26 20:25 2www.yahoo.com -
test2:google
2011-12-26 10:53 5www.google.com.hk -
test1:百度
2011-12-26 10:52 6www.baidu.com -
转:android 打包自己的自定义组件成JAR包
2011-12-24 11:54 1288http://www.cnblogs.c ... -
转:AndEngine中的字体加载及应用
2011-12-15 15:39 1564AndEngine中的字体加载及应用 An ... -
转:Android游戏框架AndEngine使用入门
2011-12-13 14:24 1595项目站点:http://www.andengine.org 项 ... -
转:notification更新数字的显示及AnimationDrawable的结合使用
2011-12-07 10:25 2639这是本人加入博客园的首篇博文,自己平常在工作学习过程遇 ... -
转:Android系统上(mv不可用)cp命令的替代方法
2011-11-30 18:32 9686Android系统上cp命令 ...
相关推荐
在Android开发中,图片色彩特效处理是一个非常重要的领域,它涉及到图像处理算法和Android系统提供的图像API。这个"android中图片色彩特效处理Demo"旨在帮助开发者理解如何改变图片的色调、饱和度和亮度,从而创建出...
在安卓(Android)平台上,开发图像处理应用时,经常会涉及到各种图片特效的实现。这个压缩包"安卓Android源码——常用图片特效处理.rar"显然包含了用于处理图片特效的源代码,可以帮助开发者理解和学习如何在...
首先,我们要明白Android中的图像处理涉及到的主要技术领域包括位图操作、色彩空间转换、滤镜应用以及图形渲染等。这些技术通常用于创建如模糊、旋转、裁剪、缩放、色彩调整、滤镜特效等常见功能。 1. **位图操作**...
这个“Android图片特效处理Demo”旨在提供一系列预设的图像处理效果,包括负片、锐化、旋转、浅色、光照、鱼眼和纹理等。接下来,我们将深入探讨这些特效以及实现它们的技术和工具。 1. **负片效果**:这是一种常见...
在Android开发中,图片特效处理是一项重要的技能,它涉及到用户界面的设计、用户体验的提升以及应用程序的性能优化。这个“android常用图片特效处理_Android.rar”压缩包可能包含了多个与Android平台图片处理相关的...
在Android平台上,图像处理和特效的应用是开发过程中一个有趣且具有挑战性的部分。"Android 图像连环画特效源码.zip"是一个专为Android开发者设计的资源,它提供了实现图像连环画特效的源代码。这个压缩包包含了实现...
研究这个源码,开发者可以学习如何在Android中实现复杂的图像处理特效,并将其应用到自己的项目中。 总的来说,"Android源码——图像连环画特效源码_new_38.zip"是一个宝贵的教育资源,它涵盖了Android图像处理的...
冰冻特效在移动应用中通常涉及到帧动画和实时图像处理,这两个主题在Android开发中占据了重要位置。帧动画是指通过连续播放一系列静态图片来创建动态效果,而实时图像处理则涉及到对摄像头捕获或存储在设备中的图像...
在Android平台上,图像处理技术是移动应用开发中的一个重要组成部分,特别是在游戏、图像编辑或视觉效果相关的应用程序中。"Android 图像冰冻特效源码.rar"是一个压缩包,包含了一个实现特定图像冰冻特效的源代码...
在Android开发中,创建独特的用户体验往往需要利用各种视觉特效,其中一种吸引人的特效就是图片的中轴旋转。本文将深入探讨如何在Android中实现轴旋转特效,以制作一个别样的图片浏览器。 首先,我们需要理解“中轴...
在Android平台上,开发移动应用图像处理功能是一项常见的任务,尤其是对于照片编辑类应用而言,图像柔化和美白特效是必不可少的。本知识点将深入探讨如何使用Android SDK和相关的开源库来实现这一效果。 首先,我们...
在Android开发中,图像处理和特效的实现是一个重要的部分,特别是在创建吸引用户的UI或游戏时。这个"Android图像连环画特效源码"提供了一种将普通图片转换为具有连环画风格效果的方法,这对于创建独特的用户体验或者...
首先,连环画特效通常涉及到图像处理技术,这在Android中可以通过使用Java或者Kotlin语言,配合Android的图像库,如Bitmap和Canvas来实现。Bitmap是Android中的基本图像处理类,它可以加载、创建和操作图像。Canvas...
《Android100种图片处理效果大全项目》是一款专注于Android平台上的图像处理示例集合,提供了丰富的图片操作功能。这个项目旨在帮助开发者深入理解和实践Android系统中的图像处理技术,包括但不限于滤镜效果、裁剪、...
在Android开发中,为了提升用户体验,尤其是在处理大量数据或者网络请求时,我们常常会使用“加载数据等待特效”(Loading Effects)来展示一个过渡状态,让用户知道应用正在后台忙碌并即将呈现所需内容。这种特效...
在Android开发中,手势识别是实现用户交互的关键技术之一,特别是在图像处理方面。"android手势处理图片平移、缩放和旋转"这个主题涉及到的主要知识点包括Android手势检测、ImageView的扩展以及图片操作。 首先,...
9. **实时滤镜和图像处理**:在图片应用或相机功能中,实时滤镜和图像处理特效是不可或缺的。源码可能涉及到OpenGL ES或renderscript的使用,实现图片的实时美颜、滤镜应用等功能。 10. **加载和空状态提示**:在...
使用OpenGL ES或RenderScript,可以将图像处理任务转移到GPU,提高处理速度,尤其适用于复杂的图像特效。 10. 图片选择器: 开发中,经常需要实现图片选择功能,可以集成像Android-Universal-Image-Loader这样的...
接着,在对应的C/C++代码中,需要定义这个方法,读取Bitmap数据,执行图像处理操作,最后更新Bitmap内容。 在IBMPhotoPhun这个示例中,可能包含了实现这些图像处理操作的源代码文件,如`imageprocessing.cpp`和相应...