How to save text writen on Canvas?

General topics about the Android-Platform itself.
Coding issues please to the subforum right below.

How to save text writen on Canvas?

Postby Manjusha » Mon Jul 26, 2010 7:08 am

Hi,
Actually i wanted to write some text on canvas and save that in jpeg format. I want to save that jpeg image in res or in Database.
Thanks...
Manjusha
Freshman
Freshman
 
Posts: 2
Joined: Fri Jul 23, 2010 8:27 am

Top

Re: How to save text writen on Canvas?

Postby midasmax » Tue Jul 27, 2010 12:54 am

A quick search on Google revealed this:
http://androidforums.com/android-develo ... rency.html

Code: Select all
Bitmap bitmap = Bitmap.createBitmap(width, height, Config.RGB_565);
        Canvas c = new Canvas(bitmap);
        c.drawColor(Color.TRANSPARENT);         
       
        Paint paint = new Paint();   
        paint.setTextSize(60);
        paint.setColor(Color.WHITE);
        c.drawText("Test", 100, 300, paint);
       
        ImageView iv = new ImageView(this);
        iv.setImageBitmap(bitmap);
        setContentView(iv);   
        try{
        File root = Environment.getExternalStorageDirectory();
        if (root.canWrite()){                                                           
            File f = new File(root, "TAG_test.png");
            FileOutputStream out = new FileOutputStream(f);
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
            out.close();
        }
        } catch (IOException e) {
            e.printStackTrace();
        }
midasmax
Junior Developer
Junior Developer
 
Posts: 15
Joined: Wed Jul 14, 2010 11:07 pm

Top

Return to General

Who is online

Users browsing this forum: No registered users and 3 guests