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 6607091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:27:56+00:00 2026-05-25T19:27:56+00:00

I have this code void drawText2(Canvas c) { DisplayMetrics metrics = new DisplayMetrics(); Display

  • 0

I have this code

void drawText2(Canvas c)
    {       

        DisplayMetrics metrics = new DisplayMetrics();
        Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
        display.getMetrics(metrics);

        int screenwidth = metrics.widthPixels;
        int screenheight = metrics.heightPixels;



            Paint paint = new Paint();
            paint.setStyle(Paint.Style.FILL);
            paint.setColor(Color.BLACK);
            paint.setTextSize(150);
            paint.setAntiAlias(true);
            paint.setTypeface(Typeface.DEFAULT_BOLD);

            Bitmap.createBitmap(100, 100, Bitmap.Config.RGB_565);
            float x = screenwidth/2;
            float y = screenheight/2;
            c.drawText("32", x, y, paint);

    }

Which works fine, but if I add in the following line

Typeface GC=Typeface.createFromAsset(getAssets(),"fonts/ADarling.ttf");

as well as change the line

paint.setTypeface(Typeface.DEFAULT_BOLD);

to

paint.setTypeface(Typeface.create(GC, 0));

It will use the font and everything seems to be working fine, but randomly the wallpaper will go black, and stay that way for a few minutes then it will appear again, and will continue to do this. Am I using the code wrong?

  • 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-05-25T19:27:57+00:00Added an answer on May 25, 2026 at 7:27 pm

    Try to initialize the font once only(do not load it everytime drawText2() called)

    private Typeface myFont;
    
    
    public myConstructor() {  
        /* ... */  
        Typeface GC = Typeface.createFromAsset(getAssets(),"fonts/ADarling.ttf");  
        myFont = Typeface.create(GC, Typeface.NORMAL);
        /* ... */  
    }
    
    void drawText2(Canvas c)
        /* ... */  
        paint.setTypeface(myFont);
        /* ... */
    }
    

    Also the following line is not needed:

    Bitmap.createBitmap(100, 100, Bitmap.Config.RGB_565);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: void Main() { List<Employee> employeeList; employeeList = new List<Employee> {
I have this simple code: public void Run() { var invokerThread = new Thread(new
I have this C++ code: extern C __declspec(dllexport) VOID AllocateFoo(MY_DATA_STRUCTURE** foo) { *foo =
I have this code: - (void)viewDidLoad { [super viewDidLoad]; landscape.image = [UIImage imageNamed:@tenerife1.png]; }
I have this code - (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item What I am looking for
I have this code: void getStringWithTag(char* pFile, long sizeSound, char* tag, char* ret, float*
I have this source code: public static void FTP_SERVER() { FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftp://myurl.com/mainfolder/);
let's assume I have this snippet of the code: void foo_for_foo( void some_function(int, int))
everyone, I have this piece of the code: void foo(int var, int var1) {
So I have this code in my main activity to start a new one:

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.