Android Rounded Bitmap没有ANTI-ALIASED,也没有过滤。带有像素化边距的结果图像(提供截图)

时间:2015-02-21 21:43:17

标签: java android canvas bitmap

我正在创建一个应用程序,在功能之间,它从Facebook通过URL获取图像,通过Bitmap解码,然后将圆形图圆圈化,并将其放入imageView。

问题是它继续像素化,如下所示:

enter image description here

这是我的代码:

imageView的布局:

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="56dp">

    <ImageView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:id="@+id/imageView_signUpConfirmedEditProfileLayout_profilePictureHolder"
        android:layout_centerInParent="true"
        android:src="@drawable/plus_lg"/>

    <ImageView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:id="@+id/imageView_signUpConfirmedEditProfileLayout_profilePicture"
        android:visibility="invisible"
        android:layout_centerInParent="true"/>

    <ProgressBar
        android:id="@+id/progressBar_signUpConfirmedEditProfileLayout_profilePictureProgressBar"
        style="?android:attr/progressBarStyleSmall"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_centerInParent="true"
        android:visibility="visible"/>
</RelativeLayout>

这是舍入位图方法:

public Bitmap getRoundedShape(Bitmap scaleBitmapImage) {
    int targetWidth = 100;
    int targetHeight = 100;
    Bitmap targetBitmap = Bitmap.createBitmap(targetWidth,
            targetHeight,Bitmap.Config.ARGB_8888);

    Canvas canvas = new Canvas(targetBitmap);
    Path path = new Path();
    path.addCircle(((float) targetWidth) / 2,
            ((float) targetHeight) / 2,
            (Math.min(((float) targetWidth),
                    ((float) targetHeight)) / 2),
            Path.Direction.CCW);
    canvas.clipPath(path);
    Bitmap sourceBitmap = scaleBitmapImage;
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setFilterBitmap(true);
    //paint.setColor(Color.WHITE);
    //paint.setStyle(Paint.Style.STROKE);
    //paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
    //paint.setDither(true);
    //paint.setShader(new BitmapShader(sourceBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
    canvas.drawBitmap(sourceBitmap,
            new Rect(0, 0, sourceBitmap.getWidth(),
                    sourceBitmap.getHeight()),
            new Rect(0, 0, targetWidth, targetHeight), paint);
    return targetBitmap;
}

正如你所看到的,我已经尝试了很多,根据评论的行数判断,呵呵。

有什么决心吗?我想也许我可以添加一个边界以某种方式剪辑1个像素的边距?但我不知道该怎么做!

有人能帮助我吗? 干杯!

1 个答案:

答案 0 :(得分:0)

尝试将更大的位图转换为圆形,然后缩放它/使其变小。

因此,下载图像,将其放大到2-4倍大小,制作圆圈,然后将其缩放回原始大小。

以下是缩放位图的方法:Android Bitmap resize