Create a Bitmap/Drawable from file path

Create bitmap from file path: File sd = Environment.getExternalStorageDirectory(); File image = new File(sd+filePath, imageName); BitmapFactory.Options bmOptions = new BitmapFactory.Options(); Bitmap bitmap = BitmapFactory.decodeFile(image.getAbsolutePath(),bmOptions); bitmap = Bitmap.createScaledBitmap(bitmap,parent.getWidth(),parent.getHeight(),true); imageView.setImageBitmap(bitmap); If you want to scale the bitmap to the parent’s height and width then use Bitmap.createScaledBitmap function. I think you are giving the wrong file path. 🙂 … Read more

How can I print an image on a Bluetooth printer in Android?

I solve it converting Bitmap to Byte array. Remember that your image must be black & white format. For full source code: https://github.com/imrankst1221/Thermal-Printer-in-Android public void printPhoto() { try { Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.img); if(bmp!=null){ byte[] command = Utils.decodeBitmap(bmp); printText(command); }else{ Log.e(“Print Photo error”, “the file isn’t exists”); } } catch (Exception e) { e.printStackTrace(); … Read more

How to solve java.lang.OutOfMemoryError trouble in Android

You can’t increase the heap size dynamically but you can request to use more by using. android:largeHeap=”true” in the manifest.xml,you can add in your manifest these lines it is working for some situations. <application android:allowBackup=”true” android:icon=”@mipmap/ic_launcher” android:label=”@string/app_name” android:largeHeap=”true” android:supportsRtl=”true” android:theme=”@style/AppTheme”> Whether your application’s processes should be created with a large Dalvik heap. This applies to … Read more

tech