- Home /
Image Gallery
Hello everyone I would like to create a photo gallery in my android app. to reduce the size of the app I wish the pictures were downloaded from the Internet, but do not know which method to use. I have to create a database? I have to implement a server? help me please
What plattform are you targeting? Where and how are the images stored?
This question as it is now, is to broad to be answered.
You're right, I'm sorry. I'm building an android app. To give you an example, I would like to create a photo gallery like that of the famous app "Backrounds HD" or any other app that provides backgrounds. I want to know what are the alternatives and what are their advantages and disadvantages.
Answer by chillersanim · Mar 29, 2016 at 12:03 PM
You could use a web server running either a database or hosting the images directly.
Alternative, if the images are already available in the internet, you could use a table with all image urls you want to include.
Database:
The advantage of using a database is that you've got more control over the images available and you can store additional information.
Direct storage:
Storing the images directly on the server is easier, as you can just use the WWW class.
User costs:
Be aware that in either case, the user needs internet connection, and in the case of mobile development, downloading images can cost the user lots of MB on his phone abonement.
Caching:
If you are okay with using lot's of space AFTER the user installed the app, you could also download all images and store them on the disk.
Or, you could only store images which the user already viewed to prevent downloading the same image mutliple times.
Greetings
Chillersanim
Answer by OmerDoron · Jan 19, 2017 at 08:12 AM
@veleno94 I made this for my project, kind of what you need (ignore "book" variables, it`s specific for my project).
Flow: Check if file exists (change the path to your path), if exists, open the file (this way you`d have to download it only the first time and not every time). if it`s not exist, download the file.
using UnityEngine;
using System.Collections;
public class OnPressingPictureButton : MonoBehaviour {
public int currentPage;
public string [] imageURL;
public Book book;
public GameObject loading;
// Update is called once per frame
void Update () {
currentPage = book.page;
}
void OnMouseDown ()
{
loading.SetActive (true); //@@@ "Loading ON"
//Checking if the file exists in the users device
if (System.IO.File.Exists (Application.persistentDataPath + "/image"+currentPage.ToString()+".jpg"))
{
//if yes, open it
loading.SetActive (false);
Application.OpenURL (Application.persistentDataPath + "/image"+currentPage.ToString()+".jpg");
}
//if not, download it
else {
StartCoroutine (TestDownload (imageURL [currentPage]));
}
}
private IEnumerator TestDownload (string uRL)
{
WWW www = new WWW (uRL);
yield return www;
while (!www.isDone) {
Debug.Log (www.progress);
yield return null;
}
string savePath = Application.persistentDataPath + "/image"+currentPage.ToString()+".jpg";
byte[] bytes = www.bytes;
System.IO.File.WriteAllBytes (savePath, bytes);
loading.SetActive (false); //@@@ "Loading OFF"
Application.OpenURL (savePath);
}
}
Your answer
Follow this Question
Related Questions
Players online counter 1 Answer
Remote database for leaderboard 2 Answers
Best way to connect to database for my mobile game? 3 Answers
[Closed] www.data help 0 Answers
How can I show image from server ? 0 Answers