-1

デコード機能を使用して画像を圧縮およびデコードするにはどうすればよいですか? デコード関数を呼び出すにはどうすればよいですか?

この行:

image = decodeFile(getResources(),R.drawable.my);

エラーが表示されます:

タイプ SQLiteDemoActivity のメソッド decodeFile(File) は、引数 (Resources、int) には適用されません。

コード:

  ArrayList<Contact> imageArry = new ArrayList<Contact>();
 ContactImageAdapter adapter;
   Button BrowseButton;
  Button BrowseButton2;
 DataBaseHandler db;
  public  static Bitmap image ;
 public  static byte[] imageInByte;



 ByteArrayOutputStream stream = new ByteArrayOutputStream();
/** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  db = new DataBaseHandler(this);




  BrowseButton=(Button)findViewById(R.id.BrowseButton);
  BrowseButton2=(Button)findViewById(R.id.BrowseButton2);

 adapter = new ContactImageAdapter(this, R.layout.screen_list,  imageArry);

  BrowseButton.setOnClickListener(new View.OnClickListener() {

  @Override
  public void onClick(View v) {



   < this line show error--->     image = decodeFile(getResources(),R.drawable.my);
    //BitmapFactory.decodeFile(photo.toString(),options);
    image.compress(CompressFormat.JPEG, 100, stream);
     imageInByte = stream.toByteArray();

    Log.d("Insert: ", "Inserting ..");
    db.addContact(new Contact("FaceBook", imageInByte));



}
   });

    BrowseButton2.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {


    List<Contact> contacts = db.getAllContacts();
    for (Contact cn : contacts) {




    String log = "ID:" + cn.getID() + " Name: " + cn.getName()      + " ,Image: " + cn.getImage();


    //Writing Contacts to log
    Log.d("Result: ", log);
    //add contacts data in arrayList
    imageArry.add(cn);

    }

    ListView dataList = (ListView) findViewById(R.id.list);
    dataList.setAdapter(adapter);

    try {
        stream.close();
        stream = null;
    } catch (IOException e) {

        e.printStackTrace();
    }

 }
   });



             private Bitmap decodeFile(File f) {
 try {
    // decode image size
    BitmapFactory.Options o = new BitmapFactory.Options();
    o.inJustDecodeBounds = true;
    BitmapFactory.decodeStream(new FileInputStream(f), null, o);

    // Find the correct scale value. It should be the power of 2.
    final int REQUIRED_SIZE = 70;
    int width_tmp = o.outWidth, height_tmp = o.outHeight;
    int scale = 1;
    while (true) {
        if (width_tmp / 2 < REQUIRED_SIZE || height_tmp / 2 < REQUIRED_SIZE)
            break;
        width_tmp /= 2;
        height_tmp /= 2;
        scale++;
    }
4

1 に答える 1

1

BitmapFatory.decodeResource(...)の代わりに使用してくださいdecodeFile(...)

于 2013-02-16T15:51:40.830 に答える