Код: Выделить всё
{selectedImages.map((image, index) => {
// Find matching image data by uri
const imageData = imageSizes.find(item => item.uri === image.uri);
newWidth = 100;
newHeight = 100;
if (imageData?.width) {
newWidth = Math.round(imageData.width / pixelRatio);
newHeight = Math.round(imageData.height / pixelRatio);
}
return (
{'text text text'}
{imageData?.width || 0}{' x '}{imageData?.height || 0}
);
})}
< /code>
Функция вызывается со следующим компонентом < /p>
{ processImages(); }} style={styles.button}>
{`test watermark`}
< /code>
Функция обработки здесь. Это работает, как предполагалось при условии, что вышеупомянутое правило соблюдается. < /P>
const processImages = async () => {
let processedUris = [];
for (let i = 0; i < selectedImages.length; i++) {
if (!viewRefs.current[i]?.current) {
console.warn(`Ref for image ${i} is not assigned`);
continue;
}
const watermarkedUri = await addWatermark(selectedImages[i], viewRefs.current[i]);
if (watermarkedUri) {
processedUris.push(watermarkedUri);
}
}
setWatermarkedImages(processedUris);
console.log('All images processed:', processedUris);
};
const addWatermark = async (imageUri, viewRef) => {
return new Promise(async (resolve) => {
setTimeout(async () => {
try {
const snapshot = await captureRef(viewRef.current, {
format: 'jpg',
quality: 1,
});
const fileName = `watermarked_${Date.now()}.jpg`;
const newUri = APP_CACHE + fileName;
await FileSystem.moveAsync({
from: snapshot,
to: newUri,
});
// console.log('Saved:', newUri);
resolve(newUri);
} catch (error) {
console.error('Error capturing image:', error);
resolve(null);
}
}, 100);
});
};
Выход с фиксированным размером (размеры, установленные на 1016x762, вывод на 2000x1500)
>
Подробнее здесь: https://stackoverflow.com/questions/795 ... dimensions
Мобильная версия