Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

onPaint() Vs Buffered images - What is efficient?

Featured Replies

The aim is Efficiency, I am wondering what would put more stress on the program. Option 1 is using only 1 thread onPaint() but if that thread is constantly looping then it's actually a lot of code that can all be removed if you just used a BufferedImage However...

Using option 2 would also be re-placing the image over and over again, And i'm not exactly sure if that's being downloaded each looping cycle or it's being Cached naturally to the user. ( I'm not talking about syncing my resource file with the sdn, Im talking about when the script is on the SDN will the osbot client cache the image onto the Bot-Users personal Computer? Is that something I'll have to implement myself?

What is more memory/cpu intense?

  • Reloading an image each cycle
    or
  • changing font types, re-drawing rectangles and colors 10-20 times per loop



Option 1

@Override
	public void onPaint(Graphics2D g) {
g.setColor(new Color(34, 30, 73, 255));
          g.fillRect(0, 132, 84, 24);		// g.drawRect(x, y, width, height);
          g.fillRect(0, 182, 84, 24);		// g.drawRect(x, y, width, height);
          g.fillRect(0, 232, 60, 24);		// g.drawRect(x, y, width, height);
	g.setFont(new Font("Trebuchet MS", Font.BOLD, 14));
		g.setColor(new Color(255, 209, 102));
          g.drawString("XP Gained", 3, 129);
          g.drawString("XP P/hour", 3, 179);
          g.drawString("Lvls Gained", 3, 229);	
    }



Option 2

    BufferedImage background;
    @Override
    public void onStart(){
        try{
            background = ImageIO.read(Main.class.getResourceAsStream("/resources/background.png"));
        } catch(IOException e){
            log(e);
        }
    }

    @Override
    public void onPaint(Graphics2D g){
        if(background != null){
            g.drawImage(background, null, x, y);
        }
    }
}


Thanks for all your answers
            :gnome: wtf these Icons are to big lmao?

Edited by Elixar

The first function uses higgghly optimized draw functions to create the rectangle, and uses less memory as your image would require to be stored in OldGen and never be collected by the garbage collector. It's by far more efficient then drawing an image. Both are still very efficient however and wont make a noticeable performance impact on your script. 

As for your second question regarding option 2. "Main.class.getResourceAsStream("/resources/background.png")" is grabbing your "background.png" directly from the loaded jar. It is not downloading anything that wasn't already streamed to the client. So in terms of "cacheing" it, it already exists in memory and therefor I guess you could say it's cached. 

 

Tl;Dr: Use BufferedImage if you'd like to create a more advanced/pretty background using an image. Use Option 1 if you just want something very fast, with little to no memory overhead. Either way, both are very efficient. 

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.