1

I am new to android studio and I am having a problem passing an image taken from the phone camera (bitmap) to a class that expects an image from drawable folder

My code works when Im passing image like this

personList.add(0, new Entry(R.drawable.image1, "", "", "", "", ""));

but when i try to pass an image produced by taking a photo from camera its shows an error Required type:int Provided:Bitmap. I don't know hot to fix it. is it possible? thank you

This is my class


public class Person {
    private int personPicture;
    private String personFullName;
    private String personRemark;
    private String personHobbies;
    private String personGender;
    private String personBirthday;

    public Person(int personPicture, String personFullName, String personRemark,String personHobbies, String personGender, String personBirthday) {
        this.setPersonPicture(personPicture);
        this.setPersonFullName(personFullName);
        this.setPersonRemark(personRemark);
        this.setPersonHobbies(personHobbies);
        this.setPersonGender(personGender);
        this.setPersonBirthday(personBirthday);
    }


    public int getPersonPicture() {
        return personPicture;
    }

    public void setPersonPicture(int personPicture) {
        this.personPicture = personPicture;
    }

    public String getPersonFullName() {
        return personFullName;
    }

    public void setPersonFullName(String personFullName) {
        this.personFullName = personFullName;
    }

    public String getPersonRemark() {
        return personRemark;
    }

    public void setPersonRemark(String personRemark) {
        this.personRemark = personRemark;
    }

    public String getPersonHobbies() {
        return personHobbies;
    }

    public void setPersonHobbies(String personHobbies) {
        this.personHobbies = personHobbies;
    }

    public String getPersonGender() {
        return personGender;
    }

    public void setPersonGender(String personGender) {
        this.personGender = personGender;
    }

    public String getPersonBirthday() {
        return personBirthday;
    }

    public void setPersonBirthday(String personBirthday) {
        this.personBirthday = personBirthday;
    }
}
brick heck
  • 11
  • 3
  • Add a Bitmap variable to the constructor: `personList.add(0, new Entry(0, "", "", "", "", "", bitmap));` Check for 0 and or null before use. You did not take a picture (in a file) but only got a thumbnail as bitmap i understand. – blackapps Dec 05 '22 at 14:14

1 Answers1

1

Hmm kinda tricky. I suggest you replace the 'int' data type for 'Object' data type. Then you'll be able to assign any kind of data into that field. Then in the image loading method you can check if personPicture is instance of int or Bitmap.

Apart from that, I suggest you save the Bitmap image into a temp folder, then access it through its path! And load the image through Glide or so, even with Android resources!

Matilveiro
  • 78
  • 5