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.

Why can't I add a image?

Featured Replies

Title^^

    @Override
    public void onPaint(Graphics2D g) {
    	Image bg = getImage("http://s9.postimg.org/5tbnkub0r/Namnl_st_1.png");
    	
    	g.drawImage(bg, 100, 100, null);
    }
    
    private Image getImage(String url) {
	    try
	    {
	      return ImageIO.read(new URL(url));
	    }
	    catch (IOException e) {}
	    return null;
    }

It doesn't show anything.

Title^^

    @Override
    public void onPaint(Graphics2D g) {
    	Image bg = getImage("http://s9.postimg.org/5tbnkub0r/Namnl_st_1.png");
    	
    	g.drawImage(bg, 100, 100, null);
    }
    
    private Image getImage(String url) {
	    try
	    {
	      return ImageIO.read(new URL(url));
	    }
	    catch (IOException e) {}
	    return null;
    }

It doesn't show anything.

 

What you are doing is a bad idea. onPaint is called many times per second, and in every loop you are re-getting the image from that url.

 

You should only get the image once and store it.

Edited by Explv

  • Author

What you are doing is a bad idea. onPaint is called many times per second, and in every loop you are re-getting the image from that url.

 

You should only get the image once and store it.

 

It didn't work sir.

    Image bg = getImage("http://s9.postimg.org/5tbnkub0r/Namnl_st_1.png");
    
    @Override
    public void onPaint(Graphics2D g) {   	
    	g.drawImage(bg, 100, 100, null);
    }
    
    private Image getImage(String url) {
	    try
	    {
	      return ImageIO.read(new URL(url));
	    }
	    catch (IOException e) {}
	    return null;
    }

 

Can anyone help me out? Appreciate it very much!

Edited by Ruzi

 

It didn't work sir.

    Image bg = getImage("http://s9.postimg.org/5tbnkub0r/Namnl_st_1.png");
    
    @Override
    public void onPaint(Graphics2D g) {   	
    	g.drawImage(bg, 100, 100, null);
    }
    
    private Image getImage(String url) {
	    try
	    {
	      return ImageIO.read(new URL(url));
	    }
	    catch (IOException e) {}
	    return null;
    }

 

 

 

You should really learn how to debug yourself. For starters, you are catching an Exception and never handling it. If you had printed out the exception by doing this:

 Image bg = getImage("http://s9.postimg.org/5tbnkub0r/Namnl_st_1.png");

    @Override
    public void onPaint(Graphics2D g){
        if(bg != null){
            g.drawImage(bg, 100, 100, null);
            System.out.println("Drawing image");
        }
    }

    private Image getImage(String url) {
        try
        {
            return ImageIO.read(new URL(url));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

You would have seen this displayed (in debug mode):

 

51af38f61d.png

 

The website returns a 403 response code (Forbidden error), most likely because it looks at the request headers and sees that you are not visiting this url from a web browser.

 

You can either reupload the image to a different site, or you can set the User-Agent in your Java code to be a browser's User-Agent like this:

Image bg = getImage("http://s9.postimg.org/5tbnkub0r/Namnl_st_1.png");

    @Override
    public void onPaint(Graphics2D g){
        if(bg != null){
            g.drawImage(bg, 100, 100, null);
            System.out.println("Drawing image");
        }
    }

    private Image getImage(String url) {
        try
        {
            URL imgUrl = new URL(url);
            URLConnection connection = imgUrl.openConnection();
            connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");
            return ImageIO.read(connection.getInputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

Which works.

Edited by Explv

  • Author

You should really learn how to debug yourself. For starters, you are catching an Exception and never handling it. If you had printed out the exception by doing this:

 Image bg = getImage("http://s9.postimg.org/5tbnkub0r/Namnl_st_1.png");

    @Override
    public void onPaint(Graphics2D g){
        if(bg != null){
            g.drawImage(bg, 100, 100, null);
            System.out.println("Drawing image");
        }
    }

    private Image getImage(String url) {
        try
        {
            return ImageIO.read(new URL(url));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

You would have seen this displayed (in debug mode):

 

51af38f61d.png

 

The website returns a 403 response code (Forbidden error), most likely because it looks at the request headers and sees that you are not visiting this url from a web browser.

 

You can either reupload the image to a different site, or you can set the User-Agent in your Java code to be a browser's User-Agent like this:

Image bg = getImage("http://s9.postimg.org/5tbnkub0r/Namnl_st_1.png");

    @Override
    public void onPaint(Graphics2D g){
        if(bg != null){
            g.drawImage(bg, 100, 100, null);
            System.out.println("Drawing image");
        }
    }

    private Image getImage(String url) {
        try
        {
            URL imgUrl = new URL(url);
            URLConnection connection = imgUrl.openConnection();
            connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36");
            return ImageIO.read(connection.getInputStream());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

Which works.

 

Thank you man! 

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.