当前位置:首页 > 开发 > 移动开发 > 正文

Android 图像处理(类型转换,比例缩放,倒影,圆角)

发表于: 2011-07-11   作者:clf_dragon   来源:转载   浏览次数:
摘要: 引用 http://www.cnblogs.com/zhengtao/articles/1930802.htm //放大缩小图片 public static Bitmap zoomBitmap(Bitmap bitmap,int w,int h){ int width = bitmap.getWidth(); int height = bitm
引用
http://www.cnblogs.com/zhengtao/articles/1930802.htm

//放大缩小图片

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;
}

Android 图像处理(类型转换,比例缩放,倒影,圆角)

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

编辑推荐
主要包含了 放大缩小 圆角图片 和 倒影 Java代码 package com.lp.imageUI; <li style="font-size
效果图: [img] [/img] 这里需要的图片是手机壁纸 main.xml <?xml version="1.0" encoding="utf-8
大家好,这一节给大家分享的是Android中几种图像特效处理的小技巧,比如圆角,倒影,还有就是图片缩放,D
2011.10.19(2)——— android 圆角与倒影 我只是把代码下了,忘了在呢看到了,对不住作者了 主要包
2011.10.19(2)——— android 圆角与倒影 我只是把代码下了,忘了在呢看到了,对不住作者了 主要包
前面发过一篇如何利用Matrix来旋转图像,那么如何来缩放图像呢?其实旋转和缩放一样,不同的是需要
绘制图形时,通过绘制相交的部分来实现,不多说,看代码: public static Bitmap getRoundedCornerB
好啦,在这里我要介绍图像的缩放啦 图像比例缩放是指将给定的图像在x轴方向按比例缩放,在y轴方向也
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http
一下是引自别人的文章 http://ysl-paradise.blogspot.com/2009/12/ii.html 废话不多说 private void
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号