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

Android 图像处理(类型转换,比例缩放,倒影,圆角)的小例子,第1张

概述1.放大缩小图片复制代码代码如下:publicstaticBitmapzoomBitmap(Bitmapbitmap,intw,inth){          intwidth=bitmap.getWidth();    &nbs

1.放大缩小图片

复制代码 代码如下:
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,wIDth,height,matrix,true);   
        return newbmp;   
    }


2.获得圆角图片的方法

复制代码 代码如下:
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,bitmap.getWIDth(),bitmap.getHeight());   
        final RectF rectF = new RectF(rect);   

        paint.setAntiAlias(true);   
        canvas.drawARGB(0,0);   
        paint.setcolor(color);   
        canvas.drawRoundRect(rectF,roundPx,paint);   

        paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));   
        canvas.drawBitmap(bitmap,rect,paint);   

        return output;   
    }


3.获得带倒影的图片方法

复制代码 代码如下:
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,height/2,false);   

       Bitmap bitmapWithreflection = Bitmap.createBitmap(wIDth,(height + height/2),Config.ARGB_8888);   

       Canvas canvas = new Canvas(bitmapWithreflection);   
       canvas.drawBitmap(bitmap,null);   
       Paint deafalutPaint = new Paint();   
       canvas.drawRect(0,height + reflectionGap,deafalutPaint);   

       canvas.drawBitmap(reflectionImage,null);   

       Paint paint = new Paint();   
       linearGradIEnt shader = new linearGradIEnt(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,bitmapWithreflection.getHeight()   
                + reflectionGap,paint);   

        return bitmapWithreflection;   
    }

4.将Drawable转化为Bitmap

复制代码 代码如下:
public static Bitmap drawabletoBitmap(Drawable drawable){
      int wIDth = drawable.getIntrinsicWIDth();
      int height = drawable.getIntrinsicHeight();
      Bitmap bitmap = Bitmap.createBitmap(wIDth,
      drawable.getopacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888: Bitmap.Config.RGB_565);
      Canvas canvas = new Canvas(bitmap);
      drawable.setBounds(0,height);
      drawable.draw(canvas);
      return bitmap;
}

总结

以上是内存溢出为你收集整理的Android 图像处理(类型转换,比例缩放,倒影,圆角)的小例子全部内容,希望文章能够帮你解决Android 图像处理(类型转换,比例缩放,倒影,圆角)的小例子所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1142546.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存