public void InitNoiseWeights(int sizeX, int sizeY, int sizeZ) { gm = GetComponent <GridManager>(); Texture2D noise2 = noise; TextureScale.Bilinear(noise2, gm.gridX, gm.gridZ); pixelValues = new Color[noise2.width, noise2.height]; for (int i = 0; i < noise2.width; i++) { for (int j = 0; j < noise2.height; j++) { pixelValues[i, j] = noise2.GetPixel(i, j); } } //Debug.Log(pixelValues.Length); for (int i = 0; i < sizeX; i++) { for (int k = 0; k < sizeY; k++) { for (int j = 0; j < sizeZ; j++) { grid[i, k, j].noiseWeight = pixelValues[i, j].grayscale; } } } }
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); }
// 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(); } }
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); }
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); }
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 static void CreatePngScreen(ref byte[] pngData, int createW, int createH) { Vector2 screenSize = ScreenInfo.GetScreenSize(); int x = (int)screenSize.x; int y = (int)screenSize.y; Texture2D tex = new Texture2D(x, y, (TextureFormat)3, false); RenderTexture renderTexture = QualitySettings.get_antiAliasing() != 0 ? RenderTexture.GetTemporary(x, y, 24, (RenderTextureFormat)7, (RenderTextureReadWrite)0, QualitySettings.get_antiAliasing()) : RenderTexture.GetTemporary(x, y, 24); if (Object.op_Inequality((Object)null, (Object)Camera.get_main())) { Camera main = Camera.get_main(); RenderTexture targetTexture = main.get_targetTexture(); Rect rect = main.get_rect(); main.set_targetTexture(renderTexture); main.Render(); main.set_targetTexture(targetTexture); main.set_rect(rect); } RenderTexture.set_active(renderTexture); tex.ReadPixels(new Rect(0.0f, 0.0f, (float)x, (float)y), 0, 0); tex.Apply(); RenderTexture.set_active((RenderTexture)null); RenderTexture.ReleaseTemporary(renderTexture); TextureScale.Bilinear(tex, createW, createH); pngData = ImageConversion.EncodeToPNG(tex); Object.Destroy((Object)tex); }
private ulong CalcTexHash(Texture2D tex) { // resize TextureScale.Bilinear(tex, 8, 8); // get grayscale Color[] clrs = tex.GetPixels(); float[] grays = new float[clrs.Length]; for (int i = 0; i < clrs.Length; i++) { grays[i] = clrs[i].grayscale; } // find average float average = 0; for (int i = 0; i < grays.Length; i++) { average += grays[i]; } average /= grays.Length; // calc hash (with binarisation) ulong hash = 0; for (int i = 0; i < grays.Length; i++) { hash = (hash << 1) | (grays[i] >= average ? 1ul : 0ul); } return(hash); }
void UploadPNG() { var tex = new Texture2D(texture.width, texture.height, TextureFormat.RGB24, false); tex.SetPixels(texture.GetPixels()); try { TextureScale.Bilinear(tex, 1280, 1280 * texture.height / texture.width); } catch (DivideByZeroException e) { Debug.LogException(e); } tex.Apply(); var bytes = tex.EncodeToPNG(); Destroy(tex); try { File.WriteAllBytes(Application.dataPath + "/../HeatMap" + jpgCounter + ".png", bytes); } catch (ArgumentNullException e) { Debug.LogException(e); } jpgCounter++; }
// Use this for initialization void Awake() { Texture2D tex = new Texture2D(map.width, map.height); tex.SetPixels(map.GetPixels()); TextureScale.Bilinear(tex, 241, 241); getempixels = tex.GetPixels(); //Debug.Log(getempixels); ganmap = new float[241, 241]; for (int y = 0; y < 241; y++) { for (int x = 0; x < 241; x++) { //Debug.Log(getempixels[x + y * x].r); ganmap[y, x] = getempixels[y * 241 + x].r; } } quadd.GetComponent <Renderer>().material.mainTexture = tex; Debug.Log("DONE BIACH"); mapgen.GenerateMap(); }
public void SetData(MapData pData) { m_pCamera.xMargin = pData.camera_margin_x; m_pCamera.yMargin = pData.camera_margin_y; m_pCamera.xSmooth = pData.camera_smooth_x; m_pCamera.ySmooth = pData.camera_smooth_y; m_pCamera.minXAndY = new Vector2(pData.camera_min_x, pData.camera_min_y); m_pCamera.maxXAndY = new Vector2(pData.camera_max_x, pData.camera_max_y); m_pCamera.BgWidth = pData.m_listBG[0].Width; m_pCamera.TerrainWidth = pData.m_listTerrain[0].Width; ResourceManager mgr = GameGOW.Get().ResourceMgr; for (int i = 0; i < pData.m_listBG.Count; ++i) { MapCellData cellData = pData.m_listBG[i]; GameObject obj = mgr.GetRes("Prefab/MapCell"); SpriteRenderer spr = obj.GetComponent <SpriteRenderer>(); Texture2D texture = mgr.GetRes <Texture2D>(cellData.resource); //因为背景图很大,需要压缩,而压缩后长宽会改变,所以需要Bilinear将长宽设置回原图的值,又因为压缩格式的图片不能重新设置尺寸,所以需要重新创建一张图 //创建一张图片 var newTexture = new Texture2D(texture.width, texture.height); //设置像素 newTexture.SetPixels(texture.GetPixels()); //应用更改 newTexture.Apply(); //设置图片尺寸 TextureScale.Bilinear(newTexture, cellData.Width, cellData.Height); //创建Sprite Rect rect = new Rect(0, 0, newTexture.width, newTexture.height); Sprite sp = Sprite.Create(newTexture, rect, new Vector2(0, 0)); spr.sprite = sp; obj.transform.parent = m_pBackGroundLayer; obj.transform.localPosition = new Vector3(cellData.pos_x, cellData.pos_y, m_pBackGroundLayer.position.z - i * 0.01f); } }
public IEnumerator CaptureByRectEx(Rect mRect, Action <Texture2D> callback = null, string mFileName = null, Vector2?size = null) { //等待渲染线程结束 yield return(new WaitForEndOfFrame()); //初始化Texture2D, 大小可以根据需求更改 Texture2D mTexture = new Texture2D((int)mRect.width, (int)mRect.height, TextureFormat.RGB24, false); //读取屏幕像素信息并存储为纹理数据 mTexture.ReadPixels(mRect, 0, 0); //应用 mTexture.Apply(); //TextureScale.Bilinear(); if (mFileName != null) { if (size != null) { TextureScale.Bilinear(mTexture, (int)size.Value.x, (int)size.Value.y); } //将图片信息编码为字节信息 byte[] bytes = mTexture.EncodeToPNG(); //保存 System.IO.File.WriteAllBytes(mFileName, bytes); } if (callback != null) { callback(mTexture); } }
Texture2D CaptureScreenshot(Rect rect) { // 先创建一个的空纹理,大小可根据实现需要来设置 Texture2D screenShot = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.RGB24, false); // 读取屏幕像素信息并存储为纹理数据, screenShot.ReadPixels(rect, 0, 0); screenShot.Apply(); //把Logo处理成350X200大小 TextureScale.Bilinear(Logo, 350, 200); //在截图上加上水印 Texture2D results = AddWatermark(screenShot, Logo, 50, 50); // 然后将这些纹理数据,生成一个png图片文件 byte[] bytes = results.EncodeToPNG(); //如果是Editor环境 if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer) { //定义截图保存路径 filename = Application.dataPath + "/screencapture" + System.Guid.NewGuid().ToString("N") + ".png"; } else if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer) { //定义截图保存路径,Android和ios要使用Application.persistentDataPath filename = Application.persistentDataPath + "/screencapture" + System.Guid.NewGuid().ToString("N") + ".png"; } System.IO.File.WriteAllBytes(filename, bytes); return(results); }
/// <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 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); }
// 選択した画像データを表示 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(); }
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(); } }
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)); }
//-------------------------------------------------------------------------- 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); */ }
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)); }
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(); }
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(); }
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); }
// 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); }
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 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 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); } }
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 static Texture2D GetTextureWithAlpha(Texture2D colorSourceTexture, Texture2D alphaSourceTexture) { Texture2D tempAlpha = alphaSourceTexture; if (!(colorSourceTexture.height == alphaSourceTexture.height && colorSourceTexture.width == alphaSourceTexture.width)) { //clone and scale the alpha source texture if needed tempAlpha = GetReadableTextureFromUnreadable(alphaSourceTexture); TextureScale.Bilinear(tempAlpha, colorSourceTexture.width, colorSourceTexture.height); } var result = new Texture2D(colorSourceTexture.width, colorSourceTexture.height); var originPixels = colorSourceTexture.GetPixels(); var alphaPixels = tempAlpha.GetPixels(); for (int i = 0; i < originPixels.Length; ++i) { var col = originPixels[i]; col.a = alphaPixels[i].a; originPixels[i] = col; } result.SetPixels(originPixels); result.Apply(); //destroy the temp texture if it is created if (tempAlpha != alphaSourceTexture) { GameObject.DestroyImmediate(tempAlpha); } return(result); }