pebble
  • Tutorials
  • Get the SDK
  • Guides
  • Documentation
  • Examples
  • Community
  • Blog
  • More
Privacy
Cookies
Publish

Pebble C API

  • Pebble C API
  • Pebble JavaScript API
  • PebbleKit JS
  • PebbleKit iOS
  • PebbleKit Android
  • Foundation
    • App
    • App Communication
    • App Glance
    • AppMessage
    • AppSync
    • AppWorker
    • DataLogging
    • DataStructures
      • UUID
    • Dictation
    • Dictionary
    • Event Service
      • AccelerometerService
      • AppFocusService
      • BatteryStateService
      • CompassService
      • ConnectionService
      • HealthService
      • TickTimerService
    • Exit Reason
    • Internationalization
    • Launch Reason
    • Logging
    • Math
    • Memory Management
    • Platform
    • Resources
      • File Formats
    • Storage
    • Timer
    • Wakeup
    • Wall Time
    • WatchInfo
    • Rocky
  • Graphics
    • Draw Commands
    • Drawing Paths
    • Drawing Primitives
    • Drawing Text
    • Fonts
    • Graphics Context
    • Graphics Types
      • Color Definitions
  • User Interface
    • Animation
      • PropertyAnimation
    • Clicks
    • Layers
      • ActionBarLayer
      • BitmapLayer
      • MenuLayer
      • RotBitmapLayer
      • ScrollLayer
      • SimpleMenuLayer
      • StatusBarLayer
      • TextLayer
    • Light
    • Preferences
    • UnobstructedArea
    • Vibes
    • Window
      • ActionMenu
      • NumberWindow
    • Window Stack
  • Standard C
    • Format
    • Locale
    • Math
    • Memory
    • String
    • Time

Resources

Managing application resources.

Resources are data files that are bundled with your application binary and can be loaded at runtime. You use resources to embed images or custom fonts in your app, but also to embed any data file. Resources are always read-only.

Resources are stored on Pebble’s flash memory and only loaded in RAM when you load them. This means that you can have a large number of resources embedded inside your app, even though Pebble’s RAM memory is very limited.

See App Resources in the Pebble Developer Guides for information on how to embed resources into your app's bundle.

Modules

File Formats

 

Function Documentation

ResHandle resource_get_handle(uint32_t resource_id)

Gets the resource handle for a file identifier.

The resource IDs are auto-generated by the Pebble build process, based on the appinfo.json. The "name" field of each resource is prefixed by RESOURCE_ID_ and made visible to the application (through the build/src/resource_ids.auto.h header which is automatically included).

For example, given the following fragment of appinfo.json:

...
"resources" : {
  "media": [
     {
        "name": "MY_ICON",
        "file": "img/icon.png",
        "type": "png",
     },
 ...
The generated file identifier for this resource is RESOURCE_ID_MY_ICON. To get a resource handle for that resource write:
ResHandle rh = resource_get_handle(RESOURCE_ID_MY_ICON);

Parameters

resource_id

The resource ID

size_t resource_size(ResHandle h)

Gets the size of the resource given a resource handle.

Parameters

h

The handle to the resource

Returns

The size of the resource in bytes

size_t resource_load(ResHandle h, uint8_t * buffer, size_t max_length)

Copies the bytes for the resource with a given handle from flash storage into a given buffer.

Parameters

h

The handle to the resource

buffer

The buffer to load the resource data into

max_length

The maximum number of bytes to copy

Returns

The number of bytes actually copied

size_t resource_load_byte_range(ResHandle h, uint32_t start_offset, uint8_t * buffer, size_t num_bytes)

Copies a range of bytes from a resource with a given handle into a given buffer.

Parameters

h

The handle to the resource

start_offset

The offset in bytes at which to start reading from the resource

buffer

The buffer to load the resource data into

num_bytes

The maximum number of bytes to copy

Returns

The number of bytes actually copied

Typedef Documentation

typedef void * ResHandle

Opaque reference to a resource.

See Also

resource_get_handle()

Macro Definition Documentation

#define RESOURCE_ID_FONT_FALLBACK RESOURCE_ID_GOTHIC_14

Need some help?

Modules

  • File Formats

Functions

  • resource_get_handle
  • resource_size
  • resource_load
  • resource_load_byte_range

Typedefs

  • ResHandle

Macro Defintions

  • RESOURCE_ID_FONT_FALLBACK

Getting Help

Do you have questions about the Pebble SDK?

Do you need some help understanding something on this page?

You can either take advantage of our awesome developer community and check out the SDK Help forums, or you can send us a message through the website!