如何用url设置圆位图的图像视图

xiaoxiao2025-08-15  30

try { URL url = new URL("http://192.168.2.18/SqliteTest/profile_image/" + c.getString("image")); Log.i("sahusahxsa",url.toString()); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setDoInput(true); connection.connect(); InputStream input = connection.getInputStream(); bitmap = BitmapFactory.decodeStream(input); circleBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888); BitmapShader shader = new BitmapShader (bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); Paint paint = new Paint(); paint.setShader(shader); paint.setAntiAlias(true); Canvas ca = new Canvas(circleBitmap); ca.drawCircle(bitmap.getWidth()/2, bitmap.getHeight()/2, bitmap.getWidth()/2, paint); } catch (IOException e) { Log.e(TAG, e.getMessage()); } ivAttachment.setImageBitmap(circleBitmap); } } catch (Exception e) { e.printStackTrace(); }
转载请注明原文地址: https://www.6miu.com/read-5034873.html

最新回复(0)