从错误读取png.class错误、png、class

2023-09-08 10:24:54 作者:怎能不累i

当我尝试从URL加载图像,使用以下code(去掉实际图像路径):

When I attempt to load an image from a URL, using the following code (real image path removed):

Bitmap bitmap = BitmapFactory.decodeStream((InputStream)new URL("https://m.xsw88.com/allimgs/daicuo/20230908/360.png").getContent());

我收到以下错误:

I receive the following error:

Error reading from ./org/apache/harmony/awt/www/content/image/png.class

这是什么可能导致错误有什么想法?

Any thoughts on what might be causing the error?

我使用的是GoogleTV的AVD,如果该事项。

I am using a GoogleTV AVD, if that matters.

推荐答案

我希望这将是足够的。

如果您使用的是PHP;

If you are using php;

echo base64_encode($imgBinary); // You can get the imagebinary by using the fread and fopen methods provided by php

在Android:

on android:

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); 
}

这可能不是最有效的方式,但它应该做的工作。从那里,你可以建立:)

This is probably not the most efficient way, but it should do the job. From there on you can build :)

可以COM preSS位图成后PNG和安全的。例如:

You can compress the bitmap into a PNG after, and safe it. example:

decodedByte.compress(compressformat, quality, stream);//suported compress formats can be used like so: Bitmap.CompressFormat.PNG etc

convertStreamToString是很容易找到的方法。只是做一个快速谷歌搜索,或写你自己的。

convertStreamToString are easily found methods. Just do a quick google search, or write your own.