提交 506d25f7 编写于 作者: D DCloud_LXH

fix(app): canvasToTempFilePath fixed #2970

上级 d1f25255
......@@ -15,15 +15,11 @@ export {
removeMediaQueryObserver,
} from '../service/api/ui/mediaQueryObserver'
export function saveImage(
base64: string,
dirname: string,
callback: (error: Error | null, tempFilePath: string) => void
) {}
export { saveImage } from './saveImage'
export function getSameOriginUrl(url: string): Promise<string> {
return Promise.resolve(url)
}
export const TEMP_PATH = ''
export { TEMP_PATH } from '../service/api/constants'
export {
getEnterOptions,
......
let index = 0
type Format = 'jpg' | 'png' | undefined
export function saveImage(
base64: string,
dirname: string,
callback: (error: Error | null, tempFilePath?: string) => void
) {
const id = `${Date.now()}${index++}`
const bitmap = new plus.nativeObj.Bitmap!(`bitmap${id}`)
bitmap.loadBase64Data(
base64,
function () {
const base64Match = base64.match(/data:image\/(\S+?);/) || [null, 'png']
let format
if (base64Match[1]) {
format = base64Match[1].replace('jpeg', 'jpg') as Format
}
const tempFilePath = `${dirname}/${id}.${format}`
bitmap.save(
tempFilePath,
{
overwrite: true,
quality: 100,
format,
},
function () {
clear()
callback(null, tempFilePath)
},
function (error) {
clear()
callback(error)
}
)
},
function (error) {
clear()
callback(error)
}
)
function clear() {
bitmap.clear()
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册