2016-06-20 62 views
0

形式JSON我跟着this打印樣品Reciepts ..如何使用動態圖像(URL)的位圖

這是我的JSON數據

{ 
    "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" 
    } 
} 

這裏,我已經在其他一些活動解析JOSN。並通過意圖傳遞。 我分配了URL/JSON響應串「Test22」

現在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

所以我想在位圖添加這個字符串..所以我可以打印..

那邊在從位置打印圖像EPSON示例代碼,他們已經用這種

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

從R.drawable這裏樣本印刷圖片,但我想從URL打印它如果打印應該刪除圖片後,它的存儲...

任何一個可以建議我什麼,我需要在R.drawable在這種情況下,加...

實際上它的一個PDF,我將其轉換爲一個圖像.. 任何人可以建議我PDF位圖或打印圖像...

回答

1

R.drawable只能從圖像打包在應用程序中。

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

更新:

從EPSON代碼

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

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"); 
+0

確定@joushua先生更換,所以在這裏我如何使用這個insted的的r.drawable在我的問題有epson示例代碼 – MLN

+0

@Madhu'Bitmap logo Data = getBitmapFromURL(url);' – Joshua

+0

這裏我的網址是Test22(因此我從json和通過intent採取它)我需要在哪裏取代它.. – MLN