Jump to content

[Solved]Is there a way to embed an online image in a gui


brandon3055

Recommended Posts

Title says it all. I recently added an information book to my mod that includes some tutorials which require images. But even at the lowest bearable resolution the image sizes are relatively large so i am just wondering if there is a way to use online images? Im guessing there isnt at least not without a lot of work but figured id ask anyway.

I am the author of Draconic Evolution

Link to comment
Share on other sites

If the problem is that the files are large, then "online" doesn't exactly help since they still have to be downloaded for viewing and local files would be faster than online.  However, I understand that you may not want to bloat the size of the mod file when it is distributed, so guess downloading the asset later might make sense.

 

I can think of a couple ways of doing this.

 

1) Open separate browser.  I think easiest is just have your GUI open a browser fully -- you can have a warning (not everyone likes having a mod open a browser) and if user clicks a button they are taken to your site with nice online tutorial.  To open a browser you can use standard Java method:

	    Desktop d=Desktop.getDesktop();

    // Browse a URL, say google.com
    try {
		d.browse(new URI("your url goes here"));
	} catch (IOException e) {
		e.printStackTrace();
	} catch (URISyntaxException e) {
		e.printStackTrace();
	}

 

2) there are ways to actually embed browsers into GUI, but you'd have to look up tutorial for that.

 

3) you can download the files during the mod loading and then access them like regular assets or skins.  This requires file management though and frankly I think could run into trouble in terms of handling cases like where the computer running the mod isn't online, or if the downloads are taking a long time.  You'd probably need to manage threads, files and online downloading -- all of which is quite possible but requires intermediate level of Java programming.

 

Overall remember that Minecraft is just Java -- so anything that can be done in Java can be done in Minecraft.  You can probably look up "display online graphic in my Java program" and get information to help.

 

But I personally recommend that you either go ahead and just include the images as regular assets, or if not that then open a regular browser.  Everything else is going to take some serious coding.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Sure there is.

Minecraft skins are textures that come from an online server. I suggest you look at the code for that.

 

Thanks i didnt think of that.

 

If the problem is that the files are large, then "online" doesn't exactly help since they still have to be downloaded for viewing and local files would be faster than online.  However, I understand that you may not want to bloat the size of the mod file when it is distributed, so guess downloading the asset later might make sense.

 

I can think of a couple ways of doing this.

 

1) Open separate browser.  I think easiest is just have your GUI open a browser fully -- you can have a warning (not everyone likes having a mod open a browser) and if user clicks a button they are taken to your site with nice online tutorial.  To open a browser you can use standard Java method:

	    Desktop d=Desktop.getDesktop();

    // Browse a URL, say google.com
    try {
		d.browse(new URI("your url goes here"));
	} catch (IOException e) {
		e.printStackTrace();
	} catch (URISyntaxException e) {
		e.printStackTrace();
	}

 

2) there are ways to actually embed browsers into GUI, but you'd have to look up tutorial for that.

 

3) you can download the files during the mod loading and then access them like regular assets or skins.  This requires file management though and frankly I think could run into trouble in terms of handling cases like where the computer running the mod isn't online, or if the downloads are taking a long time.  You'd probably need to manage threads, files and online downloading -- all of which is quite possible but requires intermediate level of Java programming.

 

Overall remember that Minecraft is just Java -- so anything that can be done in Java can be done in Minecraft.  You can probably look up "display online graphic in my Java program" and get information to help.

 

But I personally recommend that you either go ahead and just include the images as regular assets, or if not that then open a regular browser.  Everything else is going to take some serious coding.

 

The issue  is mod file size. As it is now the tutorial images take up around 70% of my mod and thats just 2 tutorials. Ideally i would like to download them once on first startup but i haven't even started to learn java file systems although it would be a good way to learn. I think i will just look at all the options you and diesieben gave me and figure out which works best for my situation.

 

Thanks for the replys!

I am the author of Draconic Evolution

Link to comment
Share on other sites

You can google "java download file" for a simple example, it's actually not that hard. The hardest part would be to get that file into the Minecraft resource system.

Already a step ahead of you.

 

This is what i have come up with keep in mind this code is just a proof of concept i will have to create a proper handler for it i just want to make sure there aren't any problems with it.

 

I am creating a new folder in the mods folder to store the images and i am getting the file path from the config file.

@Override
public void preInit(FMLPreInitializationEvent event) {

downloadLocation = event.getModConfigurationDirectory().getParentFile().getAbsolutePath() + "/mods/draconicevolution";
downloadLocation = downloadLocation.replaceAll("\\\\", "/");

File file = new File(downloadLocation);
if (!file.exists()) file.mkdir();

try {
	URL url = new URL("http://i.imgur.com/oHRx1yQ.jpg");
	String fileName = url.getFile();
	String destName = downloadLocation + fileName.substring(fileName.lastIndexOf("/"));

	InputStream is = url.openStream();
	OutputStream os = new FileOutputStream(destName);

	byte[] b = new byte[2048];
	int length;

	while ((length = is.read(b)) != -1) {
		os.write(b, 0, length);
	}

	is.close();
	os.close();
}catch (IOException e){
	LogHelper.info(e);
}

}

 

I am the author of Draconic Evolution

Link to comment
Share on other sites

Thanks

I wanted to use the absolute path because i will need that for the resource location when i go to use it but that brings me to another question. Is there a way to create resource location from a file path? From what i can tell there isnt so how would i bind the image? im guessing GL11 has a function for that?

 

Edit: Trying to figure out how the texture system works. It looks like using the texture is going to be a bit tricky unless there is another way to do it that i havent found yet.

I am the author of Draconic Evolution

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.