我收到编译错误:
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);
}*/
}
如果需要更多详细信息,请与我们联系。
答案 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()
方法内。