0

I currently have a few images (all 100x100 in dimension, very small) that are pulled from a MySQL DB server and displayed in my app. Everything works and behaves as I want. However, I noticed that when I share the images to WhatsApp, Messenger or other social media apps (I have buttons in my app that share the image) the images are blown up, as if they're too small to share so the social media apps resize them up - which pixelates the images since the original dimensions are 100x100.

In order to avoid the images being resized up I had an idea, but not sure if its possible or how to go about it. Would it be possible to place the original image onto a white canvas of 300x300 in dimensions during the share? This way the image will be 300x300 but with a white background and hopefully share properly without being resized up.

CardPreviewActivity

public class CardPreviewActivity extends AppCompatActivity {

BottomSheetLayout bottomSheetLayout;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.preview_activity);
    final SuperHero superHero = App.self.previewRequestedSuperHeroObject;
    // SET IMAGE
    ImageLoader imageLoader = CustomVolleyRequest.getInstance(this).getImageLoader();
    NetworkImageView heroPreviewImg = (NetworkImageView) findViewById(R.id.imageViewHero);
    heroPreviewImg.setImageUrl(superHero.getImageUrl(), imageLoader);

    // SET NAME
    TextView heroName = (TextView) findViewById(R.id.preview_super_hero_name);
    heroName.setText("Name: " + superHero.getName());

    // SET DIRECTLINK
    TextView heroDirectLink = (TextView) findViewById(R.id.preview_super_hero_directlink);
    heroDirectLink.setText("Direct link: " + superHero.getDirectLink());


    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setTitle(superHero.getName()); // set the top title

    bottomSheetLayout = (BottomSheetLayout) findViewById(R.id.bottomsheet);


    //SET SAVE SHARE BUTTON TEXT
    TextView heroName2 = (TextView) findViewById(R.id.btn_custom_view);
    heroName2.setText("Share " + superHero.getName());


}


<code>
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_custom_view:
                bottomSheetLayout.showWithSheetView(getLayoutInflater().inflate(R.layout.bottomsheet, bottomSheetLayout, false));
                break;


//            case R.id.btn_save_face:
//                break;

            case R.id.btn_share_face:


                ImageView imageView = (ImageView) findViewById(R.id.imageViewHero);
                Drawable mDrawable = imageView.getDrawable();
                Bitmap mBitmap = ((BitmapDrawable)mDrawable).getBitmap();

                String path = MediaStore.Images.Media.insertImage(getContentResolver(),
                        mBitmap, "face", null);

                Uri uri = Uri.parse(path);


                final SuperHero superHero = App.self.previewRequestedSuperHeroObject;
                String url = superHero.getImageUrl();
                String name = superHero.getName();


                final Intent shareIntent = new Intent(Intent.ACTION_SEND);
                shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
                shareIntent.setType("image/*");

                IntentPickerSheetView intentPickerSheetView = new IntentPickerSheetView(CardPreviewActivity.this, shareIntent, ("Share " + superHero.getName()), new IntentPickerSheetView.OnIntentPickedListener() {
                    @Override
                    public void onIntentPicked(IntentPickerSheetView.ActivityInfo activityInfo) {
                        bottomSheetLayout.dismissSheet();
                        startActivity(activityInfo.getConcreteIntent(shareIntent));
                    }
                });

                bottomSheetLayout.showWithSheetView(intentPickerSheetView);
                break;


            case R.id.btn_copy_direct_link:

                final SuperHero superHero2 = App.self.previewRequestedSuperHeroObject;

                ClipboardManager clipboard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
                ClipData clip = ClipData.newPlainText("face direct link", superHero2.getDirectLink());
                clipboard.setPrimaryClip(clip);
//                Toast.makeText(getApplicationContext(), ("Copied " + superHero2.getName() + " URL to the clipboard"), Toast.LENGTH_SHORT).show();
                bottomSheetLayout.dismissSheet();
                Snackbar.make(view, "Copied " + superHero2.getName() + "'s URL to the clipboard", Snackbar.LENGTH_LONG)
                        .setAction("Action", null)
                        .show();
                break;


            case R.id.btn_copy_direct_link_with_tags:

                final SuperHero superHero3 = App.self.previewRequestedSuperHeroObject;

                    ClipboardManager clipboard2 = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
                ClipData clip2 = ClipData.newPlainText("face direct link with image tags", ("[img]" + superHero3.getDirectLink() + "[/img]"));
                clipboard2.setPrimaryClip(clip2);
//                Toast.makeText(getApplicationContext(), ("Copied " + superHero3.getName() + " URL to the clipboard with IMG tags"), Toast.LENGTH_SHORT).show();
                bottomSheetLayout.dismissSheet();
                Snackbar.make(view, "Copied " + superHero3.getName() + "'s URL to the clipboard with IMG tags", Snackbar.LENGTH_LONG)
                        .setAction("Action", null)
                        .show();
                break;

        }
    }
    //Add back button to go back
    @Override
    public void onBackPressed() {
        super.onBackPressed();
        overridePendingTransition(R.anim.activity_back_in, R.anim.activity_back_out);
    }

    public boolean onSupportNavigateUp() {
        finish();
        overridePendingTransition(R.anim.activity_back_in, R.anim.activity_back_out);
        return true;
    }

     }
user3591436
  • 161
  • 2
  • 7
  • 19

1 Answers1

0

The easiest way to create such a bmp is to use Canvas.drawBitmap(). This method allows you to draw a bitmap on a canvas. So the solution is:

1) Create a canvas of the desired size with white background from (see this question for details).

2) Draw the bitmap on the center of the canvas using drawBitmap().

3) Use the output bmp to do the sharing.

Community
  • 1
  • 1
Doron Yakovlev Golani
  • 5,188
  • 9
  • 36
  • 60