获取错误:无法解析bitmap.compress的“压缩”符号(Bitmap.CompressFormat.PNG,0,stream);

时间:2016-02-11 13:09:11

标签: java android bitmap

我收到编译错误:

cannot resolve symbol for 'compress' for line: bitmap.compress(Bitmap.CompressFormat.PNG, 0, stream); 

请告诉我问题在哪里?

以下是班级:

public class EmployeeInfo extends ListActivity implements OnItemClickListener {

    EmpSQLiteHelper db = new EmpSQLiteHelper(this);
    List<Employee> list;
    ArrayAdapter<String> myAdapter;


    // get image from drawable
    Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.shyam);

    // convert from bitmap to byte array
    ByteArrayOutputStream stream = new ByteArrayOutputStream();

    bitmap.compress(Bitmap.CompressFormat.PNG, 0, stream);
    byte[] imageInByte = stream.toByteArray();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.emp_list);

        // drop this database if already exists
        db.onUpgrade(db.getWritableDatabase(), 1, 2);

        db.createEmpInfo(new Employee("Shyam", "28", imageInByte));
        db.createEmpInfo(new Employee("Ramesh", "30", imageInByte));
        db.createEmpInfo(new Employee("Anuj", "23", imageInByte));
        db.createEmpInfo(new Employee("Dinesh", "34", imageInByte));
        db.createEmpInfo(new Employee("Suresh", "29", imageInByte));
        db.createEmpInfo(new Employee("Arjun", "36", imageInByte));
        db.createEmpInfo(new Employee("Karn", "30", imageInByte));
        db.createEmpInfo(new Employee("Varun", "27", imageInByte));

        // get all employees
        list = db.getAllEmployeesInfo();
        List<String> listTitle = new ArrayList<String>();

        for (int i = 0; i < list.size(); i++) {
            listTitle.add(i, list.get(i).getEmp_name());
        }

        myAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listTitle);
        getListView().setOnItemClickListener(this);
        setListAdapter(myAdapter);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

        Intent intent = new Intent(this, EmpImageDisplay.class);
        intent.putExtra("employee", list.get(position).getEmp_Id());

        //startActivitiyForResult(intent, 1);
        startActivity(intent);
    }

    /*@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        // get all books again, because //something changed
        list = db.getAllEmployeesInfo();

        List<String> listTitle = new ArrayList<String>();

        for (int i = 0; i < list.size(); i++) {
            listTitle.add(i, list.get(i).getEmp_name());
        }

        myAdapter = new ArrayAdapter<String>(this,R.layout.emp_row_layout, R.id.emp_listName, listTitle);
        getListView().setOnItemClickListener(this);
        setListAdapter(myAdapter);
    }*/
}

如果需要更多详细信息,请与我们联系。

1 个答案:

答案 0 :(得分:1)

您尝试在compress课程的方法之外使用Bitmap课程中的EmployeeInfo方法。试着说:

// get image from drawable
Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.shyam);

// convert from bitmap to byte array
ByteArrayOutputStream stream = new ByteArrayOutputStream();

bitmap.compress(Bitmap.CompressFormat.PNG, 0, stream);
byte[] imageInByte = stream.toByteArray();

onCreate()方法内。