mardi 31 mars 2015

Android Bitmap image resize

So i have working on a imageview and i want to resize the pictures in my project and i know i can do it with Bitmap so i changed ,y code and began to work Bitmap and when i use the Bitmap resize its throw and eror(exption) and crash from the app



public class ClassicMode extends Activity {//מהמשחק עצמו

String pic;//תמונה של הדגל
Button answer1;//תשובות
Button answer2;
Button answer3;
Button answer4;
TextView guess;//
TextView numOfGuess;//
DatabaseHandler db = new DatabaseHandler(this);
String fn;
Guesses G;
Bitmap bm;
//int Nguess=3;//מסםר ניחושים
//int Nguesstemp=Nguess;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);

guess =(TextView)findViewById(R.id.guesses);
numOfGuess=(TextView)findViewById(R.id.numOfGuesses);
//numOfGuess.setText(Integer.toString(Nguess));
numOfGuess.setText(String.valueOf(Guesses.numOfGuesses));
Flags f = new Flags();
Random r = new Random();//הדגל שיבחר לשאלה
int num = r.nextInt(100);//Up
//Log.d("yes", "yes");
//Random ra = new Random();//הדגלים שיהיו בתשובות
//int numA = ra.nextInt(4);//Up

f = db.getFlag(num);//הצגת הדגל הרנדומלי שיצא
// final Flags d = f; // trying to make it final but it dosent help
fn = f.getName().toString();
pic = f.getImage().toString();
pic_view(pic);//מעבר לפונקציה להשמת התמונה של הדגל במשחק

//מערך ארבע כפתורים כנגד ארבע תשובות
Button [] b = new Button[4];
b[0] = (Button)findViewById(R.id.button1);
b[1] = (Button)findViewById(R.id.button2);
b[2] = (Button)findViewById(R.id.button3);
b[3] = (Button)findViewById(R.id.button4);

List<String>Answers=new ArrayList<String>();//מערך תשובות
Answers.add(f.getName().toString());//הוספת התשובה הנכונה
num = r.nextInt(30);
Answers.add(db.getFlag(num).getName().toString());//הוספת 3 תשובות רנדומליות
num = r.nextInt(30);
Answers.add(db.getFlag(num).getName().toString());
num = r.nextInt(30);
Answers.add(db.getFlag(num).getName().toString());

Collections.shuffle(Answers);//ערבוב התשובות

for(int i=0;i<Answers.size();i++)
{
b[i].setText(Answers.get(i));//השמת התשובות מהמהערך למערך הכפתורים
}
}//end of OnCreat


@SuppressLint("NewApi")
public void resetQuiz()
{
//finish();
recreate();
//numOfGuess.setText(String.valueOf(Nguess));
}

public void check(View v)
{
Log.d("yes", fn);
Button b = (Button)v;
String text = b.getText().toString();
if(text.equals(fn))
resetQuiz();
else
{
if(Guesses.numOfGuesses==1)
{
G.setNumOfGuesses(3);
finish();//כאשר מספר הניחושים
return;
}
Guesses.numOfGuesses--;
//numOfGuess=(TextView)findViewById(R.id.numOfGuesses);
//numOfGuess.setText(Integer.toString(Nguess));
numOfGuess.setText(String.valueOf(Guesses.numOfGuesses));
}

}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.second, menu);
return true;
}

private void pic_view(String pic2) {

// TODO Auto-generated method stub
//גישה לדגל לפי שמו וייבוא התמונה
Log.d("Result from pic function " , pic2);
ImageView imageView = (ImageView)findViewById(R.id.imageView1);
String uri ="@drawable/";
uri += pic2;
int imageResource = getResources().getIdentifier(uri, pic2, getPackageName());//הצוות התמונה
Bitmap bm = BitmapFactory.decodeResource(getResources(), imageResource);
Bitmap resized = Bitmap.createScaledBitmap(bm, 120, 120, true);
Drawable res= getResources().getDrawable(imageResource);//ציור התמונה
imageView.setImageDrawable(res);

}


}


the resize and the bitmap and all the image are working in the pic_view function down the code hope u can help me.


picture of my problem with the size so i want to resize the flag: http://ift.tt/1xuQpoC


Aucun commentaire:

Enregistrer un commentaire