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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:29:47+00:00 2026-05-24T08:29:47+00:00

I’m learning android and java and am trying to learn how to make a

  • 0

I’m learning android and java and am trying to learn how to make a live wallpaper
I am using the aquarium tutorial, I put it all in one file instead of spreading it but what I am trying to do is get one scale number for everything, I want to get the height of the screen divide that by the background image height (which will always be bigger), this should give me a ratio to use for scaling everything, I tried this in a surfaceView code and it worked perfect, I tried it in livewallpaper and nada.
In the surfaceView test I use onSizeChange and got the height that way and it worked no problems.
This is what I did for the livewallpaper one
This is what I put for the onSurfaceChange

public int screenWidth;
public float rescaler;
public float totalHeight = theTemplate._backgroundImage.getHeight();

@Override
public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    //add rescale and width
    screenWidth = width;
    rescaler = (float) (height / totalHeight);
    super.onSurfaceChanged(holder, format, width, height);          
}

The background image comes from an inner class named TheTemplate
This is what I did there
The variables

private SpriteAnimationActivityEngine theTest;
private Bitmap theBackgroundImage;
private float theScaler = theTest.rescaler;

then I try and rescale it using theScaler

public void initialize(Context context, SurfaceHolder surfaceHolder) {
    this.spriteThread = new SpriteThread(this); 
    this._surfaceHolder = surfaceHolder;        
    this._sprites = new ArrayList<Renderable>();
    this._context = context;
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inPurgeable = true;
    this._backgroundImage = BitmapFactory.decodeResource(context.getResources(),ca.samsstuff.testonepagewallpaper.R.drawable.sky, options);
    this.theBackgroundImage = Bitmap.createScaledBitmap(_backgroundImage,  (int) (theScaler * _backgroundImage.getWidth()),  (int) (theScaler * _backgroundImage.getHeight()), true);
    this.addSprites();
}

Then it passes it to draw the background

private void renderBackGround(Canvas canvas) {
    canvas.drawBitmap(this.theBackgroundImage, 0, 0, null);
}

Which sends it to draw

protected void onDraw(Canvas canvas) {
    this.renderBackGround(canvas);              
    for (Renderable renderable : this._sprites) {
        renderable.render(canvas);
    }
}

I keep getting errors and don’t know what I am doing wrong. Like I said I am learning both android and java but this method worked in another test I did but I got the screen height from onSizeChange can I get the height by using onSurfaceChange?

Any help would be appreciated
Thanks in advance
sam

EDIT
I also tried to rescale within the theTemplate class just to see if it would work having everything within its own class and still having issues, I used the DisplayMetrics to get the screen height this time.
This might work if I can get it going properly.
Here is this attempt

public class TheTemplate {

        private SpriteThread spriteThread;  
        private SurfaceHolder _surfaceHolder;   
        private ArrayList<Renderable> _sprites; 
        public Bitmap _backgroundImage = BitmapFactory.decodeResource(getResources(), R.drawable.sky);;
        private Context _context;

        // add rescale stuff
        private Bitmap theBackgroundImage;
        private float theScaler = initFrameParams() / _backgroundImage.getHeight();
        private Bitmap oneBackImage = Bitmap.createScaledBitmap(_backgroundImage,  (int) (theScaler * _backgroundImage.getWidth()),  (int) (theScaler * _backgroundImage.getHeight()), true);

        int initFrameParams()
        {
                            //get the screen height to use to rescale everything
            DisplayMetrics metrics = new DisplayMetrics();
            Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
            display.getMetrics(metrics);

            int screenHeight = display.getHeight();
            return screenHeight;


        }


        public void render(){
            Canvas canvas = null;
            try{

                canvas = this._surfaceHolder.lockCanvas(null);
                synchronized (this._surfaceHolder) {
                    this.onDraw(canvas);
                }

            }finally{
                if(canvas != null){
                    this._surfaceHolder.unlockCanvasAndPost(canvas);
                }
            }   
        }

        protected void onDraw(Canvas canvas) {
            this.renderBackGround(canvas);              
            for (Renderable renderable : this._sprites) {
                renderable.render(canvas);
            }
        };

        public void start(){
            this.spriteThread.switchOn();
        }

        public void stop(){
            boolean retry = true;
            this.spriteThread.switchOff();
            while (retry) {
                try {
                 this.spriteThread.join();
                    retry = false;
                } catch (InterruptedException e) {
                    // we will try it again and again...
                }
            }
        }

        public int getLeft() {      
            return 0;
        }


        public int getRight() {
            return this.theBackgroundImage.getWidth();
        }

        public void initialize(Context context, SurfaceHolder surfaceHolder) {
            this.spriteThread = new SpriteThread(this); 
            this._surfaceHolder = surfaceHolder;        
            this._sprites = new ArrayList<Renderable>();
            this._context = context;
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inPurgeable = true;
            this.theBackgroundImage = oneBackImage;
            this.addSprites();
        }


        private void addSprites() {     
            Point startPoint = new Point(100, 100);
            this._sprites.add(new SpriteOne(this._context, this, startPoint, 90));
            Point startPoint1 = new Point(100, 300);
            this._sprites.add(new SpriteOne(this._context, this, startPoint1, 50));

            Point startPoint2 = new Point(200, 200);
            this._sprites.add(new SpriteOne(this._context, this, startPoint2, 15));
        }

        private void renderBackGround(Canvas canvas)
        {
            canvas.drawBitmap(this.theBackgroundImage, 0, 0, null);
        }
    }

As I stated before any help would be appreciated.
Thanks again in advance
Sam

Edit SOLVED Here is an answer I came up with, The rescale code is where the comments are
Hope this helps someone out.

public class TheTemplate {  

            private SpriteThread spriteThread;    
            private SurfaceHolder _surfaceHolder;     
            private ArrayList<Renderable> _sprites;     
            public Bitmap _backgroundImage = BitmapFactory.decodeResource(getResources(), R.drawable.sky);;  
            private Context _context;  

            // add rescale stuff  
            //private SpriteAnimationActivityEngine theTest;  
            private Bitmap theBackgroundImage;  
            private float totalHeight = _backgroundImage.getHeight();  
            private int screenSized = initFrameParams();  
            private float theScaler = (float) (screenSized / totalHeight);  

            private Bitmap oneBackImage = Bitmap.createScaledBitmap(_backgroundImage,  (int) (theScaler * _backgroundImage.getWidth()),  (int) (theScaler * _backgroundImage.getHeight()), true);  


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

                int screenHeight = display.getHeight();  
                return screenHeight;  
            }  


            public void render(){  
                Canvas canvas = null;  
                try{  

                    canvas = this._surfaceHolder.lockCanvas(null);  
                    synchronized (this._surfaceHolder) {  
                        this.onDraw(canvas);  
                    }  

                }finally{  
                    if(canvas != null){  
                        this._surfaceHolder.unlockCanvasAndPost(canvas);  
                    }  
                }     
            }  

            protected void onDraw(Canvas canvas) {  
                this.renderBackGround(canvas);                
                for (Renderable renderable : this._sprites) {  
                    renderable.render(canvas);  
                }  
            };  

            public void start(){  
                this.spriteThread.switchOn();  
            }  

            public void stop(){  
                boolean retry = true;  
                this.spriteThread.switchOff();  
                while (retry) {  
                    try {  
                     this.spriteThread.join();  
                        retry = false;  
                    } catch (InterruptedException e) {  
                        // we will try it again and again...  
                    }  
                }  
            }  

            public int getLeft() {        
                return 0;  
            }  


            public int getRight() {  
                return this.theBackgroundImage.getWidth();  
            }  

            public void initialize(Context context, SurfaceHolder surfaceHolder) {  
                this.spriteThread = new SpriteThread(this);   
                this._surfaceHolder = surfaceHolder;          
                this._sprites = new ArrayList<Renderable>();  
                this._context = context;  
                BitmapFactory.Options options = new BitmapFactory.Options();  
                options.inPurgeable = true;  
                this.theBackgroundImage = oneBackImage;  
                this.addSprites();  
            }  


            private void addSprites() {       
                Point startPoint = new Point(100, 100);  
                this._sprites.add(new SpriteOne(this._context, this, startPoint, 90));  
                Point startPoint1 = new Point(100, 300);  
                this._sprites.add(new SpriteOne(this._context, this, startPoint1, 50));  

                Point startPoint2 = new Point(200, 200);  
                this._sprites.add(new SpriteOne(this._context, this, startPoint2, 15));  
            }  

            private void renderBackGround(Canvas canvas)  
            {  
                canvas.drawBitmap(this.theBackgroundImage, 0, 0, null);  
            }  
        }  
  • 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-24T08:29:47+00:00Added an answer on May 24, 2026 at 8:29 am

    I added the answer to the original post, hope this helps someone.
    Sam
    Sorry about that folks, new to this method of using a forum
    Here is the answer, I added comments in the code where I made the changes for scaling images.
    This method can also be used for positioning also.
    Here is the answer.

     public class TheTemplate {  
    
            private SpriteThread spriteThread;    
            private SurfaceHolder _surfaceHolder;     
            private ArrayList<Renderable> _sprites;     
            public Bitmap _backgroundImage = BitmapFactory.decodeResource(getResources(), R.drawable.sky);;  
            private Context _context;  
    
            // add rescale stuff  
            //private SpriteAnimationActivityEngine theTest;  
            private Bitmap theBackgroundImage;  
            private float totalHeight = _backgroundImage.getHeight();  
            private int screenSized = initFrameParams();  
            private float theScaler = (float) (screenSized / totalHeight);  
    
            private Bitmap oneBackImage = Bitmap.createScaledBitmap(_backgroundImage,  (int) (theScaler * _backgroundImage.getWidth()),  (int) (theScaler * _backgroundImage.getHeight()), true);  
    
    
            int initFrameParams()  
            {  
                DisplayMetrics metrics = new DisplayMetrics();  
                Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();  
                display.getMetrics(metrics);  
    
                int screenHeight = display.getHeight();  
                return screenHeight;  
            }  
    
    
            public void render(){  
                Canvas canvas = null;  
                try{  
    
                    canvas = this._surfaceHolder.lockCanvas(null);  
                    synchronized (this._surfaceHolder) {  
                        this.onDraw(canvas);  
                    }  
    
                }finally{  
                    if(canvas != null){  
                        this._surfaceHolder.unlockCanvasAndPost(canvas);  
                    }  
                }     
            }  
    
            protected void onDraw(Canvas canvas) {  
                this.renderBackGround(canvas);                
                for (Renderable renderable : this._sprites) {  
                    renderable.render(canvas);  
                }  
            };  
    
            public void start(){  
                this.spriteThread.switchOn();  
            }  
    
            public void stop(){  
                boolean retry = true;  
                this.spriteThread.switchOff();  
                while (retry) {  
                    try {  
                     this.spriteThread.join();  
                        retry = false;  
                    } catch (InterruptedException e) {  
                        // we will try it again and again...  
                    }  
                }  
            }  
    
            public int getLeft() {        
                return 0;  
            }  
    
    
            public int getRight() {  
                return this.theBackgroundImage.getWidth();  
            }  
    
            public void initialize(Context context, SurfaceHolder surfaceHolder) {  
                this.spriteThread = new SpriteThread(this);   
                this._surfaceHolder = surfaceHolder;          
                this._sprites = new ArrayList<Renderable>();  
                this._context = context;  
                BitmapFactory.Options options = new BitmapFactory.Options();  
                options.inPurgeable = true;  
                this.theBackgroundImage = oneBackImage;  
                this.addSprites();  
            }  
    
    
            private void addSprites() {       
                Point startPoint = new Point(100, 100);  
                this._sprites.add(new SpriteOne(this._context, this, startPoint, 90));  
                Point startPoint1 = new Point(100, 300);  
                this._sprites.add(new SpriteOne(this._context, this, startPoint1, 50));  
    
                Point startPoint2 = new Point(200, 200);  
                this._sprites.add(new SpriteOne(this._context, this, startPoint2, 15));  
            }  
    
            private void renderBackGround(Canvas canvas)  
            {  
                canvas.drawBitmap(this.theBackgroundImage, 0, 0, null);  
            }  
        }  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to loop through a bunch of documents I have to put
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a text area in my form which accepts all possible characters from

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.