Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8589097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:57:54+00:00 2026-06-11T22:57:54+00:00

I am drawing rotated text on canvas and then saving it to SD card

  • 0

I am drawing rotated text on canvas and then saving it to SD card as JPEG.
The problem I am facing is the canvas preview looks fine, but the rotated text in the saved image is not coming properly. When I use the default Android fonts, the final JPEG is the same as the canvas preview, but this code doesn’t work for a custom typeface.

I have uploaded both the final saved image and screenshot of canvas preview

I am using a custom view class for canvas drawing, here is my code

public class MyBringBack extends View {


    Bitmap bitmap;
    Typeface type;

public MyBringBack(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
        type = Typeface.createFromAsset(context.getAssets(),"fonts/rockwell-bold.ttf"); 
         setDrawingCacheEnabled(true);
    }


@Override
protected void onDraw(Canvas canvas) {
        // TODO Auto-generated method stub
        super.onDraw(canvas);



    Paint paint = new Paint();
        paint.setColor(Color.BLUE);
       // paint.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
        paint.setTextSize(23);
    Paint paint1 = new Paint();
        paint1.setTextSize(40);
        paint1.setColor(Color.RED);

        canvas.rotate(90,434,110);
        canvas.drawText("Demo Text Demo Text Demo Text  ", 434, 110, paint);
        canvas.restore();
        canvas.save();
        paint1.setTypeface(type);
        canvas.rotate(90,130,185);
        canvas.drawText("Text using Typeface ", 130, 185, paint1);
        canvas.restore();
        canvas.save();
        canvas.rotate(90,180,185);
        canvas.drawText("Text using Typeface ",180, 185, paint1);
        canvas.restore();
        canvas.save();
        canvas.rotate(90,230,185);
        canvas.drawText("Text using Typeface ", 230, 185, paint1);
        canvas.restore();
        canvas.save();

        this.setDrawingCacheEnabled(true);
        Bitmap c= Bitmap.createScaledBitmap(this.getDrawingCache(), canvas.getWidth(),canvas.getHeight(), false);

        /* Saving File To SD Card   */

        OutputStream outStream = null;
        File bgv = new File("/sdcard/");
        /* To build directory if needed */
        bgv.mkdirs();

        File file = new File(bgv, "final22.jpg");

        try {
        outStream = new FileOutputStream(file);
        c.compress(Bitmap.CompressFormat.JPEG, 100, outStream);

        outStream.flush();
        outStream.close();

      } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();

       } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
       }

    }

}

Is there is any problem with my code?

Please help…

thanks in advance 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T22:57:56+00:00Added an answer on June 11, 2026 at 10:57 pm

    Finally after lots of research on image processing i got my answer.
    For Saving the jpg exactly same as what is drawn on canvas we have to add just two line of code.
    First is :

    setDrawingCacheQuality(DRAWING_CACHE_QUALITY_HIGH);

    and second in onDraw we have to set AntiAlias to true,refering to my code

    paint1.setAntiAlias(true);
    

    But after this also the saved image is not of same quality that of what is drawn on canvas.
    to get the same crisp quality of image this two code will do the trick

    paint1.setDither(true);
    paint1.setFilterBitmap(true);
    

    Dither mainly provide smooth corners,AntiAlias,Dither and FilterBitmap can also be used while drawing Bitmap on canvas.

    To get more information about Dither and AntiAlias here is the link

    AntiAlias

    Dither

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So my problem lies as this. Im drawing polys in canvas using javascript. Im
I'm having problems with drawing rotated images on PDF, my output is worse. My
I am trying to use DrawString to write text as an image and then
An iPhone SDK question: I'm drawing a UIImageView on the screen. I've rotated it
I am developing an iPad application which is basically a big drawing canvas with
I'm using some code to enable me to render rotated text with the TextRenderer.DrawText
I want to draw some text in a view, rotated 90°. I'm pretty new
I am drawing an image from MetaFile (emf) and then apply some rotation transformations
I'm currently working on drawing vertical Chinese text in a label. Here's what I
I need to clear a rotated rectangle and draw it again on a canvas,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.