在某些设备上,以编程方式绘制的图标会像素化

时间:2014-06-26 18:25:32

标签: android bitmap imageview icons android-canvas

我在代码中创建一个图标,在大多数设备上显示效果很好,但在某些设备上,它显示所有像素化。我尝试以不同的密度创建图标,并查看是否将其文件手动存储在res文件夹中,密度会有所不同,但事实并非如此。

// -------------------------------------------------------------------------
// draw bitmap icon image using Canvas and store in database as BLOB
// -------------------------------------------------------------------------
Bitmap bmpBase = Bitmap.createBitmap( 120, 120, Bitmap.Config.ARGB_8888 );
...
Canvas canvas = new Canvas( bmpBase );
...
canvas.drawCircle( x, y, radius, paint );

// convert icon bitmap to PNG and extract as BLOB to store in database
ByteArrayOutputStream baos = new ByteArrayOutputStream();  
bmpBase.compress( Bitmap.CompressFormat.PNG, 100, baos );   
buffer = baos.toByteArray();


// ------------------------------------------------------------
// get icon BLOB from database as Bitmap and set in ImageView
// ------------------------------------------------------------
...
ByteArrayInputStream imageStream = new ByteArrayInputStream(iconBlob);
Bitmap iconBitmap = BitmapFactory.decodeStream(imageStream);

// Set ImageView to our icon bitmap
ImageView imageView = (ImageView) view.findViewById(R.id.row_icon);
imageView.setImageBitmap(iconBitmap);

ImageView的布局

<RelativeLayout
    android:id="@+id/row_icon_first"
    android:layout_width="20dp"
    android:layout_height="20dp"  >

    <ImageView
        android:id="@+id/row_icon"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"/>
</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

尝试推杆 机器人:adjustViewBounds =&#34;真&#34;