我正在尝试从画布上的url设置一个图像,这个图像应该是所有设备屏幕都支持的,在android中可以在没有九补丁图像的情况下这样做吗?
另外,我不能从可绘制的资源中为不同的屏幕尺寸设置不同的尺寸图像,因为我是从URL获取图像的。
发布于 2012-11-09 15:36:08
我可以给你一个建议,
URL url = new URL(urlString); //Convert url string to url object.
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myImageBitmap = BitmapFactory.decodeStream(input);
Bitmap resizedImage = Bitmap.createScaledBitmap(myImageBitmap, dstWidth, dstHeight, true);
// dstWidth & dstHeight are the needed size of image.关于屏幕尺寸,您可以通过重写View类的onSizeChanged (int w, int h, int oldw, int oldh)方法来获得它,其中w&h是当前屏幕的宽度和高度。
https://stackoverflow.com/questions/13303526
复制相似问题