private void LoadBackgroundImage(string path) { if (File.Exists(path)) { byte[] data = File.ReadAllBytes(path); Texture2D tex = new Texture2D(2, 2); if (tex.LoadImage(data)) { NoneImage.SetActive(false); ImageText.SetActive(false); BackgroundRawImage.SetActive(true); TextureScale.Bilinear(tex, BackgroundImageWidth, BackgroundImageHeight); BackgroundRawImage.GetComponent <Image>().sprite = Sprite.Create(tex, new Rect(0, 0, BackgroundImageWidth, BackgroundImageHeight), new Vector2(0, 0)); PlayerPrefs.SetString(Constants.BACKGROUND_IMG_KEY, path); } else { ErrorBackgroundImage(); } } else { ErrorBackgroundImage(); } }
public static Texture CreateSelectorThumbnail(Texture tex) { Texture2D thumb = new Texture2D(tex.width, tex.height); var pixels = (tex as Texture2D).GetPixels(); thumb.SetPixels(pixels); thumb.Apply(); if (tex.width >= tex.height) { TextureScale.Bilinear(thumb, 100, (tex.height * 100) / tex.width); } else // if (tex.width < tex.height) { TextureScale.Bilinear(thumb, (tex.width * 100) / tex.height, 100); } for (int x = 0; x < thumb.width; x++) { for (int y = 0; y < thumb.height; y++) { Color color = thumb.GetPixel(x, y); thumb.SetPixel(x, y, Color.Lerp(color, Color.white, .32f).KeepAlphaFrom(color)); } } thumb.Apply(); return(thumb as Texture); }
public void SetData(MapData pData) { m_stBound.Set(pData.bound_left, pData.bound_bottom, pData.bound_right - pData.bound_left, pData.bound_top - pData.bound_bottom); Gravity = pData.gravity; AirResistance = pData.air_resistance; wind_range = pData.wind_range; wind_step = pData.wind_step; for (int i = 0; i < pData.m_listTerrain.Count; ++i) { MapCellData cellData = pData.m_listTerrain[i]; var srcTexture = GameGOW.Get().ResourceMgr.GetRes <Texture2D>(cellData.resource); Texture2D terrain = new Texture2D(srcTexture.width, srcTexture.height); terrain.SetPixels(srcTexture.GetPixels()); terrain.Apply(); //因原图采用了压缩格式,长宽有变化,并非最初设计效果,所以这里对创建的图重新设置长宽(设置为原图的长宽值,值由地形的XML读入) TextureScale.Bilinear(terrain, cellData.Width, cellData.Height); Tile tile = new Tile(cellData.pos_x * 100, cellData.pos_y * 100, terrain); tile.m_bIsDigable = cellData.digable; if (cellData.digable) { m_listTerrains.Add(tile); } else { m_listStones.Add(tile); } if (OnTerrainCellNew != null) { OnTerrainCellNew(terrain, cellData); } } }
public IEnumerator ShowPreview(int index) { var entry = entries[index - inactiveExplorerPanelItems.Count]; if (entry.entryType == EntryType.File && IsImage(entry.extension)) { texturesToDestroy.Enqueue(previewImage.texture); using (var request = UnityWebRequestTexture.GetTexture("file://" + entry.fullPath, false)) { yield return(request.SendWebRequest()); var texture = DownloadHandlerTexture.GetContent(request); var newSize = MathHelper.ScaleRatio(new Vector2(texture.width, texture.height), previewHolder.rect.size); TextureScale.Point(texture, (int)newSize.x, (int)newSize.y); texturesToDestroy.Enqueue(previewImage.texture); previewImage.texture = texture; previewImage.color = Color.white; previewImage.rectTransform.sizeDelta = newSize; previewHolder.gameObject.SetActive(true); } } }
private Texture2D resizeLeaf(Texture2D singleLeaf, float multiplier) { Texture2D newTex = Texture2D.Instantiate(singleLeaf) as Texture2D; TextureScale.Bilinear(newTex, (int)(singleLeaf.width * multiplier), (int)(singleLeaf.height * multiplier)); return(newTex); }
public IEnumerator ExportFrame() { while (true) { if (sendToAWS && !isRunning) { isRunning = true; yield return(frameEnd); tex.Resize(arCam.pixelWidth, arCam.pixelHeight); tex.ReadPixels(screenRect, 0, 0); tex.Apply(); TextureScale.Bilinear(tex, tex.width / 2, tex.height / 2); croppedTex = TextureTools.ResampleAndCrop(tex, tex.width, tex.height / 2 + 100); frameBytes = croppedTex.EncodeToJPG(); dataToStream.ApproximateCaptureTime = System.DateTime.UtcNow; dataToStream.FrameCount = Time.frameCount; dataToStream.ImageBytes = frameBytes; JSONdataToStream = dataToStream.serialize(); _C.PutRecord(JSONdataToStream, "FrameStream", (response) => { }); frameBytes = null; JSONdataToStream = null; isRunning = false; } yield return(exportInterval); } }
/// <summary> /// Takes a texture, changes its height and width to a certain fraction of screen height (1/size). /// </summary> private static int ResizeCursorSprite(Texture2D texture, int size) { int pixelSize = Screen.height / size; TextureScale.Bilinear(texture, pixelSize, pixelSize); return(pixelSize); }
void detectHoles() { renderTexture.DiscardContents(); RenderTexture.active = camera.GetComponent <Camera> ().targetTexture; camera.GetComponent <Camera> ().Render(); texture.filterMode = FilterMode.Point; texture.wrapMode = TextureWrapMode.Clamp; texture.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0); texture.Apply(); for (int i = 0; i < 4; i++) { TextureScale.Half(texture); } FloodFill.Fill(texture, 0, 0); FloodFill.Fill(texture, texture.width - 1, 0); FloodFill.Fill(texture, texture.width - 1, texture.height - 1); FloodFill.Fill(texture, 0, texture.height - 1); // holes ConnectedComponentLabeling ccl = new ConnectedComponentLabeling(); ccl.Process(texture, texture, false, false); holesPositions = ccl.holesAveragePositions; holesPositions.Add(new Vector2(0f, 0f)); holesPositions.Add(new Vector2((float)texture.width, 0f)); holesPositions.Add(new Vector2(0f, (float)texture.height)); holesPositions.Add(new Vector2((float)texture.width, (float)texture.height)); }
public IEnumerator Save(EdgeTexture EdgeTex) { yield return(new WaitForEndOfFrame()); var texRate = (float)EdgeTex.Texture.width / EdgeTex.Texture.height; // スクショは画面全体ではなく表示されている書き込み用キャンバスと同サイズにする var height = Screen.height; var width = Mathf.RoundToInt(Screen.height * texRate * EdgeTexture.RESOLUTION_RATE); var canvasRate = 1820f / 1920f; var left = (Screen.width * canvasRate - width) * 0.5f; // 横長の画像の場合 var bottom = 0f; if (width > Screen.width) { // 画面幅以上のwidthを画面幅に合わせる var applyRate = Screen.width * canvasRate / width; width = Mathf.RoundToInt(applyRate * width); height = Mathf.RoundToInt(applyRate * height); left = 0; bottom = EdgeTex.RectTransformBottom * 0.5f; } var tex = new Texture2D(width, height, TextureFormat.RGB24, false); tex.name = EdgeTex.Texture.name; tex.ReadPixels(new Rect(left, bottom, width, height), 0, 0); tex.Apply(); TextureScale.Point(tex, Mathf.RoundToInt(Screen.height * texRate), height); yield return(EdgeTex.StartCoroutine(WriteFile(tex))); }
private static Texture2D Load(string texfile) { if (!outUtil.Exists(texfile)) { return(null); } Texture2D tex = null; LogUtil.Debug("load tex:", texfile); try { tex = outUtil.LoadTexture(texfile); // サイズ変更 if (tex.width <= 1 || tex.height <= 1) { TextureScale.Point(tex, IMG_WIDTH, IMG_HEIGHT); } else { TextureScale.Bilinear(tex, IMG_WIDTH, IMG_HEIGHT); } } catch (Exception e) { LogUtil.Debug(e); } return(tex); }
public void testLocalImage() { string filePath = "Assets/test2.jpg"; Texture2D texture = new Texture2D(300, 200, TextureFormat.RGB24, false); texture.anisoLevel = 1; texture.filterMode = FilterMode.Bilinear; texture.wrapMode = TextureWrapMode.Clamp; byte[] fileData = null; if (File.Exists(filePath)) { fileData = File.ReadAllBytes(filePath); texture.LoadImage(fileData); //..this will auto-resize the texture dimensions. } TextureScale.Bilinear(texture, texture.width / 10, texture.height / 10); Sprite picture = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero, 1); _imageResult.sprite = picture; byte[] imgData = texture.EncodeToPNG(); detectface(imgData); }
public override void OnEnter() { if (texture.IsNone || texture.Value == null) { Debug.LogWarning("<b>[ResizeTexture]</b><color=#FF9900ff> Empty Input - Please review!</color>", this.Owner); Finish(); } if (newTexture.IsNone || newTexture.Value == null) { Debug.LogWarning("<b>[ResizeTexture]</b><color=#FF9900ff> Empty Output - Please review!</color>", this.Owner); Finish(); } texItem = texture.Value as Texture2D; switch (filterMode) { case FilterMode.Point: TextureScale.Point(texItem, setWidth.Value, setHeight.Value); break; case FilterMode.Biliner: TextureScale.Bilinear(texItem, setWidth.Value, setHeight.Value); break; } newTexture.Value = texItem; texItem = null; Finish(); }
//-------------------------------------------------------------------------- void JpgToTexture2D() { string aaa = _file.Substring(0, _file.Length - 4); _texture = (Texture2D)Resources.Load(aaa); //Texture2D t2d = _texture as Texture2D; //t2d. //Resources. //_texture360 = ResizeTexture(_texture as Texture2D, 360, 180); _textureSmall = Texture2D.Instantiate(_texture); TextureScale.Bilinear(_textureSmall, 360, 180); return; //// /* * // string path = ""; * * * System.IO.FileStream stream = new System.IO.FileStream (path, System.IO.FileMode.Open, System.IO.FileAccess.Read); * System.IO.BinaryReader reader = new System.IO.BinaryReader (stream); * byte[] data = reader.ReadBytes ((int)reader.BaseStream.Length); * reader.Close (); * * System.Drawing.Image image = System.Drawing.Image.FromStream (stream); * * _texture = new Texture2D (image.Width, image.Height); * _texture.LoadImage (data); */ }
// 47 Create the method to run predictions on the grid and update /// <summary> /// Runs the predictioin model on the grid /// </summary> /// <param name="allLayers">If it should run on all layers. Default is only layer 0</param> void PredictAndUpdate(bool allLayers = false) { // 49 Set the red voxels to empty _voxelGrid.ClearReds(); // 50 Define how many layers will be used based on bool int layerCount = 1; if (allLayers) { layerCount = _voxelGrid.GridSize.y; } // 51 Iterate through all layers, running the model for (int i = 0; i < layerCount; i++) { // 52 Get the image from the grid's layer var gridImage = _voxelGrid.ImageFromGrid(layer: i); // 53 Resize the image to 256x256 ImageReadWrite.Resize256(gridImage, Color.grey); // 54 Run the inference model on the image var image = _pix2pix.Predict(gridImage); // 56 Scale the image back to the grid size TextureScale.Point(image, _voxelGrid.GridSize.x, _voxelGrid.GridSize.z); // 57 Set the layer's voxels' states to the grid _voxelGrid.SetStatesFromImage(image, layer: i); } }
public void SendWebcamFrame() { //if we have enough stored frames to match the latency if (webcamLatencyBuffer.Count >= Mathf.CeilToInt(webcamFramerate * latency * 2.3f)) { byte[] frameToSend = webcamLatencyBuffer[0]; //send the byte array to the server ClientSend.SendWebcamFrame(frameToSend.Length, frameToSend); webcamLatencyBuffer.RemoveAt(0); } if (webCamTexture != null) { //create a texture2D Texture2D _tex = new Texture2D(webCamTexture.width, webCamTexture.height); //set the texture2D pixels to be the webcamTexture's pixels _tex.SetPixels32(webCamTexture.GetPixels32()); //scale down the texture2D for performance reasons TextureScale.Bilinear(_tex, 100, 75); //get the texture2D as a byte array byte[] texBytes = _tex.GetRawTextureData(); //save the frame data to the webcam latency buffer webcamLatencyBuffer.Add(texBytes); } }
public void Output_AlbumPicturePNG(Texture2D texture, Json_Album_Data_Picture Picture) { //本体PNG { var directory = new DirectoryInfo(getAlbumPicturesPath()); if (!directory.Exists) { directory.Create(); } // テクスチャを PNG に変換 byte[] bytes = texture.EncodeToPNG(); // PNGデータをファイルとして保存 File.WriteAllBytes(directory.FullName + "/" + Picture.FileName, bytes); } //圧縮PNG { var directory = new DirectoryInfo(getAlbumSmallPicturesPath()); if (!directory.Exists) { directory.Create(); } //圧縮 TextureScale.Bilinear(texture, (int)(texture.width * 0.1f), (int)(texture.height * 0.1f)); // テクスチャを PNG に変換 byte[] bytes = texture.EncodeToPNG(); // PNGデータをファイルとして保存 File.WriteAllBytes(directory.FullName + "/" + Picture.FileName_Small, bytes); } }
private byte[] ConvertTexture(Texture t, MPTextureType texType) { Texture2D texture2D = null; if (t.width <= 4096 && t.height <= 4096) { texture2D = new Texture2D(t.width, t.height, TextureFormat.RGB24, false); RenderTexture currentRT = RenderTexture.active; RenderTexture renderTexture = new RenderTexture(t.width, t.height, 32); Graphics.Blit(t, renderTexture); RenderTexture.active = renderTexture; texture2D.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0); texture2D.Apply(); if (texture2D.width > 1024 || texture2D.height > 1024) { TextureScale.Bilinear(texture2D, 1024, 1024); } RenderTexture.active = currentRT; } return(texture2D == null ? new byte[1] { 0 } : texture2D.EncodeToJPG(80)); }
/// <summary> /// Corutine that captures an image from the camera, obtains its relevant data /// and sends the corresponding header and chunk messages. /// </summary> /// <returns>IEnumerator to be run.</returns> protected override IEnumerator SendStream() { uint textId = nextId; nextId += 1; Debug.Log("Sending snapshoot with ID " + textId + "."); //Texture2D texture = Paint(1000); int minTexSide = Mathf.Min(cam.width, cam.height); int x = minTexSide == cam.width ? 0 : (cam.width - minTexSide) / 2; int y = minTexSide == cam.height ? 0 : (cam.height - minTexSide) / 2; Texture2D texture = new Texture2D(minTexSide, minTexSide); texture.SetPixels(cam.GetPixels(x, y, minTexSide, minTexSide)); texture.Apply(true); TextureScale.Bilinear(texture, resolution, resolution); //lastCapturedFrame = texture; Color32[] pixelData = texture.GetPixels32(0); int size = Mathf.FloorToInt(pixelData.Length / Mathf.Ceil(pixelData.Length * 4.0f / maxChunkSize)); Debug.Log("Chunk size " + size); var headerMessage = new TextureHeaderMessage(networkIdentity.netId.Value, textId, texture.width, texture.height, size); SendHeaderMessage(textureMsgType, headerMessage); List <(int, Color32[], int)> chunks = DivideArrayInChunks(pixelData, size); foreach (var chunk in chunks) { var chunkMessage = new TextureChunkMessage(networkIdentity.netId.Value, textId, chunk.Item1, chunk.Item2, chunk.Item3); SendChunkMessage(textureMsgType, chunkMessage); } Debug.Log("SnapShoot for ID " + textId + " has been sent."); yield return(new WaitForSeconds(0.01f)); }
public void RealStart(bool[,] blockArray, int direction, int team_id, Color color) { // blockArray should be 5x5 blocks = new GameObject[5, 5]; System.Random rand = new System.Random(); string[] FileList = Directory.GetFiles(@"C:\temp2\", "*.png"); byte[] bytes; bytes = System.IO.File.ReadAllBytes(FileList[rand.Next(0, FileList.Length - 1)]); for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { if (blockArray[i, j]) { Vector3 newPos = transform.position + new Vector3(direction * j * block.GetComponent <Renderer>().bounds.size.x, -i * block.GetComponent <Renderer>().bounds.size.y, 0); GameObject b = (GameObject)Instantiate(block, newPos, Quaternion.identity); b.GetComponent <Mover>().MoveSpeed = direction * 1.5f; b.GetComponent <Mover>().team_id = team_id; Texture2D tex = new Texture2D(12, 12); ///while(!www.isDone) { } ///www.LoadImageIntoTexture(tex); tex.LoadImage(bytes); TextureScale.Bilinear(tex, 12, 12); Sprite sprite = Sprite.Create(tex, new Rect(0, 0, 12, 12), new Vector2(0, 0)); b.GetComponent <SpriteRenderer>().sprite = sprite; b.GetComponent <SpriteRenderer>().color = color; blocks[i, j] = b; } } } LastBlocks = BlockAmount(); }
public TextureCrop(Texture2D initialTexture, Rect rect) { if (initialTexture == null) { Debug.LogError("Texture passed is null"); return; } if (rect.xMin > initialTexture.width || rect.yMin > initialTexture.height || rect.xMax > initialTexture.width || rect.yMax > initialTexture.height) { int reqWidth = (int)rect.xMax, reqHeight = (int)rect.yMax, newWidth = 0, newHeight = 0; if (reqWidth > reqHeight) { newWidth = reqWidth; newHeight = initialTexture.height * newWidth / initialTexture.width; } else { newHeight = reqHeight; newWidth = initialTexture.width * newHeight / initialTexture.height; } TextureScale.Point(initialTexture, newWidth, newHeight); } processedTexture = new Texture2D((int)rect.width, (int)rect.height); var p = initialTexture.GetPixels((int)rect.xMin, (int)rect.yMin, (int)rect.width, (int)rect.height); processedTexture.SetPixels(p); processedTexture.Apply(); }
private IEnumerator LoadFileThumbnail(List <ExplorerEntry> entries) { foreach (var entry in entries) { var icon = entry.explorerPanelItem.icon; if (entry.entryType == EntryType.File && IsImage(entry.extension)) { //NOTE(Simon): Cancel any remaining request, if the previous coroutine was cancelled partway through using (var request = UnityWebRequestTexture.GetTexture("file://" + entry.fullPath, false)) { yield return(request.SendWebRequest()); var texture = DownloadHandlerTexture.GetContent(request); var newSize = MathHelper.ScaleRatio(new Vector2(texture.width, texture.height), entry.explorerPanelItem.iconHolder.rect.size); yield return(new WaitForEndOfFrame()); TextureScale.Point(texture, (int)newSize.x, (int)newSize.y); icon.texture = texture; icon.color = Color.white; icon.rectTransform.sizeDelta = newSize; } } } }
// 選択した画像データを表示 private void DrawSelectedImage() { EditorGUILayout.BeginVertical(); if (subWindow != null) { if (subWindow.selected == 0) { GUILayout.FlexibleSpace(); GUILayout.Label("select : " + selectedTerra); if (terratex[(int)selectedTerra] != null) { Texture2D tex = Texture2D.Instantiate(terratex[(int)selectedTerra]); TextureScale.Bilinear(tex, (int)64, (int)64); GUILayout.Box(tex); } } else if (subWindow.selected == 1) { GUILayout.FlexibleSpace(); GUILayout.Label("select : " + selectedObj); if (objtex[(int)selectedObj] != null) { Texture2D tex = Texture2D.Instantiate(objtex[(int)selectedObj]); TextureScale.Bilinear(tex, (int)64, (int)64); GUILayout.Box(tex); } } } EditorGUILayout.EndVertical(); }
// Token: 0x0600036D RID: 877 RVA: 0x0001E658 File Offset: 0x0001C858 private static Texture2D Load(string texfile) { if (!ACCTexturesView.outUtil.Exists(texfile)) { return(null); } Texture2D texture2D = null; LogUtil.Debug(new object[] { "load tex:", texfile }); try { texture2D = ACCTexturesView.outUtil.LoadTexture(texfile); if (texture2D.width <= 1 || texture2D.height <= 1) { TextureScale.Point(texture2D, 90, 5); } else { TextureScale.Bilinear(texture2D, 90, 5); } } catch (Exception ex) { LogUtil.Debug(new object[] { ex }); } return(texture2D); }
private Texture2D ProcessTextureForType(Texture2D sourceTexture, TextureScale textureScale) { Texture2D texture; if (textureScale.HasFlag(TextureScale.Small)) { texture = new Texture2D(sourceTexture.width, sourceTexture.height, TextureFormat.RGBA32, true, false); for (var i = 0; i < sourceTexture.mipmapCount; i++) { var c_0 = sourceTexture.GetPixels(i); var c_1 = texture.GetPixels(i); for (var i1 = 0; i1 < c_0.Length; i1++) { var a = c_0[i1].r + c_0[i1].g + c_0[i1].b; c_1[i1].r = c_1[i1].g = c_1[i1].b = a > 127 ? 0 : 1; c_1[i1].a = c_0[i1].a; } texture.SetPixels(c_1, i); } texture.Apply(); } else { texture = new Texture2D(sourceTexture.width, sourceTexture.height, TextureFormat.RGBA32, true); texture.SetPixels(sourceTexture.GetPixels()); texture.Apply(); } return(texture); }
private void GetOverlayTextures() { for (int i = 0; i < overlays.Length; i++) { if (overlays[i] == null) { continue; } string overlayPath = AssetDatabase.GetAssetPath(overlays[i]); byte[] fileData = File.ReadAllBytes(overlayPath); Texture2D tex = new Texture2D(2, 2); tex.LoadImage(fileData); if (tex.height != 128) { TextureScale.Point(tex, 128, 128); } //Debug.Log("Processing overlay: " + overlayIcons.Count.ToString()); overlayIcons.Add(tex); //Only uncomment these lines, if you know what you are doing. All overlays will be exported to a folder. //byte[] bytes = tex.EncodeToPNG(); //File.WriteAllBytes(Application.dataPath + "/" + "debug" + "/" + overlays[i].name + ".png", bytes); } }
public override int[][] ResizePixels(int[][] pixels, int w1, int h1, int w2, int h2) { Console.WriteLine("Resizing in unity"); Texture2D tex = new Texture2D(pixels.Length, pixels[0].Length); for (int i = 0; i < tex.width; i++) { for (int j = 0; j < tex.height; j++) { tex.SetPixel(i, j, intToColor(pixels[i][j])); } } tex.Apply(); TextureScale.Bilinear(tex, w2, h2); int[][] values = new int[tex.width][]; for (int x = 0; x < tex.width; x++) { values[x] = new int[tex.height]; for (int y = 0; y < tex.height; y++) { values[x][y] = ColorToInt(tex.GetPixel(x, y)); } } return(values); }
// Callback for avatar private void handleAvatar(byte[] responseData) { if (_current == null) { Debug.Log("Invalid call avatar"); return; } bool sRGBBackup = GL.sRGBWrite; GL.sRGBWrite = true; Texture2D tex = new Texture2D(4, 4); tex.LoadImage(responseData); #if UNITY_5_6 || UNITY_2017 if (PlayerSettings.colorSpace == ColorSpace.Linear) { var renderTexture = RenderTexture.GetTemporary(tex.width, tex.height, 24); Material linear2SRGB = new Material(Shader.Find("GLTF/Linear2sRGB")); linear2SRGB.SetTexture("_InputTex", tex); Graphics.Blit(tex, renderTexture, linear2SRGB); tex.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0); } #endif TextureScale.Bilinear(tex, (int)AVATAR_SIZE.x, (int)AVATAR_SIZE.y); _current.setAvatar(tex); GL.sRGBWrite = sRGBBackup; if (_refresh != null) { _refresh(); } }
private IEnumerator SaveTexture(Texture2D textureToSave, string pathToFile) { if (!textureToSave || pathToFile.IsNullOrEmpty()) { yield break; } if (MainGui.Instance.ScaleTexture) { //TextureScale.BilinearScale(_textureToSave); textureToSave = TextureScale.Bilinear(textureToSave, int.Parse(MainGui.Instance.XSize), int.Parse(MainGui.Instance.YSize)); } Debug.Log($"Salvando {textureToSave} como {pathToFile}"); if (!pathToFile.Contains(".")) { pathToFile = $"{pathToFile}.{MainGui.Instance.SelectedFormat}"; } var fileIndex = pathToFile.LastIndexOf('.'); var extension = pathToFile.Substring(fileIndex + 1, pathToFile.Length - fileIndex - 1); switch (extension) { case "png": { var pngBytes = textureToSave.EncodeToPNG(); File.WriteAllBytes(pathToFile, pngBytes); break; } case "jpg": { var jpgBytes = textureToSave.EncodeToJPG(); File.WriteAllBytes(pathToFile, jpgBytes); break; } case "tga": { var tgaBytes = textureToSave.EncodeToTGA(); File.WriteAllBytes(pathToFile, tgaBytes); break; } case "exr": { var exrBytes = textureToSave.EncodeToEXR(); File.WriteAllBytes(pathToFile, exrBytes); break; } default: throw new ArgumentOutOfRangeException(nameof(extension), extension, null); } Resources.UnloadUnusedAssets(); yield return(new WaitForSeconds(0.1f)); }
private void PlaySplashScreen() { Texture2D currentFrame = Resources.Load <Texture2D>("Textures/Splash/SplashFrame" + splashFrame); if (currentFrame != null) { int newWidth = currentFrame.width, newHeight = currentFrame.height; if (Screen.width < Screen.height) { newWidth = (int)(Screen.width * 0.25f); newHeight = (int)(currentFrame.height / (currentFrame.width / ((float)newWidth))); } else { newHeight = (int)(Screen.height * 0.25f); newWidth = (int)(currentFrame.width / (currentFrame.height / ((float)newHeight))); } TextureScale.Point(currentFrame, newWidth, newHeight); GUI.DrawTexture(new Rect(Screen.width / 2f - currentFrame.width / 2f, Screen.height / 2f - currentFrame.height / 2f, currentFrame.width, currentFrame.height), currentFrame); if (Time.time - lastFrameChange >= 1 / splashFPS) { splashFrame++; lastFrameChange = Time.time; } } else { Camera.main.backgroundColor = new Color((243f / 255f), (179f / 255f), (73f / 255f)); showSplash = false; } }
public Texture2D createColumn(Texture2D[] _tex) { int width = (int)size / _tex.Length; int height = (int)size / _tex.Length; // Create a new writable texture. Texture2D result = new Texture2D(width, size); for (int i = 0; i < _tex.Length; i++) { Texture2D t = _tex[i]; TextureScale.Bilinear(t, width, height); for (int x = 0; x < width; x++) { for (int y = height * i; y < height * (i + 1); y++) { Color c = t.GetPixel(x, y); result.SetPixel(x, y, c); } } } result.Apply(); return(result); }