public static Texture2D LoadTextureFromFile(string fileName) { SRInfoHelper.Log("Loading " + fileName); string filePath = @"C:\Temp" + @"\" + fileName; //string filePath = Manager.GetPluginManager().PluginPath + @"\" + fileName; if (File.Exists(filePath)) { SRInfoHelper.Log("File " + fileName + " exists"); Vector2Int imgSize = ImageHeader.GetDimensions(filePath); SRInfoHelper.Log("Image size " + imgSize.x + " " + imgSize.y); var bytes = File.ReadAllBytes(filePath); SRInfoHelper.Log("Loading bytes into image"); Texture2D tmpTexture = new Texture2D(imgSize.x, imgSize.y); tmpTexture.LoadImage(bytes); SRInfoHelper.Log("Loaded bytes into image"); tmpTexture.name = fileName.Replace(".png", ""); return(tmpTexture); //Texture2D texture = new Texture2D(tmpTexture.width, tmpTexture.height); //SRInfoHelper.Log("Loading bytes into image"); //texture.LoadImage(bytes); //return texture; } else { return(null); } }
private void ProcessMediaFile(MediaFile file) { if (file.Size == 0) { file.Size = Convert.ToInt32(_mediaStorageProvider.GetSize(file)); } file.MediaType = _mediaTypeResolver.Resolve(file); if (file.MediaType == MediaType.Image && file.Width == null && file.Height == null) { // Resolve image width and height var stream = _mediaStorageProvider.OpenRead(file); if (stream != null) { try { var size = ImageHeader.GetDimensions(stream, file.MimeType, true); file.Width = size.Width; file.Height = size.Height; file.PixelSize = size.Width * size.Height; } finally { stream.Dispose(); } } } if (file.Width.HasValue && file.Height.HasValue) { file.PixelSize = file.Width.Value * file.Height.Value; // TODO: Metadata JSON } }
/// <summary> /// Gets the image size internal. /// </summary> /// <param name="path">The path.</param> /// <param name="allowSlowMethod">if set to <c>true</c> [allow slow method].</param> /// <returns>ImageSize.</returns> private ImageSize GetImageSizeInternal(string path, bool allowSlowMethod) { ImageSize size; try { size = ImageHeader.GetDimensions(path, _logger, _fileSystem); } catch { if (!allowSlowMethod) { throw; } //_logger.Info("Failed to read image header for {0}. Doing it the slow way.", path); CheckDisposed(); size = _imageEncoder.GetImageSize(path); } StartSaveImageSizeTimer(); return(size); }
public static void ShowWarningsForTooBigTextures(string absoluteFileName) { int width = ImageHeader.GetDimensions(absoluteFileName).Width; int height = ImageHeader.GetDimensions(absoluteFileName).Height; // In 2013 this is a reasonable // max width, especially for phones. // Maybe in the far future this will go // up. // Update December 29, 2016 // Get with the times, 4k is what it's all // about! int maxDimension = 4096; bool shown = false; if (width > maxDimension) { MessageBox.Show( $"The texture is wider than {maxDimension}. This could cause problems. It is recommended to keep your texture at or under {maxDimension} width."); shown = true; } if (!shown && height > maxDimension) { MessageBox.Show( $"The texture is taller than {maxDimension}. This could cause problems. It is recommended to keep your texture at or under {maxDimension} height."); } }
public void ReadSizeEmf() { using (var imageStream = ResourceHelper.GetStream("Resources.html2openxml.emf")) { Size size = ImageHeader.GetDimensions(imageStream); Assert.Equal(100, size.Width); Assert.Equal(100, size.Height); } }
public void ReadSizeAnimatedGif() { using (var imageStream = ResourceHelper.GetStream("Resources.stan.gif")) { Size size = ImageHeader.GetDimensions(imageStream); Assert.Equal(252, size.Width); Assert.Equal(318, size.Height); } }
public void ReadSize(string resourceName) { using (var imageStream = ResourceHelper.GetStream(resourceName)) { Size size = ImageHeader.GetDimensions(imageStream); Assert.That(size.Width, Is.EqualTo(100)); Assert.That(size.Height, Is.EqualTo(100)); } }
public void ReadSizeAnimatedGif() { using (var imageStream = ResourceHelper.GetStream("Resources.stan.gif")) { Size size = ImageHeader.GetDimensions(imageStream); Assert.That(size.Width, Is.EqualTo(252)); Assert.That(size.Height, Is.EqualTo(318)); } }
public void ReadSizePngSof2() { using (var imageStream = ResourceHelper.GetStream("Resources.lumileds.png")) { Size size = ImageHeader.GetDimensions(imageStream); Assert.That(size.Width, Is.EqualTo(500)); Assert.That(size.Height, Is.EqualTo(500)); } }
private void ImageResize(string path, string dest, int maxWidth, int maxHeight, bool notify = true) { if (dest.IsEmpty()) { return; } if (maxWidth == 0 && maxHeight == 0) { maxWidth = _mediaSettings.Value.MaximumImageSize; maxHeight = _mediaSettings.Value.MaximumImageSize; } var buffer = System.IO.File.ReadAllBytes(path); var query = new ProcessImageQuery(buffer) { Quality = _mediaSettings.Value.DefaultImageQuality, Format = Path.GetExtension(path).Trim('.').ToLower(), IsValidationMode = true, Notify = notify }; var originalSize = ImageHeader.GetDimensions(buffer, MimeTypes.MapNameToMimeType(path)); if (originalSize.IsEmpty || (originalSize.Height <= maxHeight && originalSize.Width <= maxWidth)) { // Give subscribers the chance to (pre)-process var evt = new ImageUploadValidatedEvent(query, originalSize); _eventPublisher.Publish(evt); if (evt.ResultBuffer != null) { System.IO.File.WriteAllBytes(dest, evt.ResultBuffer); } return; } if (maxWidth > 0) { query.MaxWidth = maxWidth; } if (maxHeight > 0) { query.MaxHeight = maxHeight; } using (var result = _imageProcessor.Value.ProcessImage(query)) { buffer = result.OutputStream.GetBuffer(); System.IO.File.WriteAllBytes(dest, buffer); } }
/// <summary> /// Gets the image size internal. /// </summary> /// <param name="path">The path.</param> /// <param name="allowSlowMethod">if set to <c>true</c> [allow slow method].</param> /// <returns>ImageSize.</returns> private ImageSize GetImageSizeInternal(string path, bool allowSlowMethod) { //try //{ // using (var fileStream = _fileSystem.OpenRead(path)) // { // using (var file = TagLib.File.Create(new StreamFileAbstraction(Path.GetFileName(path), fileStream, null))) // { // var image = file as TagLib.Image.File; // if (image != null) // { // var properties = image.Properties; // return new ImageSize // { // Height = properties.PhotoHeight, // Width = properties.PhotoWidth // }; // } // } // } //} //catch //{ //} try { return(ImageHeader.GetDimensions(path, _logger, _fileSystem)); } catch { if (allowSlowMethod) { return(_imageEncoder.GetImageSize(path)); } throw; } }
/// <summary> /// Gets the size of the image. /// </summary> private ImageSize GetImageSize(string path, bool allowSlowMethod) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } try { return(ImageHeader.GetDimensions(path, _logger, _fileSystem)); } catch { if (!allowSlowMethod) { throw; } } return(_imageEncoder.GetImageSize(path)); }
/// <summary> /// 获取图片尺寸 /// </summary> /// <param name="pictureStream"></param> /// <returns></returns> public static Size GetPictureSize(this Stream pictureStream) { if (pictureStream == null || pictureStream.Length == 0) { return(new Size()); } Size size; try { pictureStream.Seek(0, SeekOrigin.Begin); using (var reader = new BinaryReader(pictureStream, Encoding.UTF8, true)) { size = ImageHeader.GetDimensions(reader); } } catch (Exception) { // something went wrong with fast image access, // so get original size the classic way try { pictureStream.Seek(0, SeekOrigin.Begin); using (var b = new Bitmap(pictureStream)) { size = new Size(b.Width, b.Height); } } catch { size = new Size(); } } finally { } return(size); }
public void SetTexture(Texture imageTexture) { imageRenderer.gameObject.SetActive(true); print(imageTexture); if (imageRenderer.material.mainTexture != imageTexture) { imageRenderer.material.mainTexture = imageTexture; } //Because the texture does not have a z scale we save it float currentZScale = transform.localScale.z; //https://forum.unity3d.com/threads/getting-original-size-of-texture-asset-in-pixels.165295/ Vector2Int imgSize = ImageHeader.GetDimensions(AssetDatabase.GetAssetPath(imageTexture)); Vector3 renderSize = imageRenderer.transform.localScale; float aspectRatioRender = renderSize.x / renderSize.y; float aspectRatioTexture = imgSize.x / imgSize.y; //https://stackoverflow.com/questions/6565703/math-algorithm-fit-image-to-screen-retain-aspect-ratio Vector3 aspect1 = new Vector3(imgSize.x * renderSize.y / imgSize.y, renderSize.y, currentZScale); Vector3 aspect2 = new Vector3(renderSize.x, imgSize.y * renderSize.x / imgSize.x, currentZScale); transform.localScale = aspectRatioRender > aspectRatioTexture ? aspect1 : aspect2; //transform.localScale = correctedSize/ aspectRatio*.1f; }
public float GetEffectiveHeight(InstanceSave instance) { RecursiveVariableFinder rvf = new RecursiveVariableFinder(instance, instance.ParentContainer); float height = rvf.GetValue <float>("Height"); if (height == 0) { string sourceFile = rvf.GetValue <string>("SourceFile"); if (instance.BaseType == "Sprite") { if (!string.IsNullOrEmpty(sourceFile)) { string fullFileName = FileManager.GetDirectory(GumProjectSave.FullFileName) + sourceFile; height = ImageHeader.GetDimensions(fullFileName).Height; } } } return(height); }
/// <summary> /// Gets the image size internal. /// </summary> /// <param name="path">The path.</param> /// <param name="allowSlowMethod">if set to <c>true</c> [allow slow method].</param> /// <returns>ImageSize.</returns> private ImageSize GetImageSizeInternal(string path, bool allowSlowMethod) { try { using (var file = TagLib.File.Create(path)) { var image = file as TagLib.Image.File; var properties = image.Properties; return(new ImageSize { Height = properties.PhotoHeight, Width = properties.PhotoWidth }); } } catch { } return(ImageHeader.GetDimensions(path, _logger, _fileSystem)); }
void Update() { if (Input.GetMouseButtonDown(0) && !playdatshit) { if (!File.Exists(Application.dataPath + "/Resources/" + "sizeTest.png")) { ScreenCapture.CaptureScreenshot(Application.dataPath + "/Resources/" + "sizeTest.png"); Debug.Log("[INFO] Creating size template."); } else { Vector2Int imgSize = ImageHeader.GetDimensions(Application.dataPath + "/Resources/" + "sizeTest.png"); Debug.Log("Image width: " + imgSize.x + "\n\t" + "Image height: " + imgSize.y); screenshotWidth = imgSize.x; screenshotHeight = imgSize.y; playdatshit = true; encodedList.ims = new RLEncoding[myPath.getLength()]; string folderPath; folderPath = Application.persistentDataPath + "/images"; System.IO.DirectoryInfo di = new DirectoryInfo(folderPath); if (Directory.Exists(folderPath)) { foreach (FileInfo file in di.GetFiles()) { file.Delete(); } } Debug.Log("[INFO] Saving data to: " + folderPath); System.IO.Directory.CreateDirectory(folderPath); } } if (Input.GetMouseButtonDown(1)) { int randomCombination = rand.Next(combsCombined.Count); for (int j = 0; j < targetObjects.Length; ++j) { targetObjects[j].SetActive(Array.Exists(combsCombined[randomCombination], el => el == j)); if (Array.Exists(combsCombined[randomCombination], el => el == j)) { Debug.Log("Setting active " + j); } else { Debug.Log("Setting inactive " + j); } } } if (playdatshit) { if (myPath.next()) { if (randomObjectActivation) { int randomCombination = rand.Next(combsCombined.Count); for (int j = 0; j < targetObjects.Length; ++j) { targetObjects[j].SetActive(Array.Exists(combsCombined[randomCombination], el => el == j)); } int r = rand.Next(combsCombined[randomCombination].Length); // 1: 0; 2: 0,1; 3: 0,1,2 int cnt = 0; // 0-7 index of object to look at foreach (var obj in targetObjects) { if (obj.activeSelf) { if (cnt == r) { focusObject = obj.transform; } cnt++; } } transform.position = focusObject.position + myPath.nextPosition(); transform.LookAt(focusObject.position); } else { transform.position = focusObject.position + myPath.nextPosition(); transform.LookAt(focusObject.position); } string scrPath, folderName = "images/", imageName = myPath.currentID.ToString() + ".png"; int maskID = myPath.currentID; // Path to screenshot of the view from the normal camera scrPath = Path.Combine(Application.persistentDataPath, "images", imageName); ScreenCapture.CaptureScreenshot(scrPath); // save encoding for given (object,material,image) encodedList.ims[myPath.currentID] = createRLEncoding4Image(folderName, imageName, maskID); if (saveBinaryMask) { for (int i = 0; i < encodedList.ims[myPath.currentID].annotations.Count; i++) { Texture2D tex = RLE2alpha8(encodedList.ims[myPath.currentID].annotations[i].segmentation, true); byte[] bytes = tex.EncodeToPNG(); File.WriteAllBytes(Path.Combine(Application.persistentDataPath, "images/" + maskID.ToString() + "-" + i.ToString() + ".png"), bytes); } } } else { Debug.Log("[INFO] Finished taking photos."); playdatshit = false; string jsonString = JsonUtility.ToJson(encodedList, true); using (TextWriter tw = new StreamWriter(Path.Combine(Application.persistentDataPath, "mask_data.json"))) { tw.Write(jsonString); Debug.Log("[INFO] Saved json."); } } } }
private void BuildTilesetFromImage(XElement xTileset, AtlasBuilder atlas) { m_TilesetScript.m_IsImageCollection = false; XElement xImage = xTileset.Element("image"); string textureAssetPath = xImage.GetAttributeAs <string>("source"); int textureWidth = xImage.GetAttributeAs <int>("width"); int textureHeight = xImage.GetAttributeAs <int>("height"); // Load the texture. We will make sprites and tiles out of this image. var tex2d = m_Importer.RequestAssetAtPath <Texture2D>(textureAssetPath); if (tex2d == null) { // Texture was not found so report the error to the importer UI and bail m_Importer.ReportError("Missing texture asset: {0}", textureAssetPath); m_TilesetScript.m_HasErrors = true; return; } // This is annoying but a tileset may have recently changed but Tiled hasn't been updated on the status yet var texAssetPath = AssetDatabase.GetAssetPath(tex2d); var texFullPath = Path.GetFullPath(texAssetPath); var imgHeaderDims = ImageHeader.GetDimensions(texFullPath); if (imgHeaderDims.x != textureWidth || imgHeaderDims.y != textureHeight) { // Tileset needs to be resaved in Tiled m_Importer.ReportError("Mismatching width/height detected. Tileset = ({0}, {1}), image = {2}. This may happen when a tileset image has been resized. Open map and tileset in Tiled Map Editor and resave.", textureWidth, textureHeight, imgHeaderDims); m_TilesetScript.m_HasErrors = true; return; } if (tex2d.width < textureWidth || tex2d.height < textureHeight) { // Texture was not imported into Unity correctly var max = Mathf.Max(textureWidth, textureHeight); m_Importer.ReportError("Texture was imported at a smaller size. Make sure 'Max Size' on '{0}' is at least '{1}'", textureAssetPath, max); m_TilesetScript.m_HasErrors = true; return; } for (int i = 0; i < m_TilesetScript.m_TileCount; i++) { // Get grid x,y coords int x = i % m_TilesetScript.m_TileColumns; int y = i / m_TilesetScript.m_TileColumns; // Get x source on texture int srcx = x * m_TilesetScript.m_TileWidth; srcx += x * m_TilesetScript.m_Spacing; srcx += m_TilesetScript.m_Margin; // Get y source on texture int srcy = y * m_TilesetScript.m_TileHeight; srcy += y * m_TilesetScript.m_Spacing; srcy += m_TilesetScript.m_Margin; // In Tiled, texture origin is the top-left. However, in Unity the origin is bottom-left. srcy = (textureHeight - srcy) - m_TilesetScript.m_TileHeight; if (srcy < 0) { // This is an edge condition in Tiled if a tileset's texture may have been resized break; } // Add the tile to our atlas Rect rcSource = new Rect(srcx, srcy, m_TilesetScript.m_TileWidth, m_TilesetScript.m_TileHeight); atlas.AddTile(i, tex2d, rcSource); } }
}//end CreateDirectory private void CreateXml(JArray qs, Topic topic) { if (!File.Exists(string.Format(@"Assets/Resources/Minigames/Millionaire/NEW{0}/{0}Questions.xml", topic.Title))) { XmlDocument doc = new XmlDocument(); //Creates the XML header: <?xml version="1.0" encoding="UTF-8"?> XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null); doc.AppendChild(docNode); //Creates the questions Node: <questions type="array"> XmlNode questionNode = doc.CreateElement("questions"); XmlAttribute questionAttribute = doc.CreateAttribute("type"); questionAttribute.Value = "array"; questionNode.Attributes.Append(questionAttribute); doc.AppendChild(questionNode); //Creates the title Node: <title>TOPIC</title> XmlNode titleNode = doc.CreateElement("title"); titleNode.AppendChild(doc.CreateTextNode(topic.Title)); questionNode.AppendChild(titleNode); //Creates the description Node: <description>EMPTY RIGHT NOW</description> XmlNode descritionNode = doc.CreateElement("description"); descritionNode.AppendChild(doc.CreateTextNode(topic.Description)); questionNode.AppendChild(descritionNode); //Creates the category Node: <category>UNUSED</category> XmlNode categoryNode = doc.CreateElement("category"); categoryNode.AppendChild(doc.CreateTextNode("Has been unused since I started")); questionNode.AppendChild(categoryNode); //Creates the path Node: <path>PATH WHERE IMAGES ARE STORED</path> XmlNode imgPathNode = doc.CreateElement("path"); imgPathNode.AppendChild(doc.CreateTextNode(string.Format(@"NEW{0}/Images/", topic.Title))); questionNode.AppendChild(imgPathNode); //Creates the previewImage Node: <previewImage>EMPTY RIGHT NOW</previewImage> XmlNode previewImageNode = doc.CreateElement("previewImage"); previewImageNode.AppendChild(doc.CreateTextNode("")); questionNode.AppendChild(imgPathNode); //Creates The tags Node: <tags type="array" /> XmlNode tagsNode = doc.CreateElement("tags"); XmlAttribute tagsAttribute = doc.CreateAttribute("type"); tagsAttribute.Value = "array"; tagsNode.Attributes.Append(tagsAttribute); questionNode.AppendChild(tagsNode); int questionNumber = 0; for (int currentLevel = 1; currentLevel <= 15; currentLevel++) { int numOfQuestions = 0; for (int i = 0; i < qs.Count; i++) { if (qs[i]["Level"].ToString().Equals(currentLevel.ToString())) { numOfQuestions++; } } if (numOfQuestions > 0) // While there are questions do the following //Creates the level node: <level type="array" name="LEVELNUMBER"> { XmlNode levelNode = doc.CreateElement("level"); XmlAttribute levelAttribute = doc.CreateAttribute("type"); levelAttribute.Value = "array"; levelNode.Attributes.Append(levelAttribute); levelAttribute = doc.CreateAttribute("name"); levelAttribute.Value = currentLevel.ToString(); levelNode.Attributes.Append(levelAttribute); questionNode.AppendChild(levelNode); for (int currentQuestion = 0; currentQuestion < numOfQuestions; currentQuestion++) { //Creates the question node: <question name="QUESTIONNUMBER"> XmlNode gameQuestionNode = doc.CreateElement("question"); XmlAttribute gameQuestionAttributes = doc.CreateAttribute("name"); gameQuestionAttributes.Value = (currentQuestion + 1).ToString(); gameQuestionNode.Attributes.Append(gameQuestionAttributes); levelNode.AppendChild(gameQuestionNode); //Creates the content node the contains each question: <content>QUESTION HERE</content> XmlNode actualQuestionNode = doc.CreateElement("content"); actualQuestionNode.AppendChild(doc.CreateTextNode(qs[questionNumber]["Content"].ToString())); gameQuestionNode.AppendChild(actualQuestionNode); //Creates the image node: <image>IMAGEFILENAME</image> XmlNode imageNode = doc.CreateElement("image"); imageNode.AppendChild(doc.CreateTextNode("question" + questionNumber.ToString())); gameQuestionNode.AppendChild(imageNode); string filename = string.Format(@"Assets/Resources/Minigames/Millionaire/NEW{0}/Images/question{1}.png", topic.Title, questionNumber.ToString()); FileInfo f = new FileInfo(filename); if (f.Exists) { ImageHeader.Vector2Int imgSize = ImageHeader.GetDimensions(filename); UnityEngine.Debug.Log("Topic: " + topic.Title + "\nQuestionNumber: " + questionNumber + "\nimgSize.x =" + imgSize.x + "\nimgSize.y =" + imgSize.y); XmlNode imgWidth = doc.CreateElement("imgWidth"); XmlNode imgHeight = doc.CreateElement("imgHeight"); if (imgSize.x == 0 || imgSize.y == 0) { imgWidth.AppendChild(doc.CreateTextNode("0")); gameQuestionNode.AppendChild(imgWidth); imgHeight.AppendChild(doc.CreateTextNode("0")); gameQuestionNode.AppendChild(imgHeight); } else { imgWidth.AppendChild(doc.CreateTextNode(XmlConvert.ToString(imgSize.x))); gameQuestionNode.AppendChild(imgWidth); imgHeight.AppendChild(doc.CreateTextNode(XmlConvert.ToString(imgSize.y))); gameQuestionNode.AppendChild(imgHeight); } } else { XmlNode imgWidth = doc.CreateElement("imgWidth"); XmlNode imgHeight = doc.CreateElement("imgHeight"); imgWidth.AppendChild(doc.CreateTextNode("0")); gameQuestionNode.AppendChild(imgWidth); imgHeight.AppendChild(doc.CreateTextNode("0")); gameQuestionNode.AppendChild(imgHeight); } //Creates the answers node: <answers type="array"> XmlNode answersNode = doc.CreateElement("answers"); XmlAttribute answersAttrubutes = doc.CreateAttribute("type"); answersAttrubutes.Value = "array"; answersNode.Attributes.Append(answersAttrubutes); gameQuestionNode.AppendChild(answersNode); string[] answers = qs[questionNumber]["Answers"].ToObject <string[]>(); for (int i = 0; i < 4; i++) { XmlNode answerNode = doc.CreateElement("answer"); answersNode.AppendChild(answerNode); //Creates the correct node which says whether the current answer is the correct answer or not: <correct>TRUE or FALSE</correct> XmlNode correctNode = doc.CreateElement("correct"); correctNode.AppendChild(doc.CreateTextNode((int)qs[questionNumber]["CorrectAnswerIndex"] == i ? "true" : "false")); answerNode.AppendChild(correctNode); //Creates the answer node which contains the answer: <answer>ANSWERDATA</answer> XmlNode answerContentNode = doc.CreateElement("content"); answerContentNode.AppendChild(doc.CreateTextNode(answers[i])); answerNode.AppendChild(answerContentNode); } questionNumber++; } //end for } //end if } //end for //Saves the data after it has all been retrieved doc.Save(string.Format(@"Assets/Resources/Minigames/Millionaire/NEW{0}/{0}Questions.xml", topic.Title)); doc = null; //Garbage Collect to help improve memory: Resources.UnloadUnusedAssets(); GC.WaitForPendingFinalizers(); GC.Collect(); } } //end CreateXML
private void ReactToTextureAddressMode(NamedObjectSave namedObjectSave, object oldValue) { bool isSprite = namedObjectSave.SourceType == SourceType.FlatRedBallType && namedObjectSave.SourceClassType == "Sprite"; if (isSprite) { var addressModeVariable = namedObjectSave.GetCustomVariable("TextureAddressMode"); if (addressModeVariable != null && addressModeVariable.Value != null && ((TextureAddressMode)(addressModeVariable.Value) == TextureAddressMode.Wrap || (TextureAddressMode)(addressModeVariable.Value) == TextureAddressMode.Mirror)) { // How big is the texture? var textureVariable = namedObjectSave.GetCustomVariable("Texture"); if (textureVariable != null && textureVariable.Value != null) { string value = textureVariable.Value as string; var rfs = namedObjectSave.GetContainer().GetReferencedFileSaveByInstanceName(value); if (rfs != null) { var width = ImageHeader.GetDimensions( ProjectManager.MakeAbsolute(rfs.Name)).Width; var height = ImageHeader.GetDimensions( ProjectManager.MakeAbsolute(rfs.Name)).Height; string whatIsWrong = null; if (FlatRedBall.Math.MathFunctions.IsPowerOfTwo(width) == false) { whatIsWrong = "This Sprite's texture (" + textureVariable.Value + ") has a width of " + width + " but it should be a power of two to use " + addressModeVariable.Value + " TextureAddressMode"; } if (FlatRedBall.Math.MathFunctions.IsPowerOfTwo(height) == false) { whatIsWrong = "This Sprite's texture (" + textureVariable.Value + ") has a height of " + height + " but it should be a power of two to use " + addressModeVariable.Value + " TextureAddressMode"; } if (!string.IsNullOrEmpty(whatIsWrong)) { whatIsWrong += "\nWhat would you like to do?"; MultiButtonMessageBox mbmb = new MultiButtonMessageBox(); mbmb.MessageText = whatIsWrong; mbmb.AddButton("Undo the change", DialogResult.Cancel); mbmb.AddButton("Keep the change (May cause runtime crashes)", DialogResult.Yes); var result = mbmb.ShowDialog(); if (result == DialogResult.Cancel) { addressModeVariable.Value = oldValue; } } } } } } }
object GetImageHeight() { return(ImageHeader.GetDimensions( ProjectManager.MakeAbsolute(((ReferencedFileSave)Instance).Name)).Height); }