Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
8c4b686d
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看板
未验证
提交
8c4b686d
编写于
1月 04, 2023
作者:
O
openharmony_ci
提交者:
Gitee
1月 04, 2023
浏览文件
操作
浏览文件
下载
差异文件
!13182 翻译完成:更新image.md
Merge pull request !13182 from wusongqing/E0104
上级
926c2e84
ee335d07
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
112 addition
and
96 deletion
+112
-96
en/application-dev/media/image.md
en/application-dev/media/image.md
+112
-96
未找到文件。
en/application-dev/media/image.md
浏览文件 @
8c4b686d
...
...
@@ -19,112 +19,121 @@ const color = new ArrayBuffer(96); // Create a buffer to store image pixel data.
let
opts
=
{
alphaType
:
0
,
editable
:
true
,
pixelFormat
:
4
,
scaleMode
:
1
,
size
:
{
height
:
2
,
width
:
3
}
}
// Image pixel data.
// Create a PixelMap object.
const
color
=
new
ArrayBuffer
(
96
);
let
opts
=
{
alphaType
:
0
,
editable
:
true
,
pixelFormat
:
4
,
scaleMode
:
1
,
size
:
{
height
:
2
,
width
:
3
}
}
image
.
createPixelMap
(
color
,
opts
,
(
err
,
pixelmap
)
=>
{
console
.
log
(
'
Succeeded in creating pixelmap.
'
);
})
// Read pixels.
const
area
=
{
pixels
:
new
ArrayBuffer
(
8
),
offset
:
0
,
stride
:
8
,
region
:
{
size
:
{
height
:
1
,
width
:
2
},
x
:
0
,
y
:
0
}
}
pixelmap
.
readPixels
(
area
,()
=>
{
var
bufferArr
=
new
Uint8Array
(
area
.
pixels
);
var
res
=
true
;
for
(
var
i
=
0
;
i
<
bufferArr
.
length
;
i
++
)
{
console
.
info
(
'
buffer
'
+
bufferArr
[
i
]);
if
(
res
)
{
if
(
bufferArr
[
i
]
==
0
)
{
res
=
false
;
console
.
log
(
'
readPixels end.
'
);
break
;
}
}
// Failed to create the PixelMap object.
if
(
err
)
{
console
.
info
(
'
create pixelmap failed, err
'
+
err
);
return
}
})
// Store pixels.
const
readBuffer
=
new
ArrayBuffer
(
96
);
pixelmap
.
readPixelsToBuffer
(
readBuffer
,()
=>
{
var
bufferArr
=
new
Uint8Array
(
readBuffer
);
var
res
=
true
;
for
(
var
i
=
0
;
i
<
bufferArr
.
length
;
i
++
)
{
if
(
res
)
{
if
(
bufferArr
[
i
]
!==
0
)
{
res
=
false
;
console
.
log
(
'
readPixelsToBuffer end.
'
);
break
;
}
}
// Read pixels.
const
area
=
{
pixels
:
new
ArrayBuffer
(
8
),
offset
:
0
,
stride
:
8
,
region
:
{
size
:
{
height
:
1
,
width
:
2
},
x
:
0
,
y
:
0
}
}
})
// Write pixels.
pixelmap
.
writePixels
(
area
,()
=>
{
const
readArea
=
{
pixels
:
new
ArrayBuffer
(
20
),
offset
:
0
,
stride
:
8
,
region
:
{
size
:
{
height
:
1
,
width
:
2
},
x
:
0
,
y
:
0
}}
pixelmap
.
readPixels
(
readArea
,()
=>
{
var
readArr
=
new
Uint8Array
(
readArea
.
pixels
);
var
res
=
true
;
for
(
var
i
=
0
;
i
<
readArr
.
length
;
i
++
)
{
pixelmap
.
readPixels
(
area
,()
=>
{
let
bufferArr
=
new
Uint8Array
(
area
.
pixels
);
let
res
=
true
;
for
(
let
i
=
0
;
i
<
bufferArr
.
length
;
i
++
)
{
console
.
info
(
'
buffer
'
+
bufferArr
[
i
]);
if
(
res
)
{
if
(
readArr
[
i
]
!
==
0
)
{
if
(
bufferArr
[
i
]
==
0
)
{
res
=
false
;
console
.
log
(
'
readPixels end.
please check buffer
'
);
console
.
log
(
'
readPixels end.
'
);
break
;
}
}
}
})
})
// Write pixels to the buffer.
pixelmap
.
writeBufferToPixels
(
writeColor
).
then
(()
=>
{
// Store pixels.
const
readBuffer
=
new
ArrayBuffer
(
96
);
pixelmap
.
readPixelsToBuffer
(
readBuffer
).
then
(
()
=>
{
var
bufferArr
=
new
Uint8Array
(
readBuffer
);
var
res
=
true
;
for
(
var
i
=
0
;
i
<
bufferArr
.
length
;
i
++
)
{
pixelmap
.
readPixelsToBuffer
(
readBuffer
,
()
=>
{
let
bufferArr
=
new
Uint8Array
(
readBuffer
);
let
res
=
true
;
for
(
let
i
=
0
;
i
<
bufferArr
.
length
;
i
++
)
{
if
(
res
)
{
if
(
bufferArr
[
i
]
!==
i
)
{
if
(
bufferArr
[
i
]
!==
0
)
{
res
=
false
;
console
.
log
(
'
readPixels
end.please check buffer
'
);
console
.
log
(
'
readPixels
ToBuffer end.
'
);
break
;
}
}
}
})
})
// Write pixels.
pixelmap
.
writePixels
(
area
,()
=>
{
const
readArea
=
{
pixels
:
new
ArrayBuffer
(
20
),
offset
:
0
,
stride
:
8
,
region
:
{
size
:
{
height
:
1
,
width
:
2
},
x
:
0
,
y
:
0
}}
pixelmap
.
readPixels
(
readArea
,()
=>
{
let
readArr
=
new
Uint8Array
(
readArea
.
pixels
);
let
res
=
true
;
for
(
let
i
=
0
;
i
<
readArr
.
length
;
i
++
)
{
if
(
res
)
{
if
(
readArr
[
i
]
!==
0
)
{
res
=
false
;
console
.
log
(
'
readPixels end.please check buffer
'
);
break
;
}
}
}
})
})
// Obtain image information.
pixelmap
.
getImageInfo
((
error
,
imageInfo
)
=>
{
if
(
imageInfo
!==
null
)
{
console
.
log
(
'
Succeeded in getting imageInfo
'
);
}
})
const
writeColor
=
new
ArrayBuffer
(
96
);
// Pixel data of the image.
// Write pixels to the buffer.
pixelmap
.
writeBufferToPixels
(
writeColor
).
then
(()
=>
{
const
readBuffer
=
new
ArrayBuffer
(
96
);
pixelmap
.
readPixelsToBuffer
(
readBuffer
).
then
(()
=>
{
let
bufferArr
=
new
Uint8Array
(
readBuffer
);
let
res
=
true
;
for
(
let
i
=
0
;
i
<
bufferArr
.
length
;
i
++
)
{
if
(
res
)
{
if
(
bufferArr
[
i
]
!==
i
)
{
res
=
false
;
console
.
log
(
'
readPixels end.please check buffer
'
);
break
;
}
}
}
})
})
// Release the PixelMap object.
pixelmap
.
release
(()
=>
{
console
.
log
(
'
Succeeded in releasing pixelmap
'
);
// Obtain image information.
pixelmap
.
getImageInfo
((
err
,
imageInfo
)
=>
{
// Failed to obtain the image information.
if
(
err
||
imageInfo
==
null
)
{
console
.
info
(
'
getImageInfo failed, err
'
+
err
);
return
}
if
(
imageInfo
!==
null
)
{
console
.
log
(
'
Succeeded in getting imageInfo
'
);
}
})
// Release the PixelMap object.
pixelmap
.
release
(()
=>
{
console
.
log
(
'
Succeeded in releasing pixelmap
'
);
})
})
// Create an image source (uri).
let
path
=
'
/data/local/tmp/test.jpg
'
;
const
imageSourceApi
=
image
.
createImageSource
(
path
);
const
imageSourceApi
1
=
image
.
createImageSource
(
path
);
// Create an image source (fd).
let
fd
=
29
;
const
imageSourceApi
=
image
.
createImageSource
(
fd
);
const
imageSourceApi
2
=
image
.
createImageSource
(
fd
);
// Create an image source (data).
const
data
=
new
ArrayBuffer
(
96
);
const
imageSourceApi
=
image
.
createImageSource
(
data
);
const
imageSourceApi
3
=
image
.
createImageSource
(
data
);
// Release the image source.
imageSourceApi
.
release
(()
=>
{
imageSourceApi
3
.
release
(()
=>
{
console
.
log
(
'
Succeeded in releasing imagesource
'
);
})
...
...
@@ -133,6 +142,10 @@ const imagePackerApi = image.createImagePacker();
const
imageSourceApi
=
image
.
createImageSource
(
0
);
let
packOpts
=
{
format
:
"
image/jpeg
"
,
quality
:
98
};
imagePackerApi
.
packing
(
imageSourceApi
,
packOpts
,
(
err
,
data
)
=>
{
if
(
err
)
{
console
.
info
(
'
packing from imagePackerApi failed, err
'
+
err
);
return
}
console
.
log
(
'
Succeeded in packing
'
);
})
...
...
@@ -161,36 +174,33 @@ let decodingOptions = {
// Create a pixel map in callback mode.
imageSourceApi
.
createPixelMap
(
decodingOptions
,
(
err
,
pixelmap
)
=>
{
// Failed to create the PixelMap object.
if
(
err
)
{
console
.
info
(
'
create pixelmap failed, err
'
+
err
);
return
}
console
.
log
(
'
Succeeded in creating pixelmap.
'
);
})
// Create a pixel map in promise mode.
imageSourceApi
.
createPixelMap
().
then
(
pixelmap
=>
{
console
.
log
(
'
Succeeded in creating pixelmap.
'
);
})
// Capture error information when an exception occurs during function invoking.
catch
(
error
=>
{
console
.
log
(
'
Failed in creating pixelmap.
'
+
error
);
})
// Obtain the number of bytes in each line of pixels.
var
num
=
pixelmap
.
getBytesNumberPerRow
();
// Obtain the number of bytes in each line of pixels.
let
num
=
pixelmap
.
getBytesNumberPerRow
();
// Obtain the total number of pixel bytes.
var
pixelSize
=
pixelmap
.
getPixelBytesNumber
();
// Obtain the total number of pixel bytes.
let
pixelSize
=
pixelmap
.
getPixelBytesNumber
();
// Obtain the pixel map information.
pixelmap
.
getImageInfo
().
then
(
imageInfo
=>
{});
// Obtain the pixel map information.
pixelmap
.
getImageInfo
().
then
(
imageInfo
=>
{});
// Release the PixelMap object.
pixelmap
.
release
(()
=>
{
console
.
log
(
'
Succeeded in releasing pixelmap
'
);
})
// Capture release failure information.
catch
(
error
=>
{
console
.
log
(
'
Failed in releasing pixelmap.
'
+
error
);
// Release the PixelMap object.
pixelmap
.
release
(()
=>
{
console
.
log
(
'
Succeeded in releasing pixelmap
'
);
})
}).
catch
(
error
=>
{
console
.
log
(
'
Failed in creating pixelmap.
'
+
error
);
})
```
...
...
@@ -216,7 +226,7 @@ if (imagePackerApi == null) {
}
// Set encoding parameters if the image packer is successfully created.
let
packOpts
=
{
format
:
[
"
image/jpeg
"
]
,
// The supported encoding format is jpg.
let
packOpts
=
{
format
:
"
image/jpeg
"
,
// The supported encoding format is jpg.
quality
:
98
}
// Image quality, which ranges from 0 to 100.
// Encode the image.
...
...
@@ -233,8 +243,9 @@ imageSourceApi.getImageInfo((err, imageInfo) => {
console
.
log
(
'
Succeeded in getting imageInfo
'
);
})
const
array
=
new
ArrayBuffer
(
100
);
// Incremental data.
// Update incremental data.
imageSource
IncrementalS
Api
.
updateData
(
array
,
false
,
0
,
10
,(
error
,
data
)
=>
{})
imageSourceApi
.
updateData
(
array
,
false
,
0
,
10
,(
error
,
data
)
=>
{})
```
...
...
@@ -246,10 +257,15 @@ Example scenario: The camera functions as the client to transmit image data to t
public
async
init
(
surfaceId
:
any
)
{
// (Server code) Create an ImageReceiver object.
var
receiver
=
image
.
createImageReceiver
(
8
*
1024
,
8
,
image
.
ImageFormat
.
JPEG
,
1
);
let
receiver
=
image
.
createImageReceiver
(
8
*
1024
,
8
,
image
.
ImageFormat
.
JPEG
,
1
);
// Obtain the surface ID.
receiver
.
getReceivingSurfaceId
((
err
,
surfaceId
)
=>
{
// Failed to obtain the surface ID.
if
(
err
)
{
console
.
info
(
'
getReceivingSurfaceId failed, err
'
+
err
);
return
}
console
.
info
(
"
receiver getReceivingSurfaceId success
"
);
});
// Register a surface listener, which is triggered after the buffer of the surface is ready.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录