当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript nativeImage.createFromDataURL方法代码示例

本文整理汇总了TypeScript中electron.nativeImage.createFromDataURL方法的典型用法代码示例。如果您正苦于以下问题:TypeScript nativeImage.createFromDataURL方法的具体用法?TypeScript nativeImage.createFromDataURL怎么用?TypeScript nativeImage.createFromDataURL使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在electron.nativeImage的用法示例。


在下文中一共展示了nativeImage.createFromDataURL方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: getEmojiIcon

/**
@returns An icon to use for the menu item of this emoji style.
*/
async function getEmojiIcon(style: EmojiStyle): Promise<NativeImage | undefined> {
	const cachedIcon = cachedEmojiMenuIcons.get(style);

	if (cachedIcon) {
		return cachedIcon;
	}

	if (style === 'native') {
		if (!getWindow()) {
			return undefined;
		}

		const dataUrl = await renderEmoji('🙂');
		const image = nativeImage.createFromDataURL(dataUrl);
		const resizedImage = image.resize({width: 16, height: 16});

		cachedEmojiMenuIcons.set(style, resizedImage);

		return resizedImage;
	}

	const image = nativeImage.createFromPath(
		path.join(__dirname, '..', 'static', `emoji-${style}.png`)
	);

	cachedEmojiMenuIcons.set(style, image);

	return image;
}
开发者ID:nikteg,项目名称:caprine,代码行数:32,代码来源:emoji.ts

示例2: Notification

	(_event: ElectronEvent, {id, title, body, icon, silent}: NotificationEvent) => {
		const notification = new Notification({
			title,
			body,
			hasReply: true,
			icon: nativeImage.createFromDataURL(icon),
			silent
		});

		notifications.set(id, notification);

		notification.on('click', () => {
			mainWindow.show();
			sendAction('notification-callback', {callbackName: 'onclick', id});

			notifications.delete(id);
		});

		notification.on('reply', (_event, reply: string) => {
			// We use onclick event used by messenger to go to the right convo
			sendBackgroundAction('notification-reply-callback', {callbackName: 'onclick', id, reply});

			notifications.delete(id);
		});

		notification.on('close', () => {
			sendAction('notification-callback', {callbackName: 'onclose', id});

			notifications.delete(id);
		});

		notification.show();
	}
开发者ID:kusamakura,项目名称:caprine,代码行数:33,代码来源:index.ts

示例3:

			const items = conversations.map(({label, icon}, index) => {
				return {
					label: `${label}`,
					icon: nativeImage.createFromDataURL(icon),
					click: () => {
						mainWindow.show();
						sendAction('jump-to-conversation', index + 1);
					}
				};
			});
开发者ID:kusamakura,项目名称:caprine,代码行数:10,代码来源:index.ts

示例4: TouchBarButton

	const items = conversations.map(({label, selected, icon}, index: number) => {
		return new TouchBarButton({
			label: label.length > 25 ? label.slice(0, 25) + '…' : label,
			backgroundColor: selected ? '#0084ff' : undefined,
			icon: nativeImage.createFromDataURL(icon),
			iconPosition: 'left',
			click: () => {
				sendAction('jump-to-conversation', index + 1);
			}
		});
	});
开发者ID:kusamakura,项目名称:caprine,代码行数:11,代码来源:touch-bar.ts

示例5: saveAsPng

export function saveAsPng(data:ImageData,outfile:string){
    var canv = document.createElement('canvas');
    canv.width=data.width;
    canv.height=data.height;
    var ctx = canv.getContext('2d');
    ctx.putImageData(data,0,0);
    var buf = canv.toDataURL('image/png');
    var nimg = nativeImage.createFromDataURL(buf);
    fs.writeFileSync(outfile,nimg.toPng());
    return nativeImage;
}
开发者ID:guozhaokui,项目名称:CanvasLabs,代码行数:11,代码来源:imgfunc.ts

示例6: canvasBuffer

  canvasBuffer(canvas, type, quality?) {
    let types = ['image/png', 'image/jpg', 'image/jpeg']

    type = type || 'image/png'
    quality = typeof quality === 'number' ? quality : 0.9

    if (types.indexOf(type) === -1) {
      throw new Error('unsupported image type ' + type)
    }

    let data = canvas.toDataURL(type, quality)
    let img = nativeImage.createFromDataURL(data) // electron v0.36+
    if (/^image\/jpe?g$/.test(type)) {
      return img.toJpeg(Math.floor(quality * 100))
    } else {
      return img.toPng()
    }
  }
开发者ID:atomba,项目名称:electrogram,代码行数:18,代码来源:canvasService.ts

示例7: copyFromDataURL

 export function copyFromDataURL(dataURL: string) {
   const image = electron.nativeImage.createFromDataURL(dataURL);
   electron.clipboard.writeImage(image);
 }
开发者ID:MSylvia,项目名称:superpowers-app,代码行数:4,代码来源:index.ts

示例8: saveCanvas

export function saveCanvas(canv:HTMLCanvasElement, outfile:string){
    var buf = canv.toDataURL('image/png');
    var nimg = nativeImage.createFromDataURL(buf);
    var sz:{width:number,height:number} = nimg.getSize();
    fs.writeFileSync(outfile,nimg.toPng());
}
开发者ID:guozhaokui,项目名称:CanvasLabs,代码行数:6,代码来源:imgfunc.ts


注:本文中的electron.nativeImage.createFromDataURL方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。