0

I have to make a printable business card as shown in attached image and attach to an email in the form of .png image. I have no idea how I will be making this image in android and attach it to email in .png format

enters the image description here

on Button click.For your reference I have attached an image of that card over here. Thanks for viewing my post..

Arjun saini
  • 4,223
  • 3
  • 23
  • 51
Tulika Kansal
  • 57
  • 1
  • 8

2 Answers2

2

One way you can do this is make that card into a layout and then fill it in or let the user fill it in (whichever). And then you can use the following piece of code to turn the view into a Bitmap

public Bitmap viewToBitmap(View view) {
    Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    view.draw(canvas);
    return bitmap;
}

Code is from this question here,

Convert frame layout into image and save it

Community
  • 1
  • 1
wanpanman
  • 378
  • 3
  • 10
1

Try following code

File filePath = new File("/path/file.png");
Uri uri = Uri.fromFile(filePath);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/png");
intent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(intent,"Email:"));
Ajit
  • 724
  • 7
  • 16
  • this thing i know ..my requirement is to make this image dynamically and fill all the detail from program like user image ,user name etc.. – Tulika Kansal Jun 28 '16 at 13:22
  • @TulikaKansal Simple, take screenshot of device programatically on share button then use above code to share the same. http://stackoverflow.com/questions/2661536/how-to-programmatically-take-a-screenshot-in-android – Ajit Jul 04 '16 at 05:02
  • my layout for is image is not attached to any activity and also i need device independent image i mean of fixed height and width like of visting card . how can i get it done ??\ – Tulika Kansal Jul 05 '16 at 05:42
  • @TulikaKansal in your first comment, You said you need to make image (card) dynamically, how you will make this, I think there is only one way to make such layout. Please correct me. For this device independent, you can make your own custom layout – Ajit Jul 05 '16 at 05:48
  • yes my friend i made my custom layout with a fixed hard coded height and width.and then i used layout inflater to convert that xml file in to java view object as – Tulika Kansal Jul 05 '16 at 05:54
  • ok grt , One thing dont pass harcoded height and width, use wrap content or fill parent, then programmatically take screen shot. – Ajit Jul 05 '16 at 06:02
  • if fixed height/widht is required, then pass as per screen widht /height as per calculation – Ajit Jul 05 '16 at 06:02
  • LayoutInflaterinflater(LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);View view =inflater.inflate(R.layout.emergency_card,null,false); Bitmap bitmap = Bitmap.createBitmap(200, 200, Bitmap.Config.ARGB_8888);Canvas canvas = new Canvas(bitmap) view.draw(canvas); FileOutputStream output = new FileOutputStream("file.png"); bitmap.compress(Bitmap.CompressFormat.PNG, 100, output);output.close();but it is returning me a blank image. – Tulika Kansal Jul 05 '16 at 06:03
  • dear if i will we using match parent for width then as text in design is large so it is not going to come on single line – Tulika Kansal Jul 05 '16 at 06:05