title: Android studio - PrinterThermal/ESCPOS - image from url
body: <p>I'm trying to print qr code like image, on a thermal pos bluetooth printer in android studio,the printer is connected - bluetooth, I can print the text and image as Drawable, but I can't I can't print the image from url, I would be grateful if someone can help.</p>
  <p>i want to send qr code as image to printer</p>
  <p>URL := 'http://www.examples.com/code_1.png';</p>
  <p><a href="https://i.stack.imgur.com/pjJ79.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pjJ79.png" alt="enter image description here" /></a></p>
  <p>I use this function (Android studio), for printing</p>
  <pre><code>  try {
                myBitSlika = getBitmapFromURL(&quot;https://examles.com/temp/code_nn.png&quot;) ;
          } catch (Exception e) {
              Log.e(&quot;APP&quot;, &quot;url image::&quot;, e);
          }
  
    BluetoothConnection connection = BluetoothPrintersConnections.selectFirstPaired();
        if (connection != null) 
               {
               EscPosPrinter printer = new EscPosPrinter(connection, 203, 48f, 32);
     final String text = &quot;&quot;[C]&lt;img&gt;&quot; + PrinterTextParserImg.bitmapToHexadecimalString(printer,myBitSlika )+ &quot;&lt;/img&gt;\n&quot;  +
                              &quot;[L]\n&quot; +
                              &quot;[L]&quot; + df.format(new Date()) + &quot;\n&quot; +
                              &quot;[C]================================\n&quot; +
                              &quot;[L]&lt;b&gt;Effective Java&lt;/b&gt;\n&quot; +
                              &quot;[L]    1 pcs[R]&quot; + nf.format(25000) + &quot;\n&quot; +
                              &quot;[L]&lt;b&gt;Headfirst Android Development&lt;/b&gt;\n&quot; +
                              &quot;[L]    1 pcs[R]&quot; + nf.format(45000) + &quot;\n&quot; +
                              &quot;[L]&lt;b&gt;The Martian&lt;/b&gt;\n&quot; +
                              &quot;[L]    1 pcs[R]&quot; + nf.format(20000) + &quot;\n&quot; +
                              &quot;[C]--------------------------------\n&quot; +
                              &quot;[L]TOTAL[R]&quot; + nf.format(90000) + &quot;\n&quot; +
                              &quot;[L]DISCOUNT 15%[R]&quot; + nf.format(13500) + &quot;\n&quot; +
                              &quot;[L]TAX 10%[R]&quot; + nf.format(7650) + &quot;\n&quot; +
                              &quot;[L]&lt;b&gt;GRAND TOTAL[R]&quot; + nf.format(84150) + &quot;&lt;/b&gt;\n&quot; +
                              &quot;[C]--------------------------------\n&quot; +
                              &quot;[C]&lt;barcode type='ean13' height='10'&gt;202105160005&lt;/barcode&gt;\n&quot; +
                              &quot;[C]--------------------------------\n&quot; +
                              &quot;[C]Thanks For Shopping\n&quot; +
                              &quot;[C]https://kodejava.org\n&quot; +
                              &quot;[L]\n&quot; +
                              &quot;[L]&lt;qrcode&gt;https://kodejava.org&lt;/qrcode&gt;\n&quot;;
      
                      printer.printFormattedText(text);
  </code></pre>
  <p>I use this feature to retrieve an image from the internet</p>
  <pre><code>public static Bitmap getBitmapFromURL(String src) {
      try {
          URL url = new URL(src);
          HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
          connection.setDoInput(true);
          connection.connect();
          InputStream input = connection.getInputStream();
          Bitmap myBitmap = BitmapFactory.decodeStream(input);
          return myBitmap;
      } catch (IOException e) {
          Log.e(&quot;APP&quot;, &quot;save image&quot;, e);
          return null;
      }
  }
  </code></pre>
  <p>if instead of myBitSlika, I put it to take a picture
  with drawable directory, print without problems, (PrinterTextParserImg.bitmapToHexadecimalString(printer,this.getApplicationContext().getResources().getDrawableForDensity(R.drawable.code_232,DisplayMetrics.DENSITY_LOW, getTheme()))</p>
  <pre><code>final String text = &quot;[C]&lt;img&gt;&quot; + PrinterTextParserImg.bitmapToHexadecimalString(printer,this.getApplicationContext().getResources().getDrawableForDensity(R.drawable.code_232,DisplayMetrics.DENSITY_LOW, getTheme())) + &quot;&lt;/img&gt;\n&quot; +
  </code></pre>