This commit is contained in:
root 2025-07-11 17:49:44 +08:00
parent 3f519fbc72
commit 3da2bc7c97
1 changed files with 5 additions and 3 deletions

View File

@ -7,6 +7,7 @@ interface ProjectImageProps {
alt: string
className: string
}
import { convertFileSrc } from '@tauri-apps/api/core'
const ProjectImage: React.FC<ProjectImageProps> = ({ imagePath, alt, className }) => {
const [imageSrc, setImageSrc] = useState<string>('')
@ -18,15 +19,16 @@ const ProjectImage: React.FC<ProjectImageProps> = ({ imagePath, alt, className }
setImageLoading(false)
return
}
if (imagePath.startsWith('http') || imagePath.startsWith('data:')) {
setImageSrc(imagePath)
setImageLoading(false)
return
}
try {
const dataUrl = await invoke<string>('read_image_as_data_url', { filePath: imagePath })
const dataUrl = convertFileSrc(imagePath)
setImageSrc(dataUrl)
} catch (error) {
console.error('Failed to read image:', error)