Android drawBitmap错误

时间:2014-02-27 17:32:50

标签: android

我使用drawBitmap绘制精灵,它可以在我的手机上正常工作,但不能在我的平板电脑上工作。

精灵是32x32网格

移动版(Android 2.3.6)

http://sfidasoft.com/agustin/view_1.jpg

[view_1.jpg]

平板电脑(Android 4.1.2)

http://sfidasoft.com/agustin/view_2.jpg [view_2.jpg]

代码

canvas.drawBitmap(bitmap, new Rect(0,0,32,32), new Rect(0,0,32,32), null);

请帮忙!

logcat的

02-27 14:05:12.203:D / AndroidRuntime(1226):>>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit<<<<<<< 02-27 14:05:12.203:D / AndroidRuntime(1226):CheckJNI为ON 02-27 14:05:12.530:D / AndroidRuntime(1226):调用主条目com.android.commands.pm.Pm 02-27 14:05:12.662:D / dalvikvm(1171):GC_EXPLICIT释放40K,52%免费2660K / 5511K,外部716K / 1038K,暂停92ms 02-27 14:05:12.662:W / ActivityManager(849):找不到内容提供商: 02-27 14:05:13.188:W / ActivityManager(849):找不到内容提供商: 02-27 14:05:13.223:D / PackageParser(849):扫描包:/ data / app / vmdl394565078.tmp 02-27 14:05:14.703:I / PackageManager(849):删除非系统包:com.example.latorre 02-27 14:05:14.703:I / ActivityManager(849):强制停止包com.example.latorre uid = 10007 02-27 14:05:14.703:I / Process(849):发送信号。 PID:1206 SIG:9 02-27 14:05:14.733:I / WindowManager(849):WIN DEATH:Window {b6643760 SurfaceView paused = false} 02-27 14:05:14.733:E / InputDispatcher(849):channel' b666b000 com.example.latorre / com.example.latorre.Main(server)' 〜消费者关闭输入通道或发生错误。事件= 0x8中 02-27 14:05:14.748:E / InputDispatcher(849):channel' b666b000 com.example.latorre / com.example.latorre.Main(server)' 〜频道不可挽回地被打破,将被处置! 02-27 14:05:14.783:I / WindowManager(849):WIN DEATH:Window {b666b000 com.example.latorre / com.example.latorre.Main paused = false} 02-27 14:05:14.874:W / InputManagerService(849):得到RemoteException向pid发送setActive(false)通知1206 uid 10007 02-27 14:05:15.721:D / PackageManager(849):扫描包com.example.latorre 02-27 14:05:15.721:I / PackageManager(849):包com.example.latorre codePath从/data/app/com.example.latorre-1.apk更改为/data/app/com.example.latorre -2.apk;保留数据并使用新的 02-27 14:05:15.722:I / PackageManager(849):解压缩/data/app/com.example.latorre-2.apk的本机库 02-27 14:05:15.732:D / installd(793):DexInv:--- BEGIN' /data/app/com.example.latorre-2.apk' --- 02-27 14:05:15.867:D / dalvikvm(944):GC_EXPLICIT释放181K​​,49%免费3065K / 5895K,外部2094K / 2598K,暂停41ms 02-27 14:05:16.353:D / dalvikvm(1235):DexOpt:找不到字段Landroid / graphics / BitmapFactory $ Options; .inMutable 02-27 14:05:16.623:D / dalvikvm(1235):DexOpt:加载99ms,验证+ opt 332ms 02-27 14:05:16.715:D / installd(793):DexInv:--- END' /data/app/com.example.latorre-2.apk' (成功)--- 02-27 14:05:16.715:W / PackageManager(849):pkg:com.example.lator的代码路径从/data/app/com.example.latorre-1.apk更改为/ data / app / com。 example.latorre-2.apk 02-27 14:05:16.715:W / PackageManager(849):pkg:com.example.lator的资源路径从/data/app/com.example.latorre-1.apk更改为/ data / app / com。 example.latorre-2.apk 02-27 14:05:16.715:D / PackageManager(849):活动:com.example.latorre.Main 02-27 14:05:16.723:I / ActivityManager(849):强制停止包com.example.latorre uid = 10007 02-27 14:05:17.082:I / installd(793):move /data/dalvik-cache/data@app@com.example.latorre-2.apk@classes.dex - > /data/dalvik-cache/data@app@com.example.latorre-2.apk@classes.dex 02-27 14:05:17.082:D / PackageManager(849):安装在/data/app/com.example.latorre-2.apk中的新软件包 02-27 14:05:17.132:I / ActivityManager(849):强制停止包com.example.latorre uid = 10007 02-27 14:05:17.229:D / dalvikvm(849):GC_EXPLICIT释放992K,45%空闲4410K / 7943K,外部5272K / 6583K,暂停45ms 02-27 14:05:17.262:D / dalvikvm(977):GC_EXPLICIT释放79K,51%免费2869K / 5767K,外部716K / 1038K,暂停76ms 02-27 14:05:17.362:D / dalvikvm(849):GC_EXPLICIT释放8K,45%免费4404K / 7943K,外部5039K / 6293K,暂停87ms 02-27 14:05:17.407:W / ResourceType(849):无法在包0中输入0x7f060000(t = 5 e = 0)(错误-75) 02-27 14:05:17.432:I / installd(793):unlink /data/dalvik-cache/data@app@com.example.latorre-1.apk@classes.dex 02-27 14:05:17.432:D / AndroidRuntime(1226):关闭VM 02-27 14:05:17.442:D / dalvikvm(1226):GC_CONCURRENT释放99K,72%空闲291K / 1024K,外部0K / 0K,暂停0ms + 0ms 02-27 14:05:17.442:D / jdwp(1226):获得唤醒信号,退出选择 02-27 14:05:17.442:D / dalvikvm(1226):调试器已分离;对象注册表有1个条目 02-27 14:05:17.602:D / VoiceDialerReceiver(1096):onReceive Intent {act = android.intent.action.PACKAGE_REMOVED dat = package:com.example.latorre flg = 0x10000000 cmp = com.android.voicedialer / .VoiceDialerReceiver (有额外的)} 02-27 14:05:17.602:V / RecognizerEngine(1096):deleteCachedGrammarFiles /data/data/com.android.voicedialer/files/openentries.txt 02-27 14:05:17.602:D / VoiceDialerReceiver(1096):onReceive Intent {act = android.intent.action.PACKAGE_ADDED dat = package:com.example.latorre flg = 0x10000000 cmp = com.android.voicedialer / .VoiceDialerReceiver (有额外的)} 02-27 14:05:17.602:V / RecognizerEngine(1096):deleteCachedGrammarFiles /data/data/com.android.voicedialer/files/openentries.txt 02-27 14:05:17.663:D / AndroidRuntime(1242):>>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit<<<<<<< 02-27 14:05:17.677:D / AndroidRuntime(1242):CheckJNI为ON 02-27 14:05:17.813:W / RecognitionManagerService(849):找不到可用的语音识别服务 02-27 14:05:18.075:D / AndroidRuntime(1242):调用主条目com.android.commands.am.Am 02-27 14:05:18.095:I / ActivityManager(849):开始:Intent {act = android.intent.action.MAIN cat = [android.intent.category.LAUNCHER] flg = 0x10000000 cmp = com.example.latorre /.Main}来自pid 1242 02-27 14:05:18.123:D / AndroidRuntime(1242):关闭VM 02-27 14:05:18.143:D / dalvikvm(1242):GC_CONCURRENT释放100K,70%可用315K / 1024K,外部0K / 0K,暂停0ms + 1ms 02-27 14:05:18.143:D / dalvikvm(1242):调试器已分离;对象注册表有1个条目 02-27 14:05:18.272:I / ActivityManager(849):启动proc com.example.latorre for activity com.example.latorre / .Main:pid = 1250 uid = 10007 gids = {} 02-27 14:05:18.552:D / CREADO(1250):1 02-27 14:05:18.973:D / gralloc_goldfish(1250):未检测到GPU仿真的仿真器。 02-27 14:05:19.073:I / ActivityManager(849):显示com.example.latorre / .Main:+ 957ms 02-27 14:05:19.113:D / dalvikvm(1250):GC_EXTERNAL_ALLOC释放43K,51%免费2671K / 5379K,外部972K / 1038K,暂停69ms 02-27 14:05:24.303:D / dalvikvm(944):GC_EXPLICIT释放64K,48%免费3078K / 5895K,外部2102K / 2598K,暂停44ms 02-27 14:05:29.303:D / dalvikvm(1020):GC_EXPLICIT释放92K,52%免费2697K / 5511K,外部716K / 1038K,暂停11ms 02-27 14:05:34.327:D / dalvikvm(1096):GC_EXPLICIT释放333K,52%免费2662K / 5511K,外部716K / 1038K,暂停26ms 02-27 14:05:39.323:D / dalvikvm(1171):GC_EXPLICIT释放7K,52%免费2658K / 5511K,外部716K / 1038K,暂停12ms

1 个答案:

答案 0 :(得分:0)

试试此代码

final int color = 0xff424242;    // put your color
final Paint paint = new Paint();
final Rect rect = new Rect(0,0,32,32);


paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawBitmap(bitmap, rect, rect, paint);

尝试将convertPixelsToDp(32,context)替换为32

/**
 * This method converts dp unit to equivalent pixels, depending on device density. 
 * 
 * @param dp A value in dp (density independent pixels) unit. Which we need to convert into pixels
 * @param context Context to get resources and device specific display metrics
 * @return A float value to represent px equivalent to dp depending on device density
 */
public static float convertDpToPixel(float dp, Context context){
    Resources resources = context.getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();
    float px = dp * (metrics.densityDpi / 160f);
    return px;
}

/**
 * This method converts device specific pixels to density independent pixels.
 * 
 * @param px A value in px (pixels) unit. Which we need to convert into db
 * @param context Context to get resources and device specific display metrics
 * @return A float value to represent dp equivalent to px value
 */
public static float convertPixelsToDp(float px, Context context){
    Resources resources = context.getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();
    float dp = px / (metrics.densityDpi / 160f);
    return dp;
}