卫星分布图在画布中所在比例太小。可能和图片本身太小有关。
原代码:
****************************************************************************************************************************************************************************************
页面显示:
gps_view_activity.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@color/satellites_bg" > <TextView android:id="@+id/gps_status_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="状态"/> <TextView android:id="@+id/lonlat_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="0 0"/> //自定义控件显示卫星分布状态图 <ylybbs.study.mygpstest.SatellitesView android:id="@+id/satellitesView" android:layout_width="match_parent" android:layout_height="fill_parent" /> </LinearLayout>
====================================================================================================================================绘图java文件关键语句
compassBitmap = BitmapFactory.decodeResource(res, R.drawable.bg_satellite); compassRadius = compassBitmap.getWidth() / 2;
****************************************************************************************************************************************************************************************
改进JAVA文件代码:对图进行放大
compassBitmap = BitmapFactory.decodeResource(res, R.drawable.bg_satellite);
//增加一个语句,对图进行放大
compassBitmap = Bitmap.createScaledBitmap(compassBitmap,600,600,true);
compassRadius = compassBitmap.getWidth() / 2;
***************************************************************************************************************************************************************************************
效果图:
****************************************************************************************************************************************************************************************
public static Bitmap createScaledBitmap (Bitmap src, int dstWidth, int dstHeight, boolean filter) 函数用法:
public static Bitmap createScaledBitmap (Bitmap src, int dstWidth, int dstHeight, boolean filter)
从当前存在的位图,按一定的比例创建一个新的位图。
参数
src 用来构建子集的源位图
dstWidth 新位图期望的宽度
dstHeight 新位图期望的高度
filter 如果是放大图片,filter决定是否平滑,如果是缩小图片,filter无影响
返回值
一个新的按比例变化的位图。
/** * 修改图片的大小(从当前存在的位图,按一定的比例创建一个新的位图)<br> * 方 法 名:createScaledBitmap <br> * 创 建 人: <br> * 创建时间:2016-6-7 上午9:14:47 <br> * 修 改 人: <br> * 修改日期: <br> * @param bitmap 用来构建子集的源位图 * @param iconWidth 新位图期望的宽度 * @param iconHeight 新位图期望的高度 * @param filter 未知 * @return Bitmap 一个新的按比例变化的位图。 */ public static Bitmap createScaledBitmap(Bitmap bitmap, int iconWidth, int iconHeight, boolean filter) { Bitmap bitmap2; try { bitmap2 = Bitmap.createScaledBitmap(bitmap, iconWidth, iconHeight, filter); } catch (OutOfMemoryError localOutOfMemoryError) { gc(); bitmap2 = Bitmap.createScaledBitmap(bitmap, iconWidth, iconHeight, filter); } return bitmap2; }
