public static Texture2D BytesToTexture(byte[] bytes, string resourceName) { Texture2D texture2D = new Texture2D(1, 1, TextureFormat.RGBA32, false); ImageConversion.LoadImage(texture2D, bytes); texture2D.filterMode = 0; texture2D.name = resourceName; return(texture2D); }
void SaveBitmap(NativeArray <Color32> buffer, int width, int height) { var tex = new Texture2D(width, height, TextureFormat.RGBA32, false); tex.SetPixels32(buffer.ToArray()); tex.Apply(); File.WriteAllBytes("test.png", ImageConversion.EncodeToPNG(tex)); Destroy(tex); }
public ClarifaiTagsCollection GetTagsInfo(Bitmap image) { var resizedImage = ResizeImageIfNeeded(image); var imagePngByteArray = ImageConversion.ImageToPngByteArray(resizedImage); var result = ExecutePostRequest <ClarifaiResponseDto>(MultiPartPath, imagePngByteArray, "tag"); var tagsResult = result.results == null ? null : result.results[0].result.tag; return(new ClarifaiTagsCollection(tagsResult)); }
public static Texture2D Texture2DConstruct(string Base64) { byte[] ReadBinary = Convert.FromBase64String(Base64); TextureStats(ReadBinary); Texture2D texture = new Texture2D(Width, Height); ImageConversion.LoadImage(texture, ReadBinary); return(texture); }
public void Render() { Lock(); if (!Directory.Exists(Utils.designFilesDirectory.ToAbsolute())) { Directory.CreateDirectory(Utils.designFilesDirectory.ToAbsolute()); } if (!Directory.Exists(designFilesDirectory.ToAbsolute())) { Directory.CreateDirectory(designFilesDirectory.ToAbsolute()); } var rectTransform = GetComponent <RectTransform>(); Vector2 size = rectTransform.sizeDelta * cubemapSize; var renderTexture = new RenderTexture( Mathf.RoundToInt(size.x), Mathf.RoundToInt(size.y), 24, GraphicsFormat.R32G32B32A32_SFloat, 0); var camera = GetComponentInChildren <Camera>(); camera.targetTexture = renderTexture; camera.allowHDR = true; //TierSettings.hdr = true; camera.Render(); camera.targetTexture = null; RenderTexture.active = renderTexture; Texture2D texture = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.RGBAFloat, false); texture.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0); RenderTexture.active = null; /*PhotoshopFile.PsdFile output = new PhotoshopFile.PsdFile(PhotoshopFile.PsdFileVersion.Psd); * output.RowCount = renderTexture.height; * output.ColumnCount = renderTexture.width; * output.ChannelCount = 4; * output.ColorMode = PhotoshopFile.PsdColorMode.RGB; * output.BitDepth = 32; * output.ImageCompression = PhotoshopFile.ImageCompression.Raw; * * * output.Resolution = new PhotoshopFile.ResolutionInfo(); * var layer = new PhotoshopFile.Layer(output); * layer.CreateMissingChannels(); * output.Layers.Add(layer); * * output.PrepareSave(); * output.Save(Path.Combine(resourceDirectory.ToAbsolute(), $"{name}.psd"),System.Text.Encoding.UTF8);*/ var bytes = ImageConversion.EncodeToEXR(texture, Texture2D.EXRFlags.OutputAsFloat); var outputPath = exrFilePath.ToAbsolute(); File.WriteAllBytes(outputPath, bytes); AssetDatabase.Refresh(); //Debug.Log(rectTransform.sizeDelta * cubemapSize); }
public bool CallMe(int iCallParamsBlock) { MainForm frm = new MainForm(); KdSdkApi kdApi = new KdSdkApiImpl(iCallParamsBlock); Scenes scenes = new Scenes(frm, kdApi); ICollection <FigureOnBoard> facades; try { //MessageBox.Show("Before geting facades"); facades = kdApi.getFacades(); //MessageBox.Show("After geting facades"); } catch (ArgumentNullException e) { MessageBox.Show("Объекты с атрибутом по свойству 1 не выбраны"); return(false); } catch (Exception e) { MessageBox.Show("Something wrong in getting facades \n " + e.Message); return(false); } foreach (FigureOnBoard item in facades) { if (item.figure.width == 0 || item.figure.height == 0) { MessageBox.Show("Element with id:" + item.figure + " have one or more zero parameters"); } else { if (((Facade)item.figure).getTextureId() != -1) { string path = kdApi.getImagePathFromTexture(((Facade)item.figure).getTextureId()); //MessageBox.Show(path); if (!path.Equals("")) { Bitmap image = ImageConversion.getImage(path); scenes.addFigure(new BkgImage(image), item.x, item.y); } } scenes.addFigure(item.figure, item.x, item.y); } } //scenes.addFigure(new Facade(21, 100, 100), 0, 0); if (facades.Count < 1) { MessageBox.Show("Объекты с атрибутом по свойству 1 не выбраны"); return(false); } frm.ShowDialog(); return(true); }
private static IEnumerator SaveMinimapImpl(int size) { bool wasLarge = Minimap.instance.m_largeRoot.activeSelf; if (!wasLarge) { Minimap.instance.SetMapMode(Minimap.MapMode.Large); Minimap.instance.CenterMap(Vector3.zero); } var mapPanelObject = CreateQuad(100, 100, 10, Minimap.instance.m_mapImageLarge.material); mapPanelObject.layer = 19; var renderTexture = new RenderTexture(size, size, 24); var cameraObject = new GameObject(); cameraObject.layer = 19; var camera = cameraObject.AddComponent <Camera>(); camera.targetTexture = renderTexture; camera.orthographic = true; camera.rect = new Rect(0, 0, renderTexture.width, renderTexture.height); camera.nearClipPlane = 0; camera.farClipPlane = 100; camera.orthographicSize = 50; camera.cullingMask = 1 << 19; camera.Render(); yield return(new WaitForEndOfFrame()); RenderTexture.active = renderTexture; var tex = new Texture2D(renderTexture.width, renderTexture.height, TextureFormat.RGB24, false); tex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0); tex.Apply(); RenderTexture.active = null; var filename = DateTime.Now.ToString("yyyy-dd-M-HH-mm-ss") + ".png"; var path = Path.Combine(GetScreenShotDir(), filename); Directory.CreateDirectory(Path.GetDirectoryName(path)); Console.instance.Print($"Screenshot of minimap saved to {path}"); File.WriteAllBytes(path, ImageConversion.EncodeToPNG(tex)); Object.Destroy(mapPanelObject); Object.Destroy(cameraObject); Object.Destroy(renderTexture); Object.Destroy(tex); if (!wasLarge) { Minimap.instance.SetMapMode(Minimap.MapMode.Small); } }
public void Shot() { Texture2D temp = new Texture2D(Cam.width, Cam.height); temp.SetPixels32(Cam.GetPixels32()); Debug.Log(temp.width); Debug.Log(temp.height); System.IO.File.WriteAllBytes("temp.jpg", ImageConversion.EncodeToJPG(temp)); Cam.Stop(); }
public static EncryptedImageContent EncryptImageContent(ImageContent unencryptedContent, string password) { EncryptedImageContent contentToReturn = new EncryptedImageContent(); contentToReturn.index = unencryptedContent.index; contentToReturn.encryptedImage = StringCipher.Encrypt(ImageConversion.ImageToBase64(unencryptedContent.image, ImageFormat.Png), password); contentToReturn.time = StringCipher.Encrypt(unencryptedContent.time, password); return(contentToReturn); }
public static ImageContent DecryptImageContent(EncryptedImageContent encryptedContent, string password) { ImageContent contentToReturn = new ImageContent(); contentToReturn.index = encryptedContent.index; contentToReturn.image = ImageConversion.Base64ToImage(StringCipher.Decrypt(encryptedContent.encryptedImage, password)); contentToReturn.time = StringCipher.Decrypt(encryptedContent.time, password); return(contentToReturn); }
private Sprite convertImageBase64ToSprite(string base64) { base64 = base64.Substring(base64.IndexOf(',') + 1); var base64EncodedBytes = Convert.FromBase64String(base64); Texture2D tex = new Texture2D(500, 530); ImageConversion.LoadImage(tex, base64EncodedBytes); return(Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), Vector2.zero)); }
internal Image(byte[] filedata, FilterMode filterMode = FilterMode.Bilinear) { MainTexture = new Texture2D(2, 2); MainTexture.filterMode = filterMode; if (!ImageConversion.LoadImage(MainTexture, filedata, false)) { throw new Exception("ImageConversion.LoadImage Failed!"); } SetSize(MainTexture.width, MainTexture.height); }
private void UpdateMessage() { message.header.Update(); //texture2D=duplicateTexture((Texture2D)mediaMaterial.mainTexture); //message.data = texture2D.EncodeToJPG(qualityLevel); message.data = ImageConversion.EncodeToJPG(rawImage.texture as Texture2D, qualityLevel); //Texto.text = "UPdate~"; Publish(message); }
private void SaveBitmap(NativeArray <Color32> buffer, int width, int height) { var tex = new Texture2D(width, height, TextureFormat.RGBA32, false); tex.SetPixels32(buffer.ToArray()); tex.Apply(); File.WriteAllBytes("Assets/Other/AsyncCapture/async.png", ImageConversion.EncodeToPNG(tex)); Destroy(tex); Debug.Log("Save Async"); }
public SerializeTexture Serialize(Texture2D texture) { SerializeTexture serial = new SerializeTexture(); serial.x = texture.width; serial.y = texture.height; serial.bytes = ImageConversion.EncodeToPNG(texture); return(serial); }
static void GenerateTexture(int i) { var tex = new Texture2D(4096, 4096); var bytes = ImageConversion.EncodeToPNG(tex); var appDir = System.IO.Path.GetFullPath("."); var path = string.Format("{0}/TestData/{0}.png", appDir, i); System.IO.File.WriteAllBytes(path, bytes); Debug.Log(i); }
public static Texture2D GetEmbeddedResourceAsTexture(string resourceName) { byte[] sprite = ExtractEmbeddedResource("SpriteWork.Resources." + resourceName); Texture2D texture = new Texture2D(1, 1, TextureFormat.RGBA32, false); ImageConversion.LoadImage(texture, sprite); texture.filterMode = FilterMode.Point; texture.name = resourceName; return(texture); }
static private Sprite CreateSprite(byte[] bytes) { // UnityException: SupportsTextureFormatNative can only be called from the main thread. // Constructors and field initializers will be executed from the loading thread when loading a scene. // Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function. Texture2D texture = new Texture2D(0, 0); ImageConversion.LoadImage(texture, bytes, false); return(Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero)); }
protected string CreateTexture(string texturePath, int size = 32) { var texture = new Texture2D(size, size); var data = ImageConversion.EncodeToPNG(texture); UnityEngine.Object.DestroyImmediate(texture); File.WriteAllBytes(texturePath, data); AssetDatabase.ImportAsset(texturePath, ImportAssetOptions.ForceSynchronousImport | ImportAssetOptions.ForceUpdate); return(AssetDatabase.AssetPathToGUID(texturePath)); }
void SaveBitmap(byte[] buffer, int width, int height) { Debug.Log("Write to file"); var tex = new Texture2D(width, height, TextureFormat.RGBAHalf, false); tex.LoadRawTextureData(buffer); tex.Apply(); File.WriteAllBytes("test.png", ImageConversion.EncodeToPNG(tex)); Destroy(tex); }
public SpriteAtlas SetUpSpriteAtlas(int numAtlasObjects, out List <Object> subAssets) { // Setup Sprite data var texture = new Texture2D(32, 32); var data = ImageConversion.EncodeToPNG(texture); UnityEngine.Object.DestroyImmediate(texture); // Setup Sprites subAssets = new List <Object>(); Directory.CreateDirectory(ConfigFolder + "/test"); var atlasPath = ConfigFolder + "/test" + "/testAtlas.spriteatlas"; var newAtlas = new SpriteAtlas(); var sprites = new Object[numAtlasObjects]; for (int i = 0; i < numAtlasObjects; i++) { // Create Sprite asset AssetDatabase.GenerateUniqueAssetPath(ConfigFolder); var newSpritePath = ConfigFolder + "/test" + "/testSprite" + i + ".png"; File.WriteAllBytes(newSpritePath, data); AssetDatabase.ImportAsset(newSpritePath, ImportAssetOptions.ForceSynchronousImport | ImportAssetOptions.ForceUpdate); var importer = (TextureImporter)AssetImporter.GetAtPath(newSpritePath); importer.textureType = TextureImporterType.Sprite; importer.spriteImportMode = SpriteImportMode.Multiple; importer.spritesheet = new SpriteMetaData[] { new SpriteMetaData() { name = "topleft", pivot = Vector2.zero, rect = new Rect(0, 0, 16, 16) }, new SpriteMetaData() { name = "testSprite" + i, pivot = Vector2.zero, rect = new Rect(16, 16, 16, 16) } }; importer.SaveAndReimport(); // Add sprite to subassets Object spr = AssetDatabase.LoadAssetAtPath(newSpritePath, typeof(Sprite)); spr.name = "testSprite" + i; sprites[i] = spr; subAssets.Add(spr); } // Setup Atlas newAtlas.Add(sprites); AssetDatabase.CreateAsset(newAtlas, atlasPath); AssetDatabase.Refresh(); SpriteAtlasExtensions.Add(newAtlas, sprites); SpriteAtlasUtility.PackAtlases(new SpriteAtlas[] { newAtlas }, EditorUserBuildSettings.activeBuildTarget, false); var atlasGuid = AssetDatabase.AssetPathToGUID(atlasPath); Settings.CreateOrMoveEntry(atlasGuid, Settings.groups[0]); return(newAtlas); }
static string CreateTexture(string name, int size = 32) { string assetPath = $"{TempPath}/{name}.png"; var texture = new Texture2D(size, size); var data = ImageConversion.EncodeToPNG(texture); UnityEngine.Object.DestroyImmediate(texture); File.WriteAllBytes(assetPath, data); AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceSynchronousImport | ImportAssetOptions.ForceUpdate); return(AssetDatabase.AssetPathToGUID(assetPath)); }
/// <summary> /// Load image /// </summary> /// <param name="filename">file name</param> /// <returns>`Texture`</returns> public static Texture LoadImage(string filename) { string fullpath = Path.Combine(Application.streamingAssetsPath, "TestSet", filename); var bytes = File.ReadAllBytes(fullpath); var tex = new Texture2D(2, 2); ImageConversion.LoadImage(tex, bytes, false); // LoadImage will auto-resize the texture dimensions tex.wrapMode = TextureWrapMode.Clamp; return(tex); }
private void OnChangeColor(DirectoryInfo material) { var texture = new Texture2D(1024, 1024); Debug.Log(material.FullName); var bytes = File.ReadAllBytes(material.FullName); var bytesTGA = ImageConversion.EncodeArrayToJPG(bytes, GraphicsFormat.R8G8B8_SInt, 1024, 1024); texture.LoadImage(bytesTGA); player.ChangeColor(texture); }
private static Texture2D LoadTexture(string filepath) { if (cachedTextures.ContainsKey(filepath)) { return(cachedTextures[filepath]); } Texture2D texture2D = new Texture2D(0, 0); ImageConversion.LoadImage(texture2D, File.ReadAllBytes(filepath)); return(texture2D); }
public void AddPlayerScoreElement() { Texture2D lastFace = ScreenshotManager.FaceScreenshots[ScreenshotManager.FaceScreenshots.Count - 1]; byte[] lastFaceJpg = ImageConversion.EncodeToJPG(lastFace, 60); PlayerScoreElement element = new PlayerScoreElement(PlayerScore.Value, lastFaceJpg); PlayerScoreElements.Add(element); SaveData(); }
public void SerializeTest() { Texture2D tex = m_InSprite.texture; exportObj.x = tex.width; exportObj.y = tex.height; exportObj.bytes = ImageConversion.EncodeToPNG(tex); string text = JsonConvert.SerializeObject(exportObj); File.WriteAllText(@"d:\test.json", text); }
//Creates the sprite for the artifact's icon private Sprite Icon(byte[] byteData) { if (byteData == null) { throw new ArgumentNullException("Null Argument in Icon object"); } Texture2D texture = new Texture2D(0x40, 0x40, (TextureFormat)4, false); ImageConversion.LoadImage(texture, byteData); return(Sprite.Create(texture, new Rect(0f, 0f, texture.width, texture.height), new Vector2(.5f, .5f))); }
private LoadedImagePixels ExternalLoadImageHook(byte[] arg) { //LoadImage will replace with with incoming image size. Texture2D tex = new Texture2D(2, 2, TextureFormat.RGB24, false); ImageConversion.LoadImage(tex, arg); tex = FlipTexture(tex); int[] pixels = tex.GetPixels32().Select(ColorUtils.ColorToRGB).ToArray(); return(new LoadedImagePixels(tex.height, tex.width, pixels)); }
public static Texture2D TextureFromPNG(string path) { Texture2D text = new Texture2D(2, 2); if (!ImageConversion.LoadImage(text, File.ReadAllBytes(path))) { throw new Exception("Could not acquire texture from file " + Path.GetFileName(path) + "."); } return(text); }