Skip to content

💪 A native solution to save raw image buffers (ArrayBuffer / Uint8Array) directly to the device gallery using JSI for maximum performance

License

Notifications You must be signed in to change notification settings

pioner92/react-native-img-buffer-save

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-native-img-buffer-save

A fast and lightweight React Native library built with JSI that allows you to save images directly to the device's gallery.

  • Supports saving images from Uint8Array or ArrayBuffer buffers.

Installation

Using Yarn

yarn add react-native-img-buffer-save

Using NPM

npm install react-native-img-buffer-save

iOS Specific

After installation, don't forget to install CocoaPods dependencies:

cd ios && pod install

Usage Example

import { View, Text, TouchableOpacity, StyleSheet } from 'react-native';
import { saveImageToGallery } from 'react-native-img-buffer-save';

export default function App() {
  const saveImg = () => {
    // Example binary image data (replace with actual image bytes)
    const imageBytes = Uint8Array.from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) // YOUR REAL IMAGE;
  
    // This function saves the image directly to the device's gallery.
    // It accepts both Uint8Array and ArrayBuffer inputs.
  
    // ✅ Option 1: Pass Uint8Array directly
    saveImageToGallery(imageBytes);
  
    // ✅ Option 2: Pass ArrayBuffer directly
    saveImageToGallery(imageBytes.buffer);
  };

  return (
    <View style={styles.container}>
      <TouchableOpacity onPress={saveImg}>
        <Text>Save IMG to gallery</Text>
      </TouchableOpacity>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
});

Notes

  • The library leverages JSI for high performance and low overhead.
  • Supports saving images from both Uint8Array and ArrayBuffer.
  • Currently works with both Android and iOS platforms.

Feel free to open issues or contribute!

License

MIT


Made with create-react-native-library