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.

Anyone got the code for GetImage?

Featured Replies

I had it but I lost the snippet for getting an image from URL and putting it into onPaint :(

I had it but I lost the snippet for getting an image from URL and putting it into onPaint sad.png

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

Method

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

You should return BufferedImage not Image

 

why is bufferedImage better for scripting than just using an Image?

why is bufferedImage better for scripting than just using an Image?

 

deleted answer

 

 

Ignore the stupid shit I said :doge:

Edited by Explv

Image is the superclass for all Image classes.

BufferedImage extends Image and is what you want to use when drawing.

ImageIO.read();

returns a BufferedImage, therefore your getImage() method should also return a BufferedImage.

 

You should promote loose coupling where you can.

 

The majority of image drawing methods in Graphics2D (mostly inherited from Graphics) take Image, as they do not require any specific methods located in BufferedImage. For this reason, returning Image is the less restrictive option.

Saying that people should return BufferedImage just because that's the specific implementation of the Image is pretty much your own preference. Would you also use LinkedList or ArrayList as a return type rather than List? It's fine if you do, but at least when writing API for others to use, you should use the highest level class or interface you can.

 

Also to add to the 3 (identical) previous answers; some image hosts may have browser checks to prevent automated use. This can be bypassed by adding the User-Agent property.

	public static Image loadImageByURL(String surl) {
		Image img = null;
		try {
			URL url = new URL(surl);
			URLConnection urlc = url.openConnection();
			urlc.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
			img = ImageIO.read(urlc.getInputStream());
		} catch (IOException ex) {
			Logger.getLogger(ResourceLoader.class.getName()).log(Level.SEVERE, null, ex);
		}
		return img;
	}

Edited by FrostBug

 

You should promote loose coupling where you can.

 

The majority of image drawing methods in Graphics2D (mostly inherited from Graphics) take Image, as they do not require any specific methods located in BufferedImage. For this reason, returning Image is the less restrictive option.

Saying that people should return BufferedImage just because that's the specific implementation of the Image is pretty much your own preference. Would you also use LinkedList or ArrayList as a return type rather than List? It's fine if you do, but at least when writing API for others to use, you should use the highest level class or interface you can.

 

 

You are right, I wasn't thinking about the drawImage methods in Graphics. :facep:

  • Author

 

You should promote loose coupling where you can.

 

The majority of image drawing methods in Graphics2D (mostly inherited from Graphics) take Image, as they do not require any specific methods located in BufferedImage. For this reason, returning Image is the less restrictive option.

Saying that people should return BufferedImage just because that's the specific implementation of the Image is pretty much your own preference. Would you also use LinkedList or ArrayList as a return type rather than List? It's fine if you do, but at least when writing API for others to use, you should use the highest level class or interface you can.

 

Also to add to the 3 (identical) previous answers; some image hosts may have browser checks to prevent automated use. This can be bypassed by adding the User-Agent property.

	public static Image loadImageByURL(String surl) {
		Image img = null;
		try {
			URL url = new URL(surl);
			URLConnection urlc = url.openConnection();
			urlc.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
			img = ImageIO.read(urlc.getInputStream());
		} catch (IOException ex) {
			Logger.getLogger(ResourceLoader.class.getName()).log(Level.SEVERE, null, ex);
		}
		return img;
	}

 

 

@FrostBug are.....are you a wizard?

p.s. I thought @Explv was a wizard before, but he just got WIZARDED wtfffff

Edited by Paradox68

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.