zoukankan      html  css  js  c++  java
  • 截取屏幕的一块区域并且声称图片

    在游戏开发过程中,我们经常遇到让我们分享截图的功能,这个时候首先要接入对应分享平台的SDK,然后在把截取的区域按照SDK相应的格式发送过去,达到相应的目的,接下来直接上代码,

    // Call after WaitForEndOfFrame.
        private IEnumerator ShareToSocialNetworkShareOnly_Internal(RectTransform shareArea)
        {
            yield return new WaitForEndOfFrame();
    
            var reqInfo = new MSDKFriendReqInfo();
            reqInfo.Type = (int)FriendReqType.Friend_REQ_IMG;
            reqInfo.ImagePath = ProcessShareTexture(shareArea);
            //reqInfo.ThumbPath = appSmallIconPath;
            MSDKFriend.Share(reqInfo);
        }
    
    
    private string ProcessShareTexture(RectTransform shareArea)
        {
            // Delete old image path.
            string shareImgPath = Path.Combine(Application.temporaryCachePath, "ShareImage.png");
            FileUtility.DeleteFileIfExist(shareImgPath);
    
            // Get the share screen size we need.
            Rect shareScreenRect = GetShareScreenSize(Camera.main, UIWindowManager.Instance.m_UICamera, shareArea);
    
            // Read screen pixels into share texture.
            Texture2D shareTexture = AcquireShareTexture((int)shareScreenRect.width, (int)shareScreenRect.height);
            shareTexture.ReadPixels(shareScreenRect, 0, 0, false);
            shareTexture.Apply();
    
            // Save share texture data.
            byte[] imageData = shareTexture.EncodeToPNG();
            File.WriteAllBytes(shareImgPath, imageData);
            Debug.Log("Save share image to: " + shareImgPath);
    
            return shareImgPath;
        }

    先截图,然后把相应的截图在unity运行时保存在临时缓存区域,可以在运行游戏时预览效果

  • 相关阅读:
    VC6.0图形处理7边缘检测
    VC6.0图像处理0bmp文件分析
    java版QQ 欢迎点评
    VC6.0图像处理3灰度变换
    VC6.0图形处理6图像增强
    VC6.0图像处理1浏览图片
    VC6.0图像处理4镜像
    一个软件行业中层主管在年底给团队成员的一封信
    SQL的EXISTS与in、not exists与not in 效率比较和使用
    按某字段合并字符串
  • 原文地址:https://www.cnblogs.com/qinshuaijun/p/11634539.html
Copyright © 2011-2022 走看看