Android - stretch image partially

前端 未结 3 2012
予麋鹿
予麋鹿 2021-01-16 10:54

Is there any way to stretch image partially in android? Something like this

\"enter

3条回答
  •  孤街浪徒
    2021-01-16 11:02

    That can be done in code too:

    int w = myImage.getWidth();
    int h =  myImage.getHeight();
    int thirdWidht = w / 3;
    
    //create a new blank image
    Bitmap stretchImage = Bitmap.createBitmap(w + thirdWidth, h, Bitmap.Config.ARGB_8888 );
    
    Canvas c = new Canvas(stretchImage);
    
    //draw left bit
    c.drawBitmap(normalImage, new Rect(0,0,thirdWidht,h), new Rect(0,0,thirdWidht,h), true);
    
    //draw stretched middle bit
    c.drawBitmap(normalImage, new Rect(thirdWidht,0,thirdWidht * 2, h), new Rect(thirdWidht,0,thirdWidht * 3,h), true);
    
    //draw right bit
    c.drawBitmap(normalImage, new Rect(thirdWidht * 2,0,w,h), new Rect(thirdWidht * 3,0,w + thirdWidht,h), true);
    
    myImageView.setImageBitmap(stretchImage);
    

提交回复
热议问题