import * as PIXI from "pixi.js" ; import { GameApplication } from "../core/GameApplication" ; import { Component } from "../core/Component" ; import { Base64Utlis } from "./Base64Utlis" ; export class ScreenShotUtils { public static ScreenShotBase64 ( target ) { return GameApplication . getInstance ( ) . application . renderer . extract . base64 ( target , "image/jpeg" ) ; } public static ScreenShotImage ( target ) { return GameApplication . getInstance ( ) . application . renderer . extract . image ( target , "image/jpeg" ) ; } public static downloadImg ( target ) { let str = ScreenShotUtils . ScreenShotBase64 ( target ) ; let blob = Base64Utlis . base64ToBlob ( str ) ; let aLink = document . createElement ( "img" ) ; aLink . setAttribute ( "href" , URL . createObjectURL ( blob ) ) ; aLink . setAttribute ( "download" , Date . now ( ) + "" ) ; let e = document . createEvent ( "MouseEvents" ) ; e . initMouseEvent ( "click" , false , true , window , 0 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null ) ; aLink . dispatchEvent ( e ) ; } public static weChatSaveImage ( target ) { let str = ScreenShotUtils . ScreenShotBase64 ( target ) ; let blob = Base64Utlis . base64ToBlob ( str ) ; let oImg = document . createElement ( "img" ) ; oImg . id = "oImg" ; oImg . className = "o-img" ; oImg . src = URL . createObjectURL ( blob ) ; document . body . appendChild ( oImg ) ; return oImg ; } param target param quality public static compressImage ( target , quality = 1 ) { let img = document . createElement ( "img" ) ; img . src = this . toDataURL ( target , quality ) ; return img ; } param target param quality public static toDataURL ( target , quality = 1 ) { let canvas = GameApplication . getInstance ( ) . application . renderer . extract . canvas ( target ) ; return canvas . toDataURL ( "image/jpeg" , quality ) ; } }