Jump to content

Paint Causes Lag


whipz

Recommended Posts

Hey guys I have found that this bit of code causes a heap of lag anyone able to help with the lag issue ?

 

public void onPaint(Graphics2D gr) {
		try {
			image = ImageIO.read(new URL(
					"http://i1285.photobucket.com/albums/a589/whipz/EA1C0CF0C2DDBCB04C0258B8960138B33A6C1292DB3DF36762pimgpsh_fullsize_distr_zpsdo2x7ou1.jpg"));
		} catch (IOException e) {
			e.printStackTrace();
		}
		gr.drawImage(image, 4, 342, null);
		final long runTime = System.currentTimeMillis() - startTime;
		int x = getMouse().getPosition().x;
		int y = getMouse().getPosition().y;
		gr.drawLine(0, y, 765, y);
		gr.drawLine(x, 0, x, 503);
		gr.drawString(formatTime(runTime), 125, 375);
		gr.drawString("", 125, 390);
		gr.drawString("" + getSkills().getStatic(Skill.COOKING), 125, 405);
		gr.drawString("" + getExperienceTracker().getGainedLevels(Skill.COOKING), 125, 420);
		gr.drawString("" + formatValue(getExperienceTracker().getGainedXP(Skill.COOKING)), 125, 435);
		gr.drawString("" + formatValue(getExperienceTracker().getGainedXPPerHour(Skill.COOKING)), 125, 450);
		gr.drawString("" + formatValue(getSkills().experienceToLevel(Skill.ATTACK)), 125, 465);
	}

Yet this doesnt so its obviously the image but how can i reduce the lag as it causes the script to almost not move

this is code with no lag

	public void onPaint(Graphics2D gr) {
		final long runTime = System.currentTimeMillis() - startTime;
		int x = getMouse().getPosition().x;
		int y = getMouse().getPosition().y;
		gr.drawLine(0, y, 765, y);
		gr.drawLine(x, 0, x, 503);
		gr.drawString(formatTime(runTime), 125, 375);
		gr.drawString("", 125, 390);
		gr.drawString("" + getSkills().getStatic(Skill.COOKING), 125, 405);
		gr.drawString("" + getExperienceTracker().getGainedLevels(Skill.COOKING), 125, 420);
		gr.drawString("" + formatValue(getExperienceTracker().getGainedXP(Skill.COOKING)), 125, 435);
		gr.drawString("" + formatValue(getExperienceTracker().getGainedXPPerHour(Skill.COOKING)), 125, 450);
		gr.drawString("" + formatValue(getSkills().experienceToLevel(Skill.ATTACK)), 125, 465);
	}

Thanks for any help or suggestions

 

Link to comment
Share on other sites

Just now, Vilius said:

You need to cache the image rather than reading it over and over from a website. Load the image and set it to an object in the onStart method.

so this in onStart ? 

try {
			image = ImageIO.read(new URL(
					"http://i1285.photobucket.com/albums/a589/whipz/EA1C0CF0C2DDBCB04C0258B8960138B33A6C1292DB3DF36762pimgpsh_fullsize_distr_zpsdo2x7ou1.jpg"));
		} catch (IOException e) {
			e.printStackTrace();
		}

 

Link to comment
Share on other sites

  • Decode locked this topic
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...