Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4324910
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:11:46+00:00 2026-05-21T09:11:46+00:00

I am trying to load images so I can use them as textures. I

  • 0

I am trying to load images so I can use them as textures. I have libpng, but how do find a path to an image? Is it a bad idea to put it into .apk? Is there a better way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T09:11:47+00:00Added an answer on May 21, 2026 at 9:11 am

    It appears there are two ways of doing it. I can either do what Simon N. has suggested or I can convert the images into a C Array and compile them into the source. I choose to do the latter as I can do it easily on the native side. I have even created a python (v3.2) for converting a png file to a c array header and source file. It requires PyPNG

    #!/usr/bin/env python
    
    import png
    import re
    import itertools
    
    def grouper(n, iterable, fillvalue=None):
        args = [iter(iterable)] * n
        return itertools.zip_longest(fillvalue=fillvalue, *args)
    
    def expand(array):
        new_array = [];
        for row in array:
            for v in row:
                new_array.append(v)
        return new_array
    
    def c_array_name(filename):
        '''converts the filename to the c array name'''
        return re.sub(r'\W', '_', filename)
    
    def c_array_header_filename(filename):
        '''converts the filename to the c array header filename'''
        return "{0}.h".format(filename)
    
    def c_array_source_filename(filename):
        '''converts the filename to the c array source filename'''
        return "{0}.cpp".format(filename)
    
    def c_array_header(filename):
        '''returns a string that is the c array header,
        where
            filename is the png file'''
        name = c_array_name(filename)
        return """
    #ifndef __{0}__
    #define __{0}__
    
    #include <stdint.h>
    
    extern uint_least32_t const {1}[];
    
    #endif /* __{0}__ */
    """.format(name.upper(), name)
    
    def c_array_source(filename, header_filename, array_string):
        '''returns a string that is the c array source,
        where
            name is the value from c_array_name
            array_string'''
        name = c_array_name(filename)
        return """
    #include "{0}"
    
    uint_least32_t const {1}[] = {{
    {2}
    }};
    """.format(header_filename, name, array_string)
    
    def convert_data_array_string(data):
        '''returns a string of hexes of bytes, 
        where
            data is a map of bytes'''
        return ", ".join(["0x{:02x}{:02x}{:02x}{:02x}".format(a, b, g, r)
            for r, g, b, a in grouper(4, expand(data), 0)])
    
    def png_data_from_file(path):
        '''returns a map of bytes of the png file'''
        with open(path, 'rb') as file:
            reader = png.Reader(file = file)
            data = reader.read();
            return list(data[2]);
    
    if __name__ == '__main__':
        import sys
        import os
        if len(sys.argv) != 2:
            sys.stdout.write("{0} image_path".format(sys.argv[0]))
            exit()
        path = sys.argv[1]
        filename = os.path.split(path)[1]
        header_filename = c_array_header_filename(filename)
        sys.stdout.write("Creating header file '{}'... ".format(header_filename))
        with open(header_filename, 'w') as header_file:
            header_file.write(c_array_header(filename))
        sys.stdout.write("done\n")
        source_filename = c_array_source_filename(filename)
        sys.stdout.write("Creating source file '{}'... ".format(source_filename))
        data = png_data_from_file(path)
        with open(source_filename, 'w') as source_file:
            source_file.write(c_array_source(filename, header_filename, convert_data_array_string(data)))
        del data
        sys.stdout.write("done\n")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to load some images in a scrollable pane. But for some
I'm trying to load some images using Bitmap.getBitmapResource() , but it takes about 2
I'm trying to load about 600 small images into memory. Size of each image
i'm trying to find a solution to load image names from a database and
I am trying to lazy load the Image Source for the Image Control but
Hy .what I am trying to do is load a bunch of images,resize them
i'm trying to load images from Facebook Albums to my flex app, this is
This is my current demo .I am trying to load images dynamically and now
I am trying to load multiple images that corresponds to my node when I
I'm trying to load charts as images in a secured site. An example of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.