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.

Cropping an image to a percentage?

Featured Replies

What im aiming for is similar to below :

332nr40.jpg

 

1 image - but the total width is cropped depending on the percentage.

 

i have percent to next level as so.

 

percentTNL = ((currentXp - currentLevelXp) / (nextLevelXp - currentLevelXp) * 100);

 

But i dont know how to crop the image to have the percent age D:

 

Sorry for being a nub :3

Edited by Fruity

Is it possible to have the image move to the right and just have the left side covered by something else? I feel like this might be the best option as dynamic resizing or cropping may be a little tough.

g.drawRectangle(x,y,width,height);

                                 ^

                          percentTNL

 

or something along this line... I know it doesn't do exactly what you wanted, but it's much easier.

Edited by blabla123

try this

 

Rectangle bounds = new Rectangle(Whatever bounds you want to crop to on the game screen);

int dx1 = bounds.x;

int dy1 = bounds.y;

int dx2 = bounds.x + bounds.width;

int dy2 = bounds.y + bounds.height;

int sx2 = bounds.width;

int sy2 = bounds.height;

g.drawImage(image, dx1, dy1, dx2, dy2, 0, 0, sx2, sy2, null, null);

 

You can calculate the bounding rectangle by having a pre-defined "full" (100%) rectangle, and transform its width according to your percentage variable.

Edited by FrostBug

You can work out the appropriate width like so:

int onePercentImage = (int)(image.width / 100);
int imageWidth = (onePercentImage * percentTNL);
  • Author

try this

 

Rectangle bounds = new Rectangle(Whatever bounds you want to crop to on the game screen);

int dx1 = bounds.x;

int dy1 = bounds.y;

int dx2 = bounds.x + bounds.width;

int dy2 = bounds.y + bounds.height;

int sx2 = bounds.width;

int sy2 = bounds.height;

g.drawImage(image, dx1, dy1, dx2, dy2, 0, 0, sx2, sy2, null, null);

 

You can calculate the bounding rectangle by having a pre-defined "full" (100%) rectangle, and transform its width according to your percentage variable.

 

Thank you this worked :)<3

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.