void OnConvertImage() { ShotDeviceInfo infoMain = GetMainDevice(deviceInfoNow); if (infoMain == null) { return; } Debug.Log("OnConvertImage name =" + infoMain.name); string filepath_src = GetSaveScreenShotFilePath(infoMain, false); //jpg { string filepath_dst = GetSaveScreenShotFilePath(deviceInfoNow, false); Texture2D texSrc = LoadTexture.LoadFromFile(filepath_src); Texture2D texDst = TextureUtil.ConvertSize(texSrc, deviceInfoNow.width, deviceInfoNow.height); TextureUtil.SaveTextureToFile(texDst, filepath_dst); } //png { string filepath_dst = GetSaveScreenShotFilePath(deviceInfoNow, true); Texture2D texSrc = LoadTexture.LoadFromFile(filepath_src); Texture2D texDst = TextureUtil.ConvertSize(texSrc, deviceInfoNow.width, deviceInfoNow.height); TextureUtil.SaveTextureToFile(texDst, filepath_dst); } }
void ConvertImage(string pathImgae, string savedir, GuankaJsonItemInfo info, string ext, int w, int h) { Texture2D tex = LoadTexture.LoadFromFile(pathImgae); float scale = 1f; { scale = Common.GetBestFitScale(tex.width, tex.height, w, h); w = (int)(tex.width * scale); h = (int)(tex.height * scale); Debug.Log("autoguankajson scale=" + scale + " tex.width=" + tex.width); Texture2D texNew = TextureUtil.ConvertSize(tex, w, h); FileUtil.CreateDir(savedir); string filepath_new = savedir + "/" + info.id + "." + ext; TextureUtil.SaveTextureToFile(texNew, filepath_new); } }
public void DoSave() { string filedir = GetSaveDir(deviceInfoNow); bool isSavePng24Bit = false; string filepath = GetSaveScreenShotFilePath(deviceInfoNow, false); if (deviceInfoNow.name == ScreenDeviceInfo.DEVICE_NAME_AD) { filepath = filedir + "/ad_home_" + deviceInfoNow.width + "x" + deviceInfoNow.height + ".png"; isSavePng24Bit = true; } if (deviceInfoNow.name == ScreenDeviceInfo.DEVICE_NAME_ICON) { filepath = filedir + "/icon.jpg";//png //没有alpha //isSavePng24Bit = true; } if (deviceInfoNow.name == ScreenDeviceInfo.DEVICE_NAME_COPY_RIGHT_HUAWEI) { filepath = filedir + "/huawei.png"; } bool isRealGameUI = false; if (shotItemInfo != null) { isRealGameUI = shotItemInfo.isRealGameUI; } Texture2D screenShot = null; if (isRealGameUI) { screenShot = GetTextureOfScreen(); } else { //save camera Vector2 size = new Vector2(deviceInfoNow.width, deviceInfoNow.height); screenShot = GetTextureOfCamera(size); } Texture2D texSave = null; if (isSavePng24Bit) { texSave = TextureUtil.ConvertSize(screenShot, screenShot.width, screenShot.height, TextureFormat.RGB24); } else { texSave = screenShot; } //拉伸大小 if ((texSave.width != deviceInfoNow.width) && (texSave.height != deviceInfoNow.height)) { texSave = TextureUtil.ConvertSize(texSave, deviceInfoNow.width, deviceInfoNow.height, texSave.format); } bool isSaveFile = true; //if (deviceInfoNow.name == ScreenDeviceInfo.DEVICE_NAME_ICON) { if (FileUtil.FileIsExist(filepath)) { //不覆盖原来的文件 isSaveFile = false; } } // 最后将这些纹理数据,成一个png图片文件 if (isSaveFile) { TextureUtil.SaveTextureToFile(texSave, filepath); } //ScreenCapture.CaptureScreenshot(filepath); //保存圆角的android icon // if (deviceInfoNow.name == ScreenDeviceInfo.DEVICE_NAME_ICON) // { // filepath = filedir + "/icon_android.png"; // Texture2D texTmp = RoundRectTexture(screenShot); // TextureUtil.SaveTextureToFile(texTmp, filepath); // //512x512 // Texture2D tex512 = TextureUtil.ConvertSize(texTmp, 512, 512); // filepath = filedir + "/icon_android_512.png"; // TextureUtil.SaveTextureToFile(tex512, filepath); // } Debug.Log(string.Format("截屏了一张照片: {0}", filepath)); if (!isRunDoAutoSaveOneScreenShot) { ShowScreenShotUI(true); } }
public void DoSave() { string filedir = GetSaveDir(deviceInfoNow); bool isSavePng24Bit = false; string filepath = GetSaveScreenShotFilePath(deviceInfoNow); if (deviceInfoNow.name == DEVICE_NAME_AD) { filepath = filedir + "/ad_home_" + deviceInfoNow.width + "x" + deviceInfoNow.height + ".png"; isSavePng24Bit = true; } if (deviceInfoNow.name == DEVICE_NAME_ICON) { filepath = filedir + "/icon.png"; //没有alpha isSavePng24Bit = true; } if (deviceInfoNow.name == DEVICE_NAME_COPY_RIGHT_HUAWEI) { filepath = filedir + "/huawei.png"; } bool isRealGameUI = false; if (shotItemInfo != null) { isRealGameUI = shotItemInfo.isRealGameUI; } Texture2D screenShot = null; if (isRealGameUI) { screenShot = GetTextureOfScreen(); } else { //save camera Vector2 size = new Vector2(deviceInfoNow.width, deviceInfoNow.height); screenShot = GetTextureOfCamera(size); } Texture2D texSave = null; if (isSavePng24Bit) { texSave = TextureUtil.ConvertSize(screenShot, screenShot.width, screenShot.height, TextureFormat.RGB24); } else { texSave = screenShot; } // 最后将这些纹理数据,成一个png图片文件 TextureUtil.SaveTextureToFile(texSave, filepath); //ScreenCapture.CaptureScreenshot(filepath); //保存圆角的android icon if (deviceInfoNow.name == DEVICE_NAME_ICON) { filepath = filedir + "/icon_android.png"; Texture2D texTmp = RoundRectTexture(screenShot); TextureUtil.SaveTextureToFile(texTmp, filepath); //512x512 Texture2D tex512 = TextureUtil.ConvertSize(texTmp, 512, 512); filepath = filedir + "/icon_android_512.png"; TextureUtil.SaveTextureToFile(tex512, filepath); } Debug.Log(string.Format("截屏了一张照片: {0}", filepath)); }