mirror of
https://gitee.com/openharmony/applications_photos
synced 2024-11-23 07:00:09 +00:00
commit
5a116e1e51
@ -13,6 +13,8 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession';
|
import UIExtensionContentSession from '@ohos.app.ability.UIExtensionContentSession';
|
||||||
|
import fs from '@ohos.file.fs';
|
||||||
|
import image from '@ohos.multimedia.image';
|
||||||
import ability from '@ohos.ability.ability';
|
import ability from '@ohos.ability.ability';
|
||||||
import { Constants, Log } from '@ohos/common';
|
import { Constants, Log } from '@ohos/common';
|
||||||
import common from '@ohos.app.ability.common';
|
import common from '@ohos.app.ability.common';
|
||||||
@ -20,11 +22,6 @@ import photoAccessHelper from '@ohos.file.photoAccessHelper';
|
|||||||
import { CustomContentDialog } from '@ohos.arkui.advanced.Dialog';
|
import { CustomContentDialog } from '@ohos.arkui.advanced.Dialog';
|
||||||
|
|
||||||
const TAG: string = 'SaveUIExtension';
|
const TAG: string = 'SaveUIExtension';
|
||||||
const FOREGROUND_PHOTO_WIDTH: number = 576;
|
|
||||||
const BACKGROUND_PHOTO_WIDTH: number = 512;
|
|
||||||
const FOREGROUND_PHOTO_HEIGHT: number = 344;
|
|
||||||
const BACKGROUND_PHOTO_HEIGHT: number = 360;
|
|
||||||
|
|
||||||
let storage = LocalStorage.getShared();
|
let storage = LocalStorage.getShared();
|
||||||
|
|
||||||
@Entry(storage)
|
@Entry(storage)
|
||||||
@ -40,6 +37,7 @@ export struct SaveUIExtensionPage {
|
|||||||
private wantParam: Record<string, Object> = storage.get('wantParam') as Record<string, Object>;
|
private wantParam: Record<string, Object> = storage.get('wantParam') as Record<string, Object>;
|
||||||
private session: UIExtensionContentSession =
|
private session: UIExtensionContentSession =
|
||||||
storage.get<UIExtensionContentSession>('session') as UIExtensionContentSession;
|
storage.get<UIExtensionContentSession>('session') as UIExtensionContentSession;
|
||||||
|
@State private imageMaps: (string | image.PixelMap)[] = ['', ''];
|
||||||
|
|
||||||
dialogController: CustomDialogController | null = new CustomDialogController({
|
dialogController: CustomDialogController | null = new CustomDialogController({
|
||||||
builder: CustomContentDialog({
|
builder: CustomContentDialog({
|
||||||
@ -102,8 +100,8 @@ export struct SaveUIExtensionPage {
|
|||||||
|
|
||||||
Stack({ alignContent: Alignment.Bottom }) {
|
Stack({ alignContent: Alignment.Bottom }) {
|
||||||
if (this.uris.length > 1) {
|
if (this.uris.length > 1) {
|
||||||
Image(this.getThumbnail(false))
|
Image(this.imageMaps[1])
|
||||||
.objectFit(ImageFit.Fill)
|
.objectFit(ImageFit.Cover)
|
||||||
.border({
|
.border({
|
||||||
radius: $r('app.float.radius_24'),
|
radius: $r('app.float.radius_24'),
|
||||||
color: $r('sys.color.ohos_id_color_click_effect'),
|
color: $r('sys.color.ohos_id_color_click_effect'),
|
||||||
@ -115,8 +113,8 @@ export struct SaveUIExtensionPage {
|
|||||||
.opacity(0.4)
|
.opacity(0.4)
|
||||||
}
|
}
|
||||||
|
|
||||||
Image(this.getThumbnail(true))
|
Image(this.imageMaps[0])
|
||||||
.objectFit(ImageFit.Fill)
|
.objectFit(ImageFit.Cover)
|
||||||
.border({
|
.border({
|
||||||
radius: $r('app.float.radius_24'),
|
radius: $r('app.float.radius_24'),
|
||||||
color: $r('sys.color.ohos_id_color_click_effect'),
|
color: $r('sys.color.ohos_id_color_click_effect'),
|
||||||
@ -147,7 +145,7 @@ export struct SaveUIExtensionPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
aboutToAppear() {
|
aboutToAppear() {
|
||||||
this.uris = this.wantParam?.srcFileUris as string[];
|
this.uris = this.wantParam?.['ability.params.stream'] as string[];
|
||||||
this.bundleName = this.wantParam?.bundleName as string;
|
this.bundleName = this.wantParam?.bundleName as string;
|
||||||
this.appName = this.wantParam?.appName as string;
|
this.appName = this.wantParam?.appName as string;
|
||||||
this.appId = this.wantParam?.appId as string;
|
this.appId = this.wantParam?.appId as string;
|
||||||
@ -155,6 +153,8 @@ export struct SaveUIExtensionPage {
|
|||||||
let extensionArray = this.wantParam?.extensionArray as string[];
|
let extensionArray = this.wantParam?.extensionArray as string[];
|
||||||
let photoTypeArray = this.wantParam?.photoTypeArray as photoAccessHelper.PhotoType[];
|
let photoTypeArray = this.wantParam?.photoTypeArray as photoAccessHelper.PhotoType[];
|
||||||
let photoSubtypeArray = this.wantParam?.photoSubTypeArray as photoAccessHelper.PhotoSubtype[];
|
let photoSubtypeArray = this.wantParam?.photoSubTypeArray as photoAccessHelper.PhotoSubtype[];
|
||||||
|
this.getImageMaps(0);
|
||||||
|
this.getImageMaps(1);
|
||||||
try {
|
try {
|
||||||
let imageArray = photoTypeArray.filter(type => type === photoAccessHelper.PhotoType.IMAGE);
|
let imageArray = photoTypeArray.filter(type => type === photoAccessHelper.PhotoType.IMAGE);
|
||||||
if (imageArray.length === photoTypeArray.length) {
|
if (imageArray.length === photoTypeArray.length) {
|
||||||
@ -214,16 +214,25 @@ export struct SaveUIExtensionPage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private getThumbnail(isForeground: boolean): string {
|
private async getImageMaps(index: number) {
|
||||||
if (this.uris.length == 0) {
|
if (!this.uris) {
|
||||||
return '';
|
return;
|
||||||
}
|
}
|
||||||
if (this.uris.length == 1) {
|
if (index > this.uris.length - 1) {
|
||||||
return `${this.uris[0]}?oper=thumbnail&width=${FOREGROUND_PHOTO_WIDTH}&height=${BACKGROUND_PHOTO_HEIGHT}`;
|
return;
|
||||||
} else if (isForeground) {
|
}
|
||||||
return `${this.uris[0]}?oper=thumbnail&width=${FOREGROUND_PHOTO_WIDTH}&height=${FOREGROUND_PHOTO_HEIGHT}`;
|
let uri: string = this.uris[index];
|
||||||
} else {
|
let imgFile: fs.File | undefined;
|
||||||
return `${this.uris[1]}?oper=thumbnail&width=${BACKGROUND_PHOTO_WIDTH}&height=${BACKGROUND_PHOTO_HEIGHT}`;
|
let imageSource: image.ImageSource | undefined;
|
||||||
|
try {
|
||||||
|
imgFile = fs.openSync(uri);
|
||||||
|
imageSource = image.createImageSource(imgFile.fd);
|
||||||
|
this.imageMaps[index] = imageSource.createPixelMapSync();
|
||||||
|
} catch (err) {
|
||||||
|
Log.error(TAG, `get PixelMap failed with error: ${err.code}, ${err.message}.`);
|
||||||
|
} finally {
|
||||||
|
imageSource?.release();
|
||||||
|
fs.closeSync(imgFile?.fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user