public Bitmap loadImage(String path) throws OutOfMemoryError { Bitmap bitsat; try { BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.ARGB_8888; options.inJustDecodeBounds = true; Bitmap b = BitmapFactory.decodeFile(path, options); options.inSampleSize = Futils.calculateInSampleSize(options, px, px); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; Bitmap bit; if (path.startsWith("smb:/")) bit = BitmapFactory.decodeStream(new SmbFileInputStream(path)); else bit = BitmapFactory.decodeFile(path, options); bitsat = bit; // decodeFile(path);//.createScaledBitmap(bits,imageViewReference.get().getHeight(),imageViewReference.get().getWidth(),true); } catch (Exception e) { Drawable img = ContextCompat.getDrawable(mContext, R.drawable.ic_doc_image); Bitmap img1 = ((BitmapDrawable) img).getBitmap(); bitsat = img1; } return bitsat; }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { if (requestCode == FILECHOOSER_RESULTCODE) { // found this from StackOverflow if (null == mUploadMessage) return; Uri result = intent == null || resultCode != RESULT_OK ? null : intent.getData(); mUploadMessage.onReceiveValue(result); mUploadMessage = null; } else { // -----------I wrote this code below this line---------------------------------- jpegData = intent.getExtras().getByteArray("image"); Bitmap img = BitmapFactory.decodeByteArray(jpegData, 0, jpegData.length); Drawable d = new BitmapDrawable(img); profilePicture.setBackground(d); } }
/** Load the images into memory. */ public static void LoadImages(Context context) { if (images != null) { return; } images = new Bitmap[13]; Resources res = context.getResources(); images[2] = BitmapFactory.decodeResource(res, R.drawable.two); images[3] = BitmapFactory.decodeResource(res, R.drawable.three); images[4] = BitmapFactory.decodeResource(res, R.drawable.four); images[6] = BitmapFactory.decodeResource(res, R.drawable.six); images[8] = BitmapFactory.decodeResource(res, R.drawable.eight); images[9] = BitmapFactory.decodeResource(res, R.drawable.nine); images[12] = BitmapFactory.decodeResource(res, R.drawable.twelve); }
public MyView(Context context) { super(context); mBack = BitmapFactory.decodeResource(context.getResources(), R.drawable.family); mHandler.sendEmptyMessageDelayed(0, DELAY); }