Android - stretch image partially

前端 未结 3 2009
予麋鹿
予麋鹿 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);
    
    0 讨论(0)
  • 2021-01-16 11:06

    You can prepare your image as NinePatch using Draw 9-patch and then loadt it with NinePatch class

    0 讨论(0)
  • 2021-01-16 11:07

    What you're doing is built into android, actually. Turn that image into a 9-patch.

    http://developer.android.com/guide/developing/tools/draw9patch.html

    0 讨论(0)
提交回复
热议问题