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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With