-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
V3.6.1 save image data #12503
V3.6.1 save image data #12503
Conversation
Interface Check Report! WARNING this pull request has changed these public interfaces:
@@ -30053,8 +30053,41 @@
* @en Trigger garbage collection of ScriptEngine @zh 触发 ScriptEngine 的 GC
*/
function garbageCollect(): void;
/**
+ * @en Save the image to the path indicated.
+ * @zh 保存图片到指定路径。
+ * @param data : @en the image data, should be raw data array with uint8 @zh 图片数据, 应为原始数据数组,uint8 格式。
+ * @param path : @en the path to save @zh 保存路径
+ * @param width : @en the width of the image @zh 图片宽度
+ * @param height : @en the height of the image @zh 图片高度
+ * @param filePath : @en the file path of the image @zh 图片文件路径
+ * @param callback : @en the callback function @zh 回调函数
+ * @example
+ * ```ts
+ let renderTexture = new RenderTexture();
+ let renderWindowInfo = {
+ width: this._width,
+ height: this._height
+ };
+ renderTexture.reset(renderWindowInfo);
+ cameras.forEach((camera: any) => {
+ camera.targetTexture = renderTexture;
+ });
+ await this.waitForNextFrame();
+ cameras.forEach((camera: any) => {
+ camera.targetTexture = null;
+ });
+ let pixelData = renderTexture.readPixels();
+ jsb.saveImageData(pixelData, path, width, height, filePath, (isSuccess) => {
+ if (isSuccess) {
+ console.log('save image success');
+ } else {
+ console.log('save image failed');
+ }));
+ */
+ function saveImageData(data: Uint8Array, width: number, height: number, filePath: string): Promise<void>;
+ /**
* @en DownloaderTask @zh 下载任务对象
* @param requestURL @en Request download resource URL @zh 请求下载资源的URL
* @param storagePath @en Storage path for downloaded file @zh 下载文件存储路径
* @param identifier @en identifier @zh 标识符
|
@timlyeee, Please check the result of
Task Details
|
@timlyeee, Please check the result of
Task Details
|
@timlyeee, Please check the result of
Task Details
|
@timlyeee, Please check the result of
Task Details
|
@timlyeee, Please check the result of
Task Details
|
Right now I find there's a problem for the final API, the original API looks like below: function saveImageData(data: Uint8Array, width: number, height: number, filePath: string, callback: (isSuccess: boolean) => void): void But it cannot make sure that the data is unchanged while the developer might try to edit the buffer for other usage. For that reason, I change the API return a promise to tell the developer that the data should keep the same. function saveImageData(data: Uint8Array, width: number, height: number, filePath: string, callback: (isSuccess: boolean) => void): Promise<void> Now the callback seems useless because the promise can be await or not depends on need. Should I make the API like below? function saveImageData(data: Uint8Array, width: number, height: number, filePath: string): Promise<void> |
@timlyeee, Please check the result of
Task Details
|
@timlyeee, Please check the result of
Task Details
|
@timlyeee, Please check the result of
Task Details
|
@timlyeee, Please check the result of
Task Details
|
Why promise can make sure that the data is not changed? |
@minggo The rule to code is mean to keep the data unchanged when using Promise. Also, I'll add in documentation |
@timlyeee, Please check the result of
Task Details
|
@timlyeee, Please check the result of
Task Details
|
@timlyeee, Please check the result of
Task Details
|
@timlyeee, Please check the result of
Task Details
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seyitali
Re: #https://github.com/cocos/3d-tasks/issues/9274
Changelog
Continuous Integration
This pull request:
Compatibility Check
This pull request: