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

  • SEARCH
  • Home
  • 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 8096329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:25:15+00:00 2026-06-05T21:25:15+00:00

I am developing an app which draws more or less a two-dimensional matrix of

  • 0

I am developing an app which draws more or less a two-dimensional matrix of values to a canvas. The values of this matrix are scaled to Alpha levels to illustrate intensity, and the coordinates for the matrix are simply extrapolated from row and column indexes. Below is my onDraw routine.

public void onDraw(Canvas canvas, float [][] spectrum, float nsegs,int seglen) {

    //canvas.translate(0,0);
    //alpha = 0;


    int canHeight = canvas.getHeight();
    int canWidth = canvas.getWidth();


    //float[] array = generateData(512);
    float [] spec = new float[seglen];

    final float bw = (float)(canWidth-2)/nsegs;
    final float bh = (float)(canHeight-2)/(float) seglen;

    for (int i = 0;i<seglen;i++){
        spec[i] = spectrum[i][index];   // One column at a time

    }

    float max = maxVal(spec);
    float min = minVal(spec);

    xcoor = index;
        for (int n = 0; n < seglen; n++){ 


            //Scale value to alpha (0-255)
            alpha =(int)Math.round((((spec[n] - min)/max)*255.0));

            ycoor = n;
            paint.setAlpha(alpha);

            canvas.drawPoint(xcoor,ycoor, paint);


        }

        index = (int) (index +1);
    if (index == nsegs-1){
        index = 0;

    }

}

Here paint configuration is pre-defined as:

            Paint   paint = new Paint();
            paint.setStyle(Paint.Style.FILL);
    paint.setColor(Color.WHITE);
    paint.setStrokeWidth(2);

This program draws one pixel at a time, fills one column of pixels equal to the number of elements in a column of the matrix. Then it starts on the next column, where the previous column is still displayed and so forth. At this stage when all columns are full it stars from the first column again, drawing on top of previous elements.

The Problem: The tailing columns although already drawn appear to flicker and jump around, as does the Alpha. I have attempted to canvas.save() and canvas.restore() to capture the entire canvas and restore it after a column is printed. I have double checked all my row and column indexing and alpha vales to ensure the coordinates increment as per desired (and they do). This is very similar to the sample APIdemo DrawPoints.java, however there are three primary differences.

  1. I am using DrawPoint not DrawPoints, and
  2. I don’t use “canvas.setColour” as it removes the tailing columns from the canvas.
  3. This onDraw function is operating in a Thread which extends SurfaceView

Any idea’s would be much appreciated, thank you for your time.

  • 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-05T21:25:17+00:00Added an answer on June 5, 2026 at 9:25 pm

    In the case above, I was using a SurfaceView instead of a View. Out of the Android dev docs

    Note: On each pass you retrieve the Canvas from the SurfaceHolder, the previous state of the Canvas will be retained. In order to properly animate your graphics, you must re-paint the entire surface. For example, you can clear the previous state of the Canvas by filling in a color with drawColor() or setting a background image with drawBitmap(). Otherwise, you will see traces of the drawings you previously performed.

    The Solution, re-draw the entire canvas each time to prevent the jitter.

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

Sidebar

Related Questions

I'm currently developing an app which uses the built-in Camera. I call this snippet
Currently I'm developing an Android app which draws a point on the coordinates input
I'm developing an app which downloads a json objects into database,this is done so
I am developing an app which has 9 image views in a 3x3 matrix.
Hello I am developing an app which is using a tableview with two sections(instead
I'm developing this app which as a very basic Ajax form and I'm currently
I'm developing an app in which a graph is drawn using coreplot. When I
Im developing an App which is going to be used on Samsung Galaxy SII
I'm developing an app which has a large amount of related form data to
I am developing an app which requires the phone to ring or make some

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.