【发布时间】:2013-03-22 13:36:55
【问题描述】:
我正在搜索过去的一天,但我没有成功。
我从 API 获取图像,然后使用以下代码将其下载到位图文件中。
private Bitmap DownloadImage(String URL)
{
Bitmap bitmap = null;
InputStream in = null;
try
{
in = OpenHttpConnection(URL);
bitmap = BitmapFactory.decodeStream(in);
in.close();
}
catch (IOException e1)
{
e1.printStackTrace();
}
return bitmap;
}
private InputStream OpenHttpConnection(String urlString) throws IOException
{
InputStream in = null;
int response = -1;
URL url = new URL(urlString);
URLConnection conn = url.openConnection();
if (!(conn instanceof HttpURLConnection))
throw new IOException("Not an HTTP connection");
try
{
HttpURLConnection httpConn = (HttpURLConnection) conn;
httpConn.setAllowUserInteraction(false);
httpConn.setInstanceFollowRedirects(true);
httpConn.setRequestMethod("GET");
httpConn.connect();
response = httpConn.getResponseCode();
if (response == HttpURLConnection.HTTP_OK)
{
in = httpConn.getInputStream();
}
}
catch (Exception ex)
{
throw new IOException("Error connecting");
}
return in;
}
我得到一个正方形的图像,我想裁剪四个角并使其成为圆形图像。有没有什么办法可以实现?
欢迎任何相关答案。提前致谢。
【问题讨论】:
-
不确定我的头顶,但我想作为替代方法可能是创建一个 alpha 圆形图像,在原始图像顶部切出大小合适的孔。与使用 circle 类并进行适当的编辑相比,这并不理想,但如果您找不到所需的内容并需要快速解决,这是一种替代方法。
标签: android image android-canvas crop