|
|
AIWROK½ØÍ¼»º´æ¹¤¾ß
- /**
- * AIWROK½ØÍ¼»º´æ¹¤¾ß
- * ¹¦ÄÜ£ºÌṩ¼òµ¥µÄ½ØÍ¼²¶»ñºÍ»º´æ¹ÜÀí
- * ×÷ÕߣºAIWROK¿ª·¢ÍŶÓ
- * // AIWROKÈí¼þ°²×¿½»Á÷QQȺ711841924
- * //Æ»¹ûÄÚ²âÈí¼þQQȺ648461709
- */
- var ScreenshotCache = {
- // ¼òµ¥»º´æ´æ´¢
- _cache: null,
- _cacheKey: null,
- _cacheTimestamp: null,
-
- /**
- * ²¶»ñÈ«ÆÁ½ØÍ¼²¢»º´æ
- * @param {String} key ¿ÉÑ¡µÄ»º´æ¼üÃû£¬²»ÌṩÔòʹÓÃĬÈϼü
- * @returns {Object} ½ØÍ¼¶ÔÏó£¬Èç¹ûʧ°ÜÔò·µ»Ønull
- */
- captureFullScreen: function(key) {
- // ÉèÖÃĬÈϼü
- key = key || 'default';
-
- try {
- // ¼ì²éAIWROK»·¾³
- if (typeof screen === 'undefined') {
- printl('´íÎó: AIWROK½ØÍ¼Ä£¿é²»¿ÉÓÃ');
- return null;
- }
-
- printl('Ö´ÐÐÈ«ÆÁ½ØÍ¼...');
- var screenshot = null;
-
- // ʹÓÃAIWROKÈ«ÆÁ½ØÍ¼·½·¨
- if (typeof screen.screenShotFull === 'function') {
- screenshot = screen.screenShotFull();
-
- if (screenshot) {
- printl('È«ÆÁ½ØÍ¼³É¹¦');
- // »º´æ½ØÍ¼
- this._cache = screenshot;
- this._cacheKey = key;
- this._cacheTimestamp = new Date().getTime();
- } else {
- printl('È«ÆÁ½ØÍ¼·µ»Ø¿Õ¶ÔÏó');
- }
- } else {
- printl('´íÎó: screen.screenShotFull·½·¨²»¿ÉÓÃ');
- }
-
- return screenshot;
- } catch (e) {
- printl('È«ÆÁ½ØÍ¼Ê§°Ü: ' + (e.message || e));
- return null;
- }
- },
-
- /**
- * ²¶»ñÇøÓò½ØÍ¼²¢»º´æ
- * @param {String} key ¿ÉÑ¡µÄ»º´æ¼üÃû£¬²»ÌṩÔòʹÓÃĬÈϼü
- * @param {Number} x ÆðʼX×ø±ê
- * @param {Number} y ÆðʼY×ø±ê
- * @param {Number} width ¿í¶È
- * @param {Number} height ¸ß¶È
- * @returns {Object} ½ØÍ¼¶ÔÏó£¬Èç¹ûʧ°ÜÔò·µ»Ønull
- */
- captureRegion: function(key, x, y, width, height) {
- // ²ÎÊýÑéÖ¤
- if (typeof x !== 'number' || typeof y !== 'number' ||
- typeof width !== 'number' || typeof height !== 'number' ||
- width <= 0 || height <= 0) {
- printl('´íÎó: ½ØÍ¼ÇøÓò²ÎÊýÎÞЧ');
- return null;
- }
-
- // ÉèÖÃĬÈϼü
- key = key || 'default';
-
- try {
- // ¼ì²éAIWROK»·¾³
- if (typeof screen === 'undefined') {
- printl('´íÎó: AIWROK½ØÍ¼Ä£¿é²»¿ÉÓÃ');
- return null;
- }
-
- printl('Ö´ÐÐÇøÓò½ØÍ¼: x=' + x + ', y=' + y + ', width=' + width + ', height=' + height);
- var screenshot = null;
-
- // ³¢ÊÔÇøÓò½ØÍ¼
- if (typeof screen.screenShot === 'function') {
- // ³¢ÊÔ²»Í¬²ÎÊý¸ñʽ
- try {
- screenshot = screen.screenShot(width, height, 100);
- } catch (e1) {
- // ³¢ÊÔËIJÎÊý¸ñʽ
- try {
- screenshot = screen.screenShot(x, y, width, height);
- } catch (e2) {
- printl('ÇøÓò½ØÍ¼Ê§°Ü: ' + (e2.message || e2));
- }
- }
-
- // Èç¹ûÇøÓò½ØÍ¼Ê§°Ü£¬³¢ÊÔÈ«ÆÁ½ØÍ¼×÷Ϊ±¸Ñ¡
- if (!screenshot) {
- printl('ÇøÓò½ØÍ¼Ê§°Ü£¬³¢ÊÔÈ«ÆÁ½ØÍ¼×÷Ϊ±¸Ñ¡');
- screenshot = this.captureFullScreen('temp_full');
- if (screenshot) {
- printl('ʹÓÃÈ«ÆÁ½ØÍ¼×÷ÎªÌæ´ú');
- }
- }
- } else {
- printl('´íÎó: screen.screenShot·½·¨²»¿ÉÓÃ');
- }
-
- if (screenshot) {
- // »º´æ½ØÍ¼
- this._cache = screenshot;
- this._cacheKey = key;
- this._cacheTimestamp = new Date().getTime();
- }
-
- return screenshot;
- } catch (e) {
- printl('ÇøÓò½ØÍ¼Ê§°Ü: ' + (e.message || e));
- return null;
- }
- },
-
- /**
- * »ñÈ¡µ±Ç°»º´æµÄ½ØÍ¼
- * @returns {Object} »º´æµÄ½ØÍ¼¶ÔÏó£¬Èç¹ûûÓлº´æÔò·µ»Ønull
- */
- getCachedScreenshot: function() {
- if (this._cache) {
- printl('»ñÈ¡»º´æµÄ½ØÍ¼: ' + this._cacheKey);
- } else {
- printl('ûÓлº´æµÄ½ØÍ¼');
- }
- return this._cache;
- },
-
- /**
- * Êͷŵ±Ç°»º´æµÄ½ØÍ¼×ÊÔ´
- * @returns {Boolean} ÊÇ·ñÊͷųɹ¦
- */
- releaseCache: function() {
- if (!this._cache) {
- printl('ûÓпÉÊͷŵĻº´æ');
- return false;
- }
-
- try {
- // ³¢ÊÔ°²È«ÊÍ·Å×ÊÔ´
- if (typeof this._cache === 'object') {
- // ÕâÀï¿ÉÒÔÌí¼ÓÌØ¶¨µÄ×ÊÔ´ÊÍ·ÅÂß¼
- // ÀýÈçµ÷ÓÃÌØ¶¨µÄÊÍ·Å·½·¨µÈ
- printl('ÊͷŽØÍ¼×ÊÔ´');
- }
-
- // ÇåÀí»º´æÒýÓÃ
- this._cache = null;
- this._cacheKey = null;
- this._cacheTimestamp = null;
-
- printl('»º´æÒѳɹ¦ÊÍ·Å');
- return true;
- } catch (e) {
- printl('ÊÍ·Å»º´æÊ§°Ü: ' + (e.message || e));
- return false;
- }
- },
-
- /**
- * ¼ì²éÊÇ·ñÓлº´æµÄ½ØÍ¼
- * @returns {Boolean} ÊÇ·ñÓлº´æ
- */
- hasCache: function() {
- return this._cache !== null;
- },
-
- /**
- * »ñÈ¡µ±Ç°»º´æµÄÐÅÏ¢
- * @returns {Object} »º´æÐÅÏ¢
- */
- getCacheInfo: function() {
- return {
- hasCache: this._cache !== null,
- key: this._cacheKey,
- timestamp: this._cacheTimestamp,
- age: this._cacheTimestamp ? new Date().getTime() - this._cacheTimestamp : 0
- };
- },
-
- /**
- * ²é¿´µ±Ç°»º´æµÄ½ØÍ¼
- * Ö±½ÓʹÓÃprintlÊä³öͼƬ¶ÔÏ󣬷ûºÏAIWROK»·¾³µÄʵ¼ÊʹÓ÷½Ê½
- * @returns {Boolean} ÊÇ·ñ³É¹¦ÏÔʾͼƬ
- */
- viewCachedImage: function() {
- if (!this._cache) {
- printl('´íÎó: ûÓпɲ鿴µÄ»º´æÍ¼Æ¬');
- return false;
- }
-
- try {
- printl('ʹÓÃprintlÖ±½ÓÊä³öͼƬ¶ÔÏó:');
- // ¸ù¾ÝÓû§·´À¡£¬Ö±½ÓʹÓÃprintlÊä³öͼƬ¶ÔÏóÊÇ×îÓÐЧµÄ·½Ê½
- printl(this._cache);
- printl('ͼƬ´òÓ¡Íê³É');
- return true;
- } catch (e) {
- printl('ÏÔʾͼƬʧ°Ü: ' + (e.message || e));
- return false;
- }
- }
- };
- /**
- * ²âÊÔͼƬÏÔʾ¹¦ÄÜ
- * ¹¦ÄÜ£º²âÊÔʹÓÃprintlÖ±½ÓÊä³öͼƬ¶ÔÏóµÄ·½·¨
- * @param {Object} imageObj ¿ÉÑ¡µÄͼƬ¶ÔÏó£¬Èç¹û²»ÌṩÔò³¢ÊÔ½ØÍ¼
- */
- function testImageDisplay(imageObj) {
- printl('=== ͼƬÏÔʾ¹¦ÄܲâÊÔ ===');
-
- // Èç¹ûûÓÐÌṩͼƬ¶ÔÏ󣬳¢ÊÔ½ØÍ¼
- var testImage = imageObj || null;
- if (!testImage) {
- printl('\nÕýÔÚ²¶»ñ²âÊÔ½ØÍ¼...');
- testImage = ScreenshotCache.captureFullScreen('test_display');
- if (!testImage) {
- printl('´íÎó: ÎÞ·¨»ñÈ¡²âÊÔͼƬ');
- return false;
- }
- }
-
- printl('\nʹÓÃprintlÖ±½ÓÊä³öͼƬ¶ÔÏó...');
-
- try {
- // ¸ù¾ÝÓû§·´À¡£¬Ö±½ÓʹÓÃprintlÊä³öͼƬ¶ÔÏóÊÇ×îÓÐЧµÄ·½Ê½
- printl('ͼƬ¶ÔÏóÐÅÏ¢:');
- printl(testImage);
- printl('\n²âÊÔ½á¹û: ³É¹¦Ê¹ÓÃprintlÊä³öͼƬ');
- return true;
- } catch (e) {
- printl('\n²âÊÔ½á¹û: ʧ°Ü - ' + (e.message || e));
- return false;
- }
- }
- /**
- * ¼òµ¥Ê¹ÓÃʾÀý
- */
- function screenshotExample() {
- printl('=== AIWROK½ØÍ¼»º´æ¹¤¾ßʾÀý ===');
-
- // 1. Ö´ÐÐÈ«ÆÁ½ØÍ¼
- printl('\n1. Ö´ÐÐÈ«ÆÁ½ØÍ¼...');
- var screenshot = ScreenshotCache.captureFullScreen('main_screen');
-
- if (screenshot) {
- printl('È«ÆÁ½ØÍ¼³É¹¦²¢ÒÑ»º´æ');
-
- // 2. ²é¿´»º´æÐÅÏ¢
- printl('\n2. »º´æÐÅÏ¢:');
- var info = ScreenshotCache.getCacheInfo();
- printl(' »º´æ¼ü: ' + info.key);
- printl(' »º´æÄêÁä: ' + info.age + ' ºÁÃë');
-
- // 3. »ñÈ¡»º´æµÄ½ØÍ¼£¨ÀýÈçÓÃÓÚ´¦Àí£©
- printl('\n3. »ñÈ¡»º´æµÄ½ØÍ¼...');
- var cachedScreenshot = ScreenshotCache.getCachedScreenshot();
-
- if (cachedScreenshot) {
- printl(' ³É¹¦»ñÈ¡»º´æµÄ½ØÍ¼');
- // 4. ²é¿´»º´æµÄͼƬ
- printl('\n4. ²é¿´»º´æµÄͼƬ...');
- printl(' Ìáʾ: ʹÓÃprintlÖ±½ÓÊä³öͼƬ¶ÔÏ󣬷ûºÏAIWROK»·¾³µÄʵ¼ÊʹÓ÷½Ê½');
- var viewResult = ScreenshotCache.viewCachedImage();
- printl(' ͼƬÏÔʾ: ' + (viewResult ? '³É¹¦' : 'ʧ°Ü'));
- }
-
- // 5. ʹÓÃÍê±ÏºóÊÍ·Å»º´æ
- printl('\n5. ÊÍ·Å»º´æ×ÊÔ´...');
- ScreenshotCache.releaseCache();
-
- // 6. ÑéÖ¤»º´æÊÇ·ñÒÑÊÍ·Å
- printl('\n6. ÑéÖ¤»º´æ×´Ì¬:');
- printl(' »º´æ´æÔÚ: ' + (ScreenshotCache.hasCache() ? 'ÊÇ' : '·ñ'));
- } else {
- printl('È«ÆÁ½ØÍ¼Ê§°Ü');
- }
-
- printl('\n=== ʾÀýÖ´ÐÐÍê³É ===');
- }
- /**
- * Ö÷º¯Êý - ÑÝʾ»ù±¾¹¦ÄÜ
- */
- function main() {
- printl('====================================');
- printl(' AIWROK½ØÍ¼»º´æ¹¤¾ß');
- printl('====================================');
- printl('¼òµ¥ÊµÓõĽØÍ¼ºÍ»º´æ¹ÜÀí');
- printl('====================================');
-
- // ÔËÐÐʾÀý
- screenshotExample();
-
- printl('\nʹÓÃ˵Ã÷:');
- printl('1. ½ØÍ¼²¢»º´æ: ScreenshotCache.captureFullScreen(¼üÃû)');
- printl(' »ò ScreenshotCache.captureRegion(¼üÃû, x, y, ¿í, ¸ß)');
- printl('2. »ñÈ¡»º´æ: ScreenshotCache.getCachedScreenshot()');
- printl('3. ²é¿´Í¼Æ¬: ScreenshotCache.viewCachedImage()');
- printl(' (ʹÓÃprintlÖ±½ÓÊä³öͼƬ¶ÔÏ󣬷ûºÏAIWROK»·¾³µÄʵ¼ÊʹÓ÷½Ê½)');
- printl('4. ÊÍ·Å»º´æ: ScreenshotCache.releaseCache()');
- printl('5. ¼ì²é»º´æ: ScreenshotCache.hasCache()');
- printl('6. »ñÈ¡ÐÅÏ¢: ScreenshotCache.getCacheInfo()');
- printl('');
- printl('ͼƬÏÔʾ˵Ã÷:');
- printl('- ÒѸù¾ÝAIWROK»·¾³Êµ¼ÊʹÓ÷½Ê½ÓÅ»¯£¬Ö±½ÓʹÓÃprintlÊä³öͼƬ¶ÔÏó');
- printl('- ÄúÒ²¿ÉÒÔÖ±½Ó»ñÈ¡»º´æµÄͼƬ¶ÔÏóºóÊÖ¶¯Ê¹ÓÃprintlÊä³ö:');
- printl(' var img = ScreenshotCache.getCachedScreenshot();');
- printl(' printl(img);');
- printl('====================================');
- }
- main()
¸´ÖÆ´úÂë
|
|