Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error reading from png.class

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("http://some-path/img.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?

I am using a GoogleTV AVD, if that matters.

like image 340
Steve Avatar asked Nov 29 '11 17:11

Steve


1 Answers

I hope this will be sufficient.

If you are using php;

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

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 :)

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 are easily found methods. Just do a quick google search, or write your own.

like image 128
Joey Roosing Avatar answered Oct 13 '22 00:10

Joey Roosing