2011-07-21 1 views
0

J'ai obtenu du code, il dessine des images en fonction de la taille de l'image. mais je veux étirer l'image en plein écran. J'ai beaucoup essayé mais rien n'a vraiment aidé. Quelqu'un peut-il le faire pour moi? merci à l'avancecomment modifier ce code pour étirer l'image en plein écran dans android

public Bitmap getBitmap(int width, int height, int index) { 
     Bitmap b = Bitmap.createBitmap(width, height, 
       Bitmap.Config.ARGB_8888); 
     b.eraseColor(0xF000FFFF); 
     Canvas c = new Canvas(b); 
     Drawable d = getResources().getDrawable(mBitmapIds[index]); 

     int margin = 1; 
     int border =1 ; 
     Rect r = new Rect(margin, margin, width - margin, height - margin); 

     int imageWidth = r.width() - (border * 2); 
     int imageHeight = imageWidth * d.getIntrinsicHeight() 
       /d.getIntrinsicWidth(); 
     if (imageHeight > r.height() - (border * 2)) { 
      imageHeight = r.height() - (border * 2); 
      imageWidth = imageHeight * d.getIntrinsicWidth() 
        /d.getIntrinsicHeight(); 
     } 

     r.left += ((r.width() - imageWidth)/2) - border; 
     r.right = r.left + imageWidth + border + border; 
     r.top += ((r.height() - imageHeight)/2) - border; 
     r.bottom = r.top + imageHeight + border + border; 

     Paint p = new Paint(); 
     p.setColor(0xFFC0C0C0); 
     c.drawRect(r, p); 
     r.left += border; 
     r.right -= border; 
     r.top += border; 
     r.bottom -= border; 

     d.setBounds(r); 
     d.draw(c); 
     return b; 
    } 
+0

essayez de définir comme image d'arrière-plan plutôt que comme image src il va s'étirer mais peut déformer l'image – ingsaurabh

Répondre

0

vérifier cette méthode ................. onClick de l'ongle du pouce, vous pouvez démarrer une nouvelle activité en mode plein écran:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
WindowManager.LayoutParams.FLAG_FULLSCREEN); 

et passer le uri d'image ou quelque chose qui indique la source d'image à la nouvelle activité:

Intent intent = new Intent(YouActivity.this, FullImage.class); 
intent.putExtra("imageUri", R.drawable.yourImage); // or the path to your image. 

dans FullImage classe d'activité

ImageView icon = (ImageView) findViewById(R.id.myImage); 
BitmapFactory.Options options = new BitmapFactory.Options(); 
options.inTempStorage = new byte[3*1024]; 
Bitmap ops = BitmapFactory.decodeFile(path, options); // instead path you can get an image from previous activity. 
icon.setImageBitmap(ops); 
Questions connexes