Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //this is how I assigned an image to image view
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data)
- {
- super.onActivityResult(requestCode, resultCode, data);
- if(requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data)
- {
- selected_image = data.getData();
- String[] filePath= {MediaStore.Images.Media.DATA};
- cursor = getContentResolver().query(selected_image, filePath, null, null, null);
- cursor.moveToFirst();
- int columnIndex = cursor.getColumnIndex(filePath[0]);
- String picturePath = cursor.getString(columnIndex);
- cursor.close();
- /*get width and height to rescaled*/
- original_image = BitmapFactory.decodeFile(picturePath);
- int width = original_image.getWidth();
- int height = original_image.getHeight();
- int newWidth = width / 2;
- int newHeight = height / 2;
- Log.i("Before Scale", "Width = " + width + ", Height = " + height);
- Log.i("After Scale", "Width = " + newWidth + ", Height = " + newHeight);
- /*scaling image*/
- BitmapFactory.Options image_size = new BitmapFactory.Options();
- original_image.recycle();
- imageUpload = Bitmap.createScaledBitmap(BitmapFactory.decodeFile(picturePath, image_size), newWidth, newHeight, false);
- baos = new ByteArrayOutputStream();
- if(original_image.isRecycled() == true)
- {
- Log.i("I", "True");
- }
- if(image.getDrawable() == null)
- {
- image.setImageBitmap(imageUpload);
- imageUpload.compress(Bitmap.CompressFormat.JPEG, 100, baos);
- image_data_1 = baos.toByteArray();
- encoded_image_1 = Base64.encodeBytes(image_data_1);
- }
- else if(image2.getDrawable() == null)
- {
- image2.setImageBitmap(imageUpload);
- imageUpload.compress(Bitmap.CompressFormat.JPEG, 100, baos);
- image_data_2 = baos.toByteArray();
- encoded_image_2 = Base64.encodeBytes(image_data_2);
- }
- else if(image3.getDrawable() == null)
- {
- image3.setImageBitmap(imageUpload);
- imageUpload.compress(Bitmap.CompressFormat.JPEG, 100, baos);
- image_data_3 = baos.toByteArray();
- encoded_image_3 = Base64.encodeBytes(image_data_3);
- }
- else if(image4.getDrawable() == null)
- {
- image4.setImageBitmap(imageUpload);
- imageUpload.compress(Bitmap.CompressFormat.JPEG, 100, baos);
- image_data_4 = baos.toByteArray();
- encoded_image_4 = Base64.encodeBytes(image_data_4);
- }
- else if(image5.getDrawable() == null)
- {
- image5.setImageBitmap(imageUpload);
- imageUpload.compress(Bitmap.CompressFormat.JPEG, 100, baos);
- image_data_5 = baos.toByteArray();
- encoded_image_5 = Base64.encodeBytes(image_data_5);
- }
- else if(image6.getDrawable() == null)
- {
- image6.setImageBitmap(imageUpload);
- imageUpload.compress(Bitmap.CompressFormat.JPEG, 100, baos);
- image_data_6 = baos.toByteArray();
- encoded_image_6 = Base64.encodeBytes(image_data_6);
- }
- }
- //remove image
- remove.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- if(image6.getDrawable() != null)
- {
- image6.setImageBitmap(null);
- image_data_6 = null;
- }
- else if(image5.getDrawable() != null)
- {
- image5.setImageBitmap(null);
- image_data_5 = null;
- }
- else if(image4.getDrawable() != null)
- {
- image4.setImageBitmap(null);
- image_data_4 = null;
- }
- else if(image3.getDrawable() != null)
- {
- image3.setImageBitmap(null);
- image_data_3 = null;
- }
- else if(image2.getDrawable() != null)
- {
- image2.setImageBitmap(null);
- image_data_2 = null;
- }
- else if(image.getDrawable() != null)
- {
- image.setImageBitmap(null);
- image_data_1 = null;
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment