Fetch the repository succeeded.
本示例构建了一个图片放大案例,主要实现两个功能。
async readImage(imgUri: string, context: Context, decodingOptions?: image.DecodingOptions): Promise<PixelMap | null> {
const resourceMgr: resourceManager.ResourceManager = context.resourceManager;
const fileData = resourceMgr.getRawFileContentSync(imgUri)
const buffer = fileData.buffer.slice(0)
const imageSourceApi: image.ImageSource = image.createImageSource(buffer)
let pixmap: image.PixelMap;
if (decodingOptions) {
pixmap = await imageSourceApi.createPixelMap(decodingOptions);
} else {
pixmap = await imageSourceApi.createPixelMap();
}
return pixmap;
}
resetImg(): void {
this.imgScale = 1;
this.isScaling = true;
this.imgOffSetX = 0;
this.imgOffSetY = 0;
}
TapGesture()
.onAction((event: GestureEvent) => {
if (event && this.isScaling == true) {
this.imgScale = this.imgScale * Constants.IMAGE_SCALE_3;
this.imgOffSetX = Constants.IMAGE_WIDTH / 2 - event.fingerList[0].globalX;
this.imgOffSetY = Constants.IMAGE_HEIGHT / 2 - event.fingerList[0].globalY;
this.isScaling = false;
}
})
PanGesture()
.onActionStart(() => {
this.preOffsetX = this.imgOffSetX;
this.preOffsetY = this.imgOffSetY;
})
Button('放大镜')
.onClick(() => {
this.isScaling = true;
})
Button('重置图片')
.onClick(()=>{
this.resetImg();
})
亲爱的Harmony Next开发者,您好!
为了协助您高效开发,提高鸿蒙场景化示例的质量,希望您在浏览或使用后抽空填写一份简单的问卷,我们将会收集您的宝贵意见进行优化
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。