简体   繁体   English

调整位图大小

[英]Resize the bitmap

Im my project I am capturing the image from Camera app and displaying image in listview by using following code . 我是我的项目我从相机应用程序捕获图像并使用以下代码在列表视图中显示图像。 MySimpleCursorAdapter: MySimpleCursorAdapter:

public class MySimpleCursorAdapter extends SimpleCursorAdapter {

    public MySimpleCursorAdapter(Context context, int layout, Cursor c,
        String[] from, int[] to) {
        super(context, layout, c, from, to);
    }

    @Override
    public void setViewImage(ImageView image_v, String id) {

        String path = id;
        Bitmap b = BitmapFactory.decodeFile(path);
        image_v.setImageBitmap(resizedBitmap);

    }

}

List.java List.java

String[] from = new String[]{DbManager.babyName, DbManager.baby_image}; 
        int[] to = new int[] {/*R.id.list_id,*/ R.id.drname12,R.id.imageView1};//,R.id.list_date};{                 
        MySimpleCursorAdapter   Adapter = new MySimpleCursorAdapter(this, R.layout.rowlayout, c1, from, to);       
        list.setAdapter(Adapter);

Every things is working fine till this point But when I try to resize the bitmap by using this piece of code 到目前为止,每件事情都运行良好但是当我尝试使用这段代码调整位图大小时

 Bitmap resizedBitmap = Bitmap.createScaledBitmap(b, 200, 200, true);

its giving following error : 它给出以下错误:

05-22 07:13:07.562: E/AndroidRuntime(478): FATAL EXCEPTION: main
05-22 07:13:07.562: E/AndroidRuntime(478): java.lang.NullPointerException
05-22 07:13:07.562: E/AndroidRuntime(478):  at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:380)
05-22 07:13:07.562: E/AndroidRuntime(478):  at com.example.tottal.baby.care.MySimpleCursorAdapter.setViewImage(MySimpleCursorAdapter.java:22)
05-22 07:13:07.562: E/AndroidRuntime(478):  at android.support.v4.widget.SimpleCursorAdapter.bindView(SimpleCursorAdapter.java:143)
05-22 07:13:07.562: E/AndroidRuntime(478):  at android.support.v4.widget.CursorAdapter.getView(CursorAdapter.java:256)

Error is here check this properly 错误在这里检查这个正确

 Bitmap b = BitmapFactory.decodeFile(path);

your variable path or b may be null. 您的变量pathb可能为null。

check these variable not equal to null then use them. 检查这些变量不等于null然后使用它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM