当我尝试从URL加载图像时,使用以下代码(删除实际图像路径):
Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL("http://some-path/img.png").getContent());
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Error reading from ./org/apache/harmony/awt/www/content/image/png.class
Run Code Online (Sandbox Code Playgroud)
有关可能导致错误的原因的任何想法?
我正在使用GoogleTV AVD,如果这很重要的话.
我希望这已经足够了。
如果您使用的是 php;
echo base64_encode($imgBinary); // You can get the imagebinary by using the fread and fopen methods provided by php
Run Code Online (Sandbox Code Playgroud)
在安卓上:
HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(new HttpGet(url));
HttpEntity entity = httpResponse.getEntity();
if(entity != null) {
InputStream is = entity.getContent();
byte[] decodedString = Base64.decode(convertStreamToString(is), Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
}
Run Code Online (Sandbox Code Playgroud)
这可能不是最有效的方法,但它应该可以完成工作。从那里你可以构建:)
之后您可以将位图压缩为 PNG 并保存。例子:
decodedByte.compress(compressformat, quality, stream);//suported compress formats can be used like so: Bitmap.CompressFormat.PNG etc
Run Code Online (Sandbox Code Playgroud)
ConvertStreamToString 是很容易找到的方法。只需快速进行谷歌搜索,或者编写您自己的。
| 归档时间: |
|
| 查看次数: |
774 次 |
| 最近记录: |