Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
ec2af0d4
D
Docs
项目概览
OpenHarmony
/
Docs
大约 1 年 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
ec2af0d4
编写于
10月 17, 2022
作者:
O
openharmony_ci
提交者:
Gitee
10月 17, 2022
浏览文件
操作
浏览文件
下载
差异文件
!10548 翻译完成:10308 资料更新 (仅涉及代码更新)
Merge pull request !10548 from wusongqing/TR10308
上级
e3c5e52f
29ea6213
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
62 addition
and
96 deletion
+62
-96
en/application-dev/media/image.md
en/application-dev/media/image.md
+62
-96
未找到文件。
en/application-dev/media/image.md
浏览文件 @
ec2af0d4
...
@@ -21,45 +21,43 @@ let opts = { alphaType: 0, editable: true, pixelFormat: 4, scaleMode: 1, size: {
...
@@ -21,45 +21,43 @@ let opts = { alphaType: 0, editable: true, pixelFormat: 4, scaleMode: 1, size: {
// Create a PixelMap object.
// Create a PixelMap object.
const
color
=
new
ArrayBuffer
(
96
);
const
color
=
new
ArrayBuffer
(
96
);
let
opts
=
{
alphaType
:
0
,
editable
:
true
,
pixelFormat
:
4
,
scaleMode
:
1
,
size
:
{
height
:
2
,
width
:
3
}
}
let
opts
=
{
alphaType
:
0
,
editable
:
true
,
pixelFormat
:
4
,
scaleMode
:
1
,
size
:
{
height
:
2
,
width
:
3
}
}
image
.
createPixelMap
(
color
,
opts
,
pixelmap
=>
{
image
.
createPixelMap
(
color
,
opts
,
pixelmap
=>
{
expect
(
pixelmap
!==
null
).
assertTrue
();
console
.
log
(
'
Succeeded in creating pixelmap.
'
);
console
.
info
(
'
TC_001-1 success
'
);
})
done
();
})
// Read pixels.
// Read pixels.
pixelmap
.
readPixels
(
area
,(
data
)
=>
{
pixelmap
.
readPixels
(
area
,(
data
)
=>
{
if
(
data
!==
null
)
{
if
(
data
!==
null
)
{
var
bufferArr
=
new
Uint8Array
(
area
.
pixels
);
var
bufferArr
=
new
Uint8Array
(
area
.
pixels
);
var
res
=
true
;
var
res
=
true
;
for
(
var
i
=
0
;
i
<
bufferArr
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
bufferArr
.
length
;
i
++
)
{
console
.
info
(
'
TC_021-1
buffer
'
+
bufferArr
[
i
]);
console
.
info
(
'
buffer
'
+
bufferArr
[
i
]);
if
(
res
)
{
if
(
res
)
{
if
(
bufferArr
[
i
]
==
0
)
{
if
(
bufferArr
[
i
]
==
0
)
{
res
=
false
;
res
=
false
;
console
.
info
(
'
TC_021-1 Success
'
);
console
.
log
(
'
readPixels end.
'
);
expect
(
true
).
assertTrue
();
done
();
break
;
break
;
}
}
}
}
}
}
}
})
// Store pixels.
// Store pixels.
const
readBuffer
=
new
ArrayBuffer
(
96
);
const
readBuffer
=
new
ArrayBuffer
(
96
);
pixelmap
.
readPixelsToBuffer
(
readBuffer
,()
=>
{
pixelmap
.
readPixelsToBuffer
(
readBuffer
,()
=>
{
var
bufferArr
=
new
Uint8Array
(
readBuffer
);
var
bufferArr
=
new
Uint8Array
(
readBuffer
);
var
res
=
true
;
var
res
=
true
;
for
(
var
i
=
0
;
i
<
bufferArr
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
bufferArr
.
length
;
i
++
)
{
if
(
res
)
{
if
(
res
)
{
if
(
bufferArr
[
i
]
!==
0
)
{
if
(
bufferArr
[
i
]
!==
0
)
{
res
=
false
;
res
=
false
;
console
.
info
(
'
TC_020-1 Success
'
);
console
.
log
(
'
readPixelsToBuffer end.
'
);
expect
(
true
).
assertTrue
();
done
();
break
;
break
;
}
}
}
}
}
}
})
// Write pixels.
// Write pixels.
pixelmap
.
writePixels
(
area
,()
=>
{
pixelmap
.
writePixels
(
area
,()
=>
{
...
@@ -71,13 +69,13 @@ pixelmap.writePixels(area,() => {
...
@@ -71,13 +69,13 @@ pixelmap.writePixels(area,() => {
if
(
res
)
{
if
(
res
)
{
if
(
readArr
[
i
]
!==
0
)
{
if
(
readArr
[
i
]
!==
0
)
{
res
=
false
;
res
=
false
;
console
.
info
(
'
TC_022-1 Success
'
);
console
.
log
(
'
readPixels end.please check buffer
'
);
expect
(
true
).
assertTrue
();
done
();
break
;
break
;
}
}
}
}
}
}
})
})
// Write pixels to the buffer.
// Write pixels to the buffer.
pixelmap
.
writeBufferToPixels
(
writeColor
).
then
(()
=>
{
pixelmap
.
writeBufferToPixels
(
writeColor
).
then
(()
=>
{
...
@@ -89,38 +87,33 @@ pixelmap.writeBufferToPixels(writeColor).then(() => {
...
@@ -89,38 +87,33 @@ pixelmap.writeBufferToPixels(writeColor).then(() => {
if
(
res
)
{
if
(
res
)
{
if
(
bufferArr
[
i
]
!==
i
)
{
if
(
bufferArr
[
i
]
!==
i
)
{
res
=
false
;
res
=
false
;
console
.
info
(
'
TC_023 Success
'
);
console
.
log
(
'
readPixels end.please check buffer
'
);
expect
(
true
).
assertTrue
()
done
();
break
;
break
;
}
}
}
}
}
}
})
})
// Obtain image information.
// Obtain image information.
pixelmap
.
getImageInfo
(
imageInfo
=>
{
pixelmap
.
getImageInfo
(
imageInfo
=>
{
if
(
imageInfo
!==
null
)
{
if
(
imageInfo
!==
null
)
{
console
.
info
(
'
TC_024-1 imageInfo is ready
'
);
console
.
log
(
'
Succeeded in getting imageInfo
'
);
expect
(
imageInfo
.
size
.
height
==
4
).
assertTrue
();
expect
(
imageInfo
.
size
.
width
==
6
).
assertTrue
();
expect
(
imageInfo
.
pixelFormat
==
4
).
assertTrue
();
done
();
}
}
})
})
// Release the PixelMap object.
// Release the PixelMap object.
pixelmap
.
release
(()
=>
{
pixelmap
.
release
(()
=>
{
expect
(
true
).
assertTrue
();
console
.
log
(
'
Succeeded in releasing pixelmap
'
);
console
.
log
(
'
TC_027-1 suc
'
);
done
();
})
})
let
path
=
'
/data/local/tmp/test.jpg
'
;
// Create an image source (uri).
// Create an image source (uri).
const
imageSourceApi
=
image
.
createImageSource
(
path
);
// '/data/local/tmp/test.jpg'
let
path
=
'
/data/local/tmp/test.jpg
'
;
const
imageSourceApi
=
image
.
createImageSource
(
path
);
// Create an image source (fd).
// Create an image source (fd).
const
imageSourceApi
=
image
.
createImageSource
(
29
);
let
fd
=
29
;
const
imageSourceApi
=
image
.
createImageSource
(
fd
);
// Create an image source (data).
// Create an image source (data).
const
data
=
new
ArrayBuffer
(
96
);
const
data
=
new
ArrayBuffer
(
96
);
...
@@ -128,15 +121,15 @@ const imageSourceApi = image.createImageSource(data);
...
@@ -128,15 +121,15 @@ const imageSourceApi = image.createImageSource(data);
// Release the image source.
// Release the image source.
imageSourceApi
.
release
(()
=>
{
imageSourceApi
.
release
(()
=>
{
console
.
info
(
'
TC_044-1 Success
'
);
console
.
log
(
'
Succeeded in releasing imagesource
'
);
})
})
// Encode the image.
// Encode the image.
const
imagePackerApi
=
image
.
createImagePacker
();
const
imagePackerApi
=
image
.
createImagePacker
();
const
imageSourceApi
=
image
.
createImageSource
(
0
);
let
packOpts
=
{
format
:
"
image/jpeg
"
,
quality
:
98
};
imagePackerApi
.
packing
(
imageSourceApi
,
packOpts
,
data
=>
{
imagePackerApi
.
packing
(
imageSourceApi
,
packOpts
,
data
=>
{
console
.
info
(
'
TC_062-1 finished
'
);
console
.
log
(
'
Succeeded in packing
'
);
expect
(
data
!==
null
).
assertTrue
();
done
();
})
})
// Release the ImagePacker object.
// Release the ImagePacker object.
...
@@ -164,59 +157,40 @@ let decodingOptions = {
...
@@ -164,59 +157,40 @@ let decodingOptions = {
// Create a pixel map in callback mode.
// Create a pixel map in callback mode.
imageSourceApi
.
createPixelMap
(
decodingOptions
,
pixelmap
=>
{
imageSourceApi
.
createPixelMap
(
decodingOptions
,
pixelmap
=>
{
console
.
info
(
'
TC_050 createPixelMap
'
);
console
.
log
(
'
Succeeded in creating pixelmap.
'
);
expect
(
pixelmap
!==
null
).
assertTrue
();
})
done
();
})
}
// Create a pixel map in promise mode.
// Create a pixel map in promise mode.
imageSourceApi
.
createPixelMap
().
then
(
pixelmap
=>
{
imageSourceApi
.
createPixelMap
().
then
(
pixelmap
=>
{
console
.
info
(
'
TC_050-11 createPixelMap
'
);
console
.
log
(
'
Succeeded in creating pixelmap.
'
);
expect
(
pixelmap
!==
null
).
assertTrue
();
done
();
})
})
// Capture error information when an exception occurs during function invoking.
// Capture error information when an exception occurs during function invoking.
catch
(
error
=>
{
catch
(
error
=>
{
console
.
log
(
'
TC_050-11 error:
'
+
error
);
console
.
log
(
'
Failed in creating pixelmap.
'
+
error
);
expect
().
assertFail
();
done
();
})
})
// Obtain the number of bytes in each line of pixels.
// Obtain the number of bytes in each line of pixels.
pixelmap
.
getBytesNumberPerRow
(
num
=>
{
pixelmap
.
getBytesNumberPerRow
(
num
=>
{
console
.
info
(
'
TC_025-1 num is
'
+
num
);
console
.
log
(
'
Succeeded in getting BytesNumber PerRow.
'
);
expect
(
num
==
expectNum
).
assertTrue
();
done
();
})
})
// Obtain the total number of pixel bytes.
// Obtain the total number of pixel bytes.
pixelmap
.
getPixelBytesNumber
(
num
=>
{
pixelmap
.
getPixelBytesNumber
(
num
=>
{
console
.
info
(
'
TC_026-1 num is
'
+
num
);
console
.
log
(
'
Succeeded in getting PixelBytesNumber.
'
);
expect
(
num
==
expectNum
).
assertTrue
();
done
();
})
})
// Obtain the pixel map information.
// Obtain the pixel map information.
pixelmap
.
getImageInfo
(
imageInfo
=>
{})
pixelmap
.
getImageInfo
(
imageInfo
=>
{})
// Print the failure information.
console
.
info
(
'
TC_024-1 imageInfo is empty
'
);
expect
(
false
).
assertTrue
()
// Release the PixelMap object.
// Release the PixelMap object.
pixelmap
.
release
(()
=>
{
pixelmap
.
release
(()
=>
{
expect
(
true
).
assertTrue
();
console
.
log
(
'
Succeeded in releasing pixelmap
'
);
console
.
log
(
'
TC_027-1 suc
'
);
done
();
})
})
// Capture release failure information.
// Capture release failure information.
catch
(
error
=>
{
catch
(
error
=>
{
console
.
log
(
'
TC_027-1 error:
'
+
error
);
console
.
log
(
'
Failed in releasing pixelmap.
'
+
error
);
expect
().
assertFail
();
done
();
})
})
```
```
...
@@ -230,9 +204,7 @@ const imageSourceApi = image.createImageSource(path); // '/data/local/tmp/test.p
...
@@ -230,9 +204,7 @@ const imageSourceApi = image.createImageSource(path); // '/data/local/tmp/test.p
// Print the error message if the image source fails to be created.
// Print the error message if the image source fails to be created.
if
(
imageSourceApi
==
null
)
{
if
(
imageSourceApi
==
null
)
{
console
.
info
(
'
TC_062 create image source failed
'
);
console
.
log
(
'
Failed in creating imageSource.
'
);
expect
(
false
).
assertTrue
();
done
();
}
}
// Create an image packer if the image source is successfully created.
// Create an image packer if the image source is successfully created.
...
@@ -240,9 +212,7 @@ const imagePackerApi = image.createImagePacker();
...
@@ -240,9 +212,7 @@ const imagePackerApi = image.createImagePacker();
// Print the error information if the image packer fails to be created.
// Print the error information if the image packer fails to be created.
if
(
imagePackerApi
==
null
)
{
if
(
imagePackerApi
==
null
)
{
console
.
info
(
'
TC_062 create image packer failed
'
);
console
.
log
(
'
Failed in creating imagePacker.
'
);
expect
(
false
).
assertTrue
();
done
();
}
}
// Set encoding parameters if the image packer is successfully created.
// Set encoding parameters if the image packer is successfully created.
...
@@ -252,9 +222,7 @@ let packOpts = { format:["image/jpeg"], // The supported encoding format is jpg.
...
@@ -252,9 +222,7 @@ let packOpts = { format:["image/jpeg"], // The supported encoding format is jpg.
// Encode the image.
// Encode the image.
imagePackerApi
.
packing
(
imageSourceApi
,
packOpts
)
imagePackerApi
.
packing
(
imageSourceApi
,
packOpts
)
.
then
(
data
=>
{
.
then
(
data
=>
{
console
.
info
(
'
TC_062 finished
'
);
console
.
log
(
'
Succeeded in packing
'
);
expect
(
data
!==
null
).
assertTrue
();
done
();
})
})
// Release the image packer after the encoding is complete.
// Release the image packer after the encoding is complete.
...
@@ -262,9 +230,7 @@ imagePackerApi.release();
...
@@ -262,9 +230,7 @@ imagePackerApi.release();
// Obtain the image source information.
// Obtain the image source information.
imageSourceApi
.
getImageInfo
(
imageInfo
=>
{
imageSourceApi
.
getImageInfo
(
imageInfo
=>
{
console
.
info
(
'
TC_045 imageInfo
'
);
console
.
log
(
'
Succeeded in getting imageInfo
'
);
expect
(
imageInfo
!==
null
).
assertTrue
();
done
();
})
})
// Update incremental data.
// Update incremental data.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录