Android - stretch image partially
Is there any way to stretch image partially in android? Something like this
开发者_JAVA百科Here, image is stretched in the 1/3 middle section, but left and right endings remains "as is".
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
You can prepare your image as NinePatch using Draw 9-patch and then loadt it with NinePatch class
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);
精彩评论