Madhu Madhu - 5 months ago 51
JSON Question

How to Use Dynamic Image(URL) form json in bitmap

I followed this to print Sample Reciepts..

This is my Json data

{
"response": {
"status": "http://www.neodynamic.com/articles/How-to-print-raw-ESC-POS-commands-from-PHP-directly-to-the-client-printer/php-print-esc-pos-sample-receipt.png"
}
}


Here I have parsed JOSN in some other activity..and passed that in a intent.
and I assigned that url/json response to a string "Test22"

now
Test22 = http://www.neodynamic.com/articles/How-to-print-raw-ESC-POS-commands-from-PHP-directly-to-the-client-printer/php-print-esc-pos-sample-receipt.png


So I want to add this string in the Bitmap.. so that i can print..

Over there in EPSON sample code for printing image from a Location they have used this

Bitmap logoData = BitmapFactory.decodeResource(getResources(), R.drawable.store);
StringBuilder textData = new StringBuilder();
final int barcodeWidth = 2;
final int barcodeHeight = 100;


Here sample is printing Image from R.drawable But I want to Print it from URL
if its storing after printing It should delete Image...

Can any one suggest me what I need to add at R.drawable in this case...

Actually Its a Pdf I am converting it to a image..
Can any one suggest me PDF to bitmap or Print a Image...

Answer

R.drawable is only from images packed in app.

public static Bitmap getBitmapFromURL(String src) {
    try {
        URL url = new URL(src);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setDoInput(true);
        connection.connect();
        InputStream input = connection.getInputStream();
        Bitmap myBitmap = BitmapFactory.decodeStream(input);
        return myBitmap;
    } catch (IOException e) {
        // Log exception
        return null;
    }
}

Update:

Replace from EPSON code

Bitmap logoData = BitmapFactory.decodeResource(getResources(), R.drawable.store);

to

Bitmap logoData = getBitmapFromURL("http://www.neodynamic.com/articles/How-to-print-raw-ESC-POS-co‌​mmands-from-PHP-directly-to-the-client-printer/php-print-esc-pos-sample-receipt.p‌​ng");
Comments