获取错误致命信号11(SIGSEGV)位于0x09050941(代码= 1)On使用Canvas进行圆形图像

时间:2013-03-11 10:20:59

标签: android sqlite canvas bitmap bitmapfactory

我遇到了一个奇怪的问题。 在我的应用程序中,用户可以更改他/她的个人资料图片。并且该图像在一轮中显示。 我从相机/文件(图库)&转换圆角的位图我正在使用以下代码。

public static Bitmap getRoundedShape(Context context, Bitmap scaleBitmapImage, int imageWidth, int imageHeight) {
        int targetWidth = getDPEquivalentPixels(context, imageWidth);
        int targetHeight = getDPEquivalentPixels(context, imageHeight);
        Bitmap targetBitmap = Bitmap.createBitmap(targetWidth, targetHeight, Bitmap.Config.ARGB_8888);

        Canvas canvas = new Canvas(targetBitmap);
        Path path = new Path();
        path.addCircle(((float) targetWidth - 1) / 2, ((float) targetHeight - 1) / 2, (Math.min(((float) targetWidth), ((float) targetHeight)) / 2), Path.Direction.CW);
        Paint paint = new Paint();
        paint.setColor(Color.GRAY);
        // paint.setStyle(Paint.Style.STROKE);
        paint.setStyle(Paint.Style.FILL);
        paint.setAntiAlias(true);
        paint.setDither(true);
        paint.setFilterBitmap(true);
        canvas.drawOval(new RectF(0, 0, targetWidth, targetHeight), paint);

        canvas.clipPath(path);
        Bitmap sourceBitmap = scaleBitmapImage;
        canvas.drawBitmap(sourceBitmap, new Rect(0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight()), new Rect(0, 0, targetWidth, targetHeight), null);
        return targetBitmap;
    }

首先我将图像上传到服务器压缩它。然后我将它保存在本地SQLite中作为字节数组&使用上面的方法将其转换为圆形位图,以便在ImageView上显示。

现在,从现在开始,我将推荐SQLite的个人资料图片。我的问题是第一次圆角代码工作正常但是当我使用SQLIte Image&尝试将其转换为圆形我遇到了错误。

A/libc(14809): Fatal signal 11 (SIGSEGV) at 0x5f763ee0 (code=1), thread 14809

编辑::

我正在使用用户POJO,它保存从SQLite恢复的用户对象。我正在将这个Pojo转换成json&存储在SharedPreferance中,直到用户会话处于活动状态。

public class User {

    private int uid;
    private String userName;
    private String firstName;
    private String lastName;
    private String email;
    private Date dob;
    private String gender;
    private int delFlag;
    private int pin;
    private Bitmap imageData;

}

我正在使用Gson for JSON to POJO&反对解析。但我不知道Gson库是否会正确解析我的imageData(数据类型位图)。这可能会造成问题。

1 个答案:

答案 0 :(得分:1)

我认为您需要检查this guys solution,因为Bitmap似乎不可序列化。我不太了解JSON / Gson的机制,知道这肯定是问题所在。如果我在你的鞋子里,我会首先更改代码,以便它从PNG文件而不是JSON读取位图,并确认这是 问题。然后看一下更好的方法来序列化/存储位图,如上面的链接。