Jump to content
John Kouraklis

Where do I store my own images on Android?

Recommended Posts

Hi,

can anyone help me with this?

Where am I supposed to store my images on Android?

I use the deployment manager to store them in "res\drawable-xxx" but my app does not find it.

 

How do I access the folder from the binary file? I mean, would that be "res\drawable-xxx" or "..\res\drawable-xxx"?

 

Thanks

Share this post


Link to post
Maby this way work for you?
(uses System.IOUtils)
AppPath := TPath.GetHomePath;
FileName := TPath.Combine(AppPath, 'Filename.ext');

 

Edited by KodeZwerg
  • Like 1

Share this post


Link to post

Is there an issue with using GetDocumentsPath (which in the deployment manager for Android translates to assets/internal), or subfolders thereof?

 

Alternatively, use KodeZwerg's solution. GetHomePath in deployment manager translates to ., i.e. the root

Share this post


Link to post

Alternatively, you can store your images as resources (project / resources and images) and then use this function to load the images from the resource:
 

procedure LoadImageFromResource(ResourceName : String; TargetBitmap : TBitmap);
var
  rStream   : TResourceStream;
begin
  If TargetBitmap <> nil then
  Begin
    Try
      rStream := TResourceStream.Create(hInstance,ResourceName,RT_RCDATA);
    Except
      rStream := nil
    End;
    if rStream <> nil then
    Begin
      Try
        TargetBitmap.LoadFromStream(rStream);
      Finally
        rStream.Free;
      End;
    End;
  End;
end;

That way you don't care about paths.

Share this post


Link to post

I know all these approaches (the link, the resources and using getDocumentPath)

 

@Dave Nottage: But this is not the recommended way by Android. I am concerned if those approaches are safe.

 

@Yaron: Is this appropriate way for apps with big number of images? 

 

Share this post


Link to post

@John Kouraklis I guess it really depends on how the images are used.   I use the resource approach where the images are elements in my UI (buttons, sprites, etc).

Unlike windows which places all the resources in the executable, if you look into the installation folder on Android, you'll see that all the resource files are in their own folder as actual files, so the resource function is just re-routing to these files.

 

I also use a caching mechanism in my apps where the images are scaled in high quality to the UI resolution and then saved uncompressed to speed up future loads.

  • Like 1

Share this post


Link to post
9 minutes ago, Yaron said:

Unlike windows which places all the resources in the executable, if you look into the installation folder on Android, you'll see that all the resource files are in their own folder as actual files, so the resource function is just re-routing to these files.

@Yaron That was my concern TBH---a huge file like in Win

 

10 minutes ago, Yaron said:

I also use a caching mechanism in my apps where the images are scaled in high quality to the UI resolution and then saved uncompressed to speed up future loads.

I recall a similar discussion somewhere else. 🙂

 

You mean the original file in the resources is in high-res and then you scale it down to meet the screen resolution, right? and then you store this in a cache directory

Share this post


Link to post

I use this code for the paths, it works for both Windows and Android

  UserDataPath          := System.IOUtils.TPath.GetHomePath+System.IOUtils.TPath.DirectorySeparatorChar+clientName+System.IOUtils.TPath.DirectorySeparatorChar;
  cacheFolder           := 'cache'+System.IOUtils.TPath.DirectorySeparatorChar;

 

With regards to the UI, yes, I use high resolution source images so the same app will work on any resolution display and maintain a sharp & crisp image.

 

Delphi does a real bad job at high quality image downscaling, but after a year of banging my head against the wall with multiple down-votes and even after offering a bounty on stackoverflow, I finally found a method that will scale the image in high quality using hardware on Android which I posted here:

https://stackoverflow.com/questions/52989024/low-quality-delphi-user-interface-design-under-android-when-using-timage

 

If you want to see how bad Delphi's GPU canvas is by default, look at this post:
https://stackoverflow.com/questions/51157715/low-quality-downscale-interpolation-when-using-a-gpu-canvas-and-tcanvas-drawbitm

 

Share this post


Link to post

You could consider to use

System.IOUtils.TPath.Combine(path1, path2);

to get rid of the

TPath.DirectorySeparatorChar

Share this post


Link to post
On 11/13/2018 at 8:43 AM, Rollo62 said:

You could consider to use


System.IOUtils.TPath.Combine(path1, path2);

 

Yes--that's the recommended way. I can't remember where I read it but Combine takes care any leading slashes based on the OS

Share this post


Link to post

Target: Android, in Deployment windows, if you add your file to remote path: .\assets\internal\, in delphi, you can access it at TPath.GetDocumentsPath.

 

if you have a big number of picture, I suggest you should store it in a SQLite database. When you release you APP, release one file is better than many many files.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×