private void dockPanel1_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(typeof(ToolBoxItem))) { MapViewer viewer = this.CreateNewMapViewer(); viewer.DropToolBoxItem(e.Data.GetData(typeof(ToolBoxItem)) as ToolBoxItem, new Point(e.X, e.Y)); } else if (e.Data.GetDataPresent("FileNameW")) { MapViewer viewer = this.CreateNewMapViewer(); string[] paths = (string[])e.Data.GetData("FileNameW"); foreach (string path in paths) { Bitmap img = null; if (path.ToLower().EndsWith("tga")) { img = TargaImage.LoadTargaImage(path); } else { img = new Bitmap(path); } img.ReplaceColor(Editor.TransparentColor, Color.Transparent); Sprite sprite = new Sprite { Img = img, Path = null }; viewer.AddTile(sprite, this.PointToClient(new Point(e.X, e.Y))); } } }
private BitmapSource LoadTGA(byte[] bytes) { System.Drawing.Bitmap bmp = TargaImage.LoadTargaImage(bytes); BitmapSource bs = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(bmp.GetHbitmap(), IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(bmp.Width, bmp.Height)); bs.Freeze(); return(bs); }
private Bitmap LoadImage(string filename) { switch (Path.GetExtension(filename)) { case ".tga": return(TargaImage.LoadTargaImage(filename)); default: return(new Bitmap(filename)); } }
public DoDLevel(string name, string habRelativePath, string levelBaseFullPath, string levelFullPath) { this.name = name; this.habRelativePath = habRelativePath; string briefingImageFullPath = Path.Combine(levelFullPath, "briefing.tga"); if (File.Exists(briefingImageFullPath)) { brefingImage = TargaImage.LoadTargaImage(Path.Combine(levelFullPath, "briefing.tga")); } else { brefingImage = TargaImage.LoadTargaImage(Path.Combine(levelBaseFullPath, "default_briefing.tga")); } }
private void btnNeutralityFlag_Click(object sender, EventArgs e) { OpenFileDialog fd = new OpenFileDialog(); fd.Filter = "Targa File (*.tga)|*.tga"; fd.ShowDialog(this); if (fd.FileName == "") { btnNeutralityFlag.BackColor = Color.LightPink; NewCountryFlagPicture.Image = null; } else { Bitmap newFlag = TargaImage.LoadTargaImage(fd.FileName); NewCountryFlagPicture.Image = newFlag; btnNeutralityFlag.BackColor = Color.LightGreen; } CreateNewCountryButton.Enabled = NewCountryFieldsCheck(); }
public static Bitmap LoadBitmapFromFile(string path, SegaSaturnColor transparentColor = null) { if (Path.GetExtension(path).ToLowerInvariant() == ".bin") { using (Stream stream = File.Open(path, FileMode.Open)) { using (BinaryReader streamReader = new BinaryReader(stream)) { Bitmap bin = new Bitmap(streamReader.ReadUInt16(), streamReader.ReadUInt16(), PixelFormat.Format32bppArgb); using (BmpPixelSnoop tmp = new BmpPixelSnoop(bin)) { for (int y = 0; y < tmp.Height; ++y) { for (int x = 0; x < tmp.Width; ++x) { tmp.SetPixel(x, y, new SegaSaturnColor(streamReader.ReadUInt16())); } } } return(bin); } } } if (Path.GetExtension(path).ToLowerInvariant() == ".tga") { Bitmap tga = TargaImage.LoadTargaImage(path); if (transparentColor != null) { tga.ReplaceColor(transparentColor, Color.Transparent); } return(tga); } Bitmap bitmap = (Bitmap)Bitmap.FromFile(path); if (transparentColor != null) { bitmap.ReplaceColor(transparentColor, Color.Transparent); } return(bitmap); }
public static Bitmap GetBitmap(string path) { try { Bitmap img = null; if (path.ToLower().EndsWith("tga")) { img = TargaImage.LoadTargaImage(path); } else { img = new Bitmap(path); } img.ReplaceColor(Editor.TransparentColor, Color.Transparent); return(img); } catch (Exception ex) { Program.Logger.Error(String.Format("Fail to load texture : {0}", path), ex); throw new InvalidOperationException(String.Format("Fail to load texture : {0}", path), ex); } }
private async Task ExtractAll() { await Task.Run(delegate { foreach (var chunk in Parser.Chunks) { string path = System.IO.Path.Combine(Destination, chunk.Name); if (File.Exists(path)) { continue; } Dispatcher.Invoke(delegate { LoadingBody.Text = path; LoadingProgress.Maximum = Parser.Chunks.Count; LoadingProgress.Value++; }); Parser.ExtractFile(Destination, chunk); if (tgaConvert == true) { if (System.IO.Path.GetExtension(chunk.Name) == ".tga") { using (var targa = TargaImage.LoadTargaImage(path)) { using (var fileStream = File.OpenWrite( System.IO.Path.Combine(Destination, chunk.Name.Remove(chunk.Name.Length - 4, 4) + ".png"))) { targa.Save(fileStream, ImageFormat.Png); } } File.Delete(path); } } } }); }
void ExtractTarGA(string path, StinkyFile.ManifestChunk chunk, StinkyFile.Primitive.RefPrim <bool> success) { try { using (var targa = TargaImage.LoadTargaImage(path)) { using (var fileStream = File.OpenWrite( System.IO.Path.Combine(Installation.DestinationDirectory, chunk.Name.Remove(chunk.Name.Length - 4, 4) + ".png"))) { targa.Save(fileStream, ImageFormat.Png); } } var destpath = Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path) + ".png"); Installation.FileChanged(destpath, FileChange.ADD); File.Delete(path); } catch (Exception e) { success.Value = false; return; } success.Value = true; }
/// <summary> /// マテリアルをUnity用に変換する /// </summary> /// <returns>Unity用マテリアル</returns> /// <param name='material_index'>PMX用マテリアルインデックス</param> /// <param name='is_transparent'>透過か</param> private Material ConvertMaterial(uint material_index, bool is_transparent) { var material = format_.material_list.material[material_index]; //先にテクスチャ情報を検索 Texture2D main_texture = null; if (material.usually_texture_index == uint.MaxValue) { main_texture = Texture2D.whiteTexture; } else { var texture_file_name = format_.texture_list.texture_file[material.usually_texture_index]; var path = format_.meta_header.folder + "/" + texture_file_name; if (File.Exists(path)) { if (material.usually_texture_index < format_.texture_list.texture_file.Length) { if (Path.GetExtension(texture_file_name).ToUpper() == ".DDS") { main_texture = Texture2D.whiteTexture; main_texture = DDSImage.LoadDDS(path); main_texture.wrapModeV = TextureWrapMode.MirrorOnce; } else if (Path.GetExtension(texture_file_name).ToUpper() == ".BMP") { main_texture = BMPLoader.LoadBMP(path).ToTexture2D(); } else if (Path.GetExtension(texture_file_name).ToUpper() == ".TGA") { try { var bitmap = TargaImage.LoadTargaImage(path); main_texture = new Texture2D(bitmap.Width, bitmap.Height); var stream = new MemoryStream(); bitmap.Save(stream, ImageFormat.Png); main_texture.LoadImage(stream.ToArray()); stream.Close(); main_texture.Apply(); } catch (Exception e) { Debug.Log("TGA Exception"); Debug.Log(texture_file_name); Debug.LogError(e.Message); main_texture = Texture2D.whiteTexture; } //main_texture = CreateTexture(path); } else { main_texture = new Texture2D(1, 1, TextureFormat.RGBA32, false); main_texture.LoadImage(File.ReadAllBytes(path)); // Fill the texture field } //main_texture.alphaIsTransparency = true; } } else { main_texture = Texture2D.whiteTexture; } } var result = new Material(Resources.Load <Material>("Transparent")) { renderQueue = (int)(3000 + material_index) }; result.SetTexture("_BaseColorMap", main_texture); result.SetVector("_BaseColor", material.diffuse_color); result.SetFloat("_TransparentSortPriority", material_index); result.name = format_.material_list.material[material_index].name; try { foreach (var m in GameObject.Find("Preview Builder Main").GetComponent <PreviewBuilder.PreviewBuilder>() .MaterialExtraConfigurationList.Materials) { foreach (var item in m.MaterialName) { if (result.name.ToUpper().Contains(item.ToUpper())) { result.SetFloat("_AlphaCutoffPrepass", float.Parse(m.Throttle)); Debug.Log($"{result.name} {m.Throttle}"); goto Found; } else { var defaultValue = (from t in GameObject.Find("Preview Builder Main") .GetComponent <PreviewBuilder.PreviewBuilder>().MaterialExtraConfigurationList.Materials where t.Name == "Default" select t).FirstOrDefault(); result.SetFloat("_AlphaCutoffPrepass", float.Parse(defaultValue.Throttle)); } } } } catch (Exception e) { Debug.LogError(e.Message); } Found: return(result); }
private static Texture LoadTga(string path) { return(TargaImage.LoadTargaImage(path)); }
public string GetImage(string destPath, string nickName) { try { char[] buffer = new char[4]; this.reader.Read(buffer, 0, 4); string ash = new string(buffer); int ver = this.reader.ReadInt32(); if (!ash.Equals("UTF ") && ver == 257) { throw new Exception("Wrong file format"); } int nodeOffset = this.reader.ReadInt32(); int nodeSize = this.reader.ReadInt32(); this.reader.BaseStream.Position = this.reader.BaseStream.Position + 8; int stringOffset = this.reader.ReadInt32(); int stringSize = this.reader.ReadInt32(); this.reader.BaseStream.Position = this.reader.BaseStream.Position + 4; this.reader.BaseStream.Position = 36; int dataOffset = this.reader.ReadInt32(); int dateSize = (int)(this.reader.BaseStream.Length - this.reader.BaseStream.Position); #region get nodes this.reader.BaseStream.Position = nodeOffset; List <PrimitiveNode> nodes = new List <PrimitiveNode>(); while (this.reader.BaseStream.Position < nodeOffset + nodeSize) { nodes.Add(this.GetNode(this.reader)); } #endregion #region get strings foreach (PrimitiveNode node in nodes) { node.Nodestring = this.Getstring(this.reader, node, stringOffset); // node.PrintNode(); } #endregion PrimitiveNode mipNode = (from node in nodes where node.Nodestring.Equals("MIP0") select node).FirstOrDefault(); if (mipNode == null) { throw new Exception("Couldn't locate mip node"); } this.reader.BaseStream.Position = dataOffset + mipNode.ChildOffset; byte[] fileBytes = new byte[mipNode.Size]; this.reader.Read(fileBytes, 0, fileBytes.Length); string fileName = this.getFileName(nodes, nodeOffset); if (fileName == "") { fileName = nickName; } fileName += ".jpg"; Bitmap image = TargaImage.LoadTargaImage(fileBytes); image.Save(destPath + fileName); return(fileName); #region test /* * string path = @"C:\Users\Yaoquizque\Desktop\FreelancerTrading\FilesFeed\commoditiesModels\TGA\"; * using (BinaryWriter bw = new BinaryWriter(File.Open(path + this.getFileName(nodes, nodeOffset), FileMode.Create))) * { * bw.Write(fileBytes); * }*/ #endregion } finally { this.Dispose(); } }
public bool OpenFile(string path) { if (!File.Exists(path)) { MessageBox.Show(String.Format("File: {0} not found.", path), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } Cursor.Current = Cursors.WaitCursor; try { this.MapPath = path; using (StreamReader fs = new StreamReader(path)) { this.panelGrid.Controls.Clear(); while (!fs.EndOfStream) { string line = fs.ReadLine(); if (string.IsNullOrWhiteSpace(line)) { continue; } string[] tab = line.Split(new[] { '\t', ' ' }, StringSplitOptions.RemoveEmptyEntries); Sprite sprite = new Sprite(); if (!Sprite.Filename2path.ContainsKey(tab[0])) { this.panelGrid.Controls.Clear(); this.UpdateStatusbar(); MessageBox.Show(String.Format("Sprite {0} is not found in available sprites", tab[0]), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } sprite.Path = Sprite.Filename2path[tab[0]]; if (sprite.Path.ToLower().EndsWith("tga")) { sprite.Img = TargaImage.LoadTargaImage(sprite.Path); } else { sprite.Img = new Bitmap(sprite.Path); } sprite.Img.ReplaceColor(Editor.TransparentColor, Color.Transparent); this.AddTile(sprite, new Point(Convert.ToInt32(tab[1]), Convert.ToInt32(tab[2])), tab.Length > 3 ? (int?)Convert.ToInt32(tab[3]) : null); } this.PushForUndoRedo(); this.UpdateStatusbar(); /*this.panelGrid.Controls.Add(new Panel * { * Width = 1, * Height = 1, * BackColor = Color.Transparent, * Left = 5000, * Top = 5000, * });*/ return(true); } } finally { Cursor.Current = Cursors.Default; } }
/// <summary> /// マテリアルをUnity用に変換する /// </summary> /// <returns>Unity用マテリアル</returns> /// <param name='material_index'>PMX用マテリアルインデックス</param> /// <param name='is_transparent'>透過か</param> private Material ConvertMaterial(uint material_index, bool is_transparent) { var material = format_.material_list.material[material_index]; //先にテクスチャ情報を検索 Texture2D main_texture = null; if (material.usually_texture_index == uint.MaxValue) { main_texture = Texture2D.whiteTexture; } else { var texture_file_name = format_.texture_list.texture_file[material.usually_texture_index]; var path = format_.meta_header.folder + "/" + texture_file_name; if (File.Exists(path)) { if (material.usually_texture_index < format_.texture_list.texture_file.Length) { if (texture_file_name.EndsWith(".dds", StringComparison.OrdinalIgnoreCase)) { try { main_texture = DDSImage.LoadDDS(path); main_texture.wrapModeV = TextureWrapMode.MirrorOnce; } catch { main_texture = Texture2D.whiteTexture; } } else if (texture_file_name.EndsWith(".bmp", StringComparison.OrdinalIgnoreCase)) { main_texture = BMPLoader.LoadBMP(path).ToTexture2D(); } else if (texture_file_name.EndsWith(".tga", StringComparison.OrdinalIgnoreCase)) { try { var bitmap = TargaImage.LoadTargaImage(path); main_texture = new Texture2D(bitmap.Width, bitmap.Height); var stream = new MemoryStream(); bitmap.Save(stream, ImageFormat.Png); main_texture.LoadImage(stream.ToArray()); stream.Close(); main_texture.Apply(); } catch (Exception e) { Debug.Log("TGA Exception"); Debug.Log(texture_file_name); Debug.LogError(e.Message); main_texture = Texture2D.whiteTexture; } //main_texture = CreateTexture(path); } else { main_texture = new Texture2D(1, 1, TextureFormat.RGBA32, false); main_texture.LoadImage(File.ReadAllBytes(path)); // Fill the texture field } //main_texture.alphaIsTransparency = true; } } else { main_texture = Texture2D.whiteTexture; } } #if Unlit var result = new Material(Resources.Load <Material>("MMDUnlit")) { renderQueue = (int)(3000 + material_index) }; result.SetTexture("_UnlitColorMap", main_texture); result.SetVector("_UnlitColor", material.diffuse_color); result.SetFloat("_TransparentSortPriority", material_index); result.name = format_.material_list.material[material_index].name; return(result); #else var result = new Material(Resources.Load <Material>("MMDLit")) { renderQueue = (int)(3000 + material_index) }; result.SetTexture("_BaseColorMap", main_texture); result.SetVector("_BaseColor", material.diffuse_color); result.SetFloat("_Smoothness", 0f); result.SetFloat("_TransparentSortPriority", material_index); result.name = format_.material_list.material[material_index].name; return(result); #endif }
public override void vmethod_0(GameTime gameTime_0, SpriteBatch spriteBatch_0) { this.gclass143_0.method_3(gameTime_0, spriteBatch_0); Vector2 vector2_1 = this.method_13(this.int_9, this.int_10); if (this.GClass32_0 != null) { string text = new string(this.GClass32_0.Name.Where <char>((Func <char, bool>)(char_0 => this.spriteFont_0.Characters.Contains(char_0))).ToArray <char>()); Vector2 vector2_2 = this.spriteFont_0.MeasureString(text); int num1 = 20; float num2 = vector2_2.X + (float)(2 * num1); float num3 = vector2_2.Y + (float)(2 * num1); spriteBatch_0.smethod_0(new Microsoft.Xna.Framework.Rectangle((int)((double)vector2_1.X - (double)num2 / 2.0), (int)((double)vector2_1.Y + 64.0 + 12.0), (int)num2, (int)num3), this.texture2D_3, 30, Microsoft.Xna.Framework.Color.White); spriteBatch_0.DrawString(this.spriteFont_0, text, new Vector2(vector2_1.X - num2 / 2f + (float)num1, (float)((double)vector2_1.Y + 64.0 + 12.0) + (float)num1), Microsoft.Xna.Framework.Color.Black); } try { string shortTimeString = DateTime.Now.ToShortTimeString(); Vector2 vector2_2 = this.spriteFont_0.MeasureString(shortTimeString); spriteBatch_0.DrawString(this.spriteFont_0, shortTimeString, new Vector2((float)((double)GClass138.graphicsDeviceManager_0.PreferredBackBufferWidth - (double)vector2_2.X - 25.0), 0.0f), Microsoft.Xna.Framework.Color.White); } catch { } if (this.bool_2) { if ((double)this.float_0 < 1.0) { spriteBatch_0.Draw(this.texture2D_2, new Microsoft.Xna.Framework.Rectangle(0, 0, GClass138.graphicsDeviceManager_0.PreferredBackBufferWidth, GClass138.graphicsDeviceManager_0.PreferredBackBufferHeight), Microsoft.Xna.Framework.Color.White * this.float_0); this.float_0 += 0.01f; } else { this.method_0(); MediaPlayer.Stop(); spriteBatch_0.Draw(this.texture2D_2, new Microsoft.Xna.Framework.Rectangle(0, 0, GClass138.graphicsDeviceManager_0.PreferredBackBufferWidth, GClass138.graphicsDeviceManager_0.PreferredBackBufferHeight), Microsoft.Xna.Framework.Color.White); if (this.texture2D_1 != null) { spriteBatch_0.Draw(this.texture2D_1, new Microsoft.Xna.Framework.Rectangle(0, 0, GClass138.graphicsDeviceManager_0.PreferredBackBufferWidth, GClass138.graphicsDeviceManager_0.PreferredBackBufferHeight), Microsoft.Xna.Framework.Color.White); spriteBatch_0.Draw(this.texture2D_5, new Vector2(0.0f, 0.0f), Microsoft.Xna.Framework.Color.White); } if (this.task_0 != null) { return; } // ISSUE: object of a compiler-generated type is created // ISSUE: variable of a compiler-generated type Class120.Class117 class117 = new Class120.Class117(); // ISSUE: reference to a compiler-generated field class117.class120_0 = this; // ISSUE: reference to a compiler-generated field class117.gclass95_0 = this.GClass32_0.method_14(true); // ISSUE: reference to a compiler-generated field class117.gclass95_0.FullScreen = true; // ISSUE: reference to a compiler-generated field class117.gclass95_0.Event_0 += (EventHandler)((sender, e) => { this.Hide = false; this.method_5(); }); // ISSUE: reference to a compiler-generated field // ISSUE: reference to a compiler-generated field if (File.Exists(class117.gclass95_0.String_1) && File.Exists(class117.gclass95_0.String_2)) { // ISSUE: reference to a compiler-generated field using (Bitmap bitmap = TargaImage.LoadTargaImage(class117.gclass95_0.String_1)) { using (MemoryStream memoryStream = new MemoryStream()) { bitmap.Save((Stream)memoryStream, ImageFormat.Png); this.texture2D_1 = Texture2D.FromStream(GClass138.graphicsDevice_0, (Stream)memoryStream); } } this.method_17(this.GClass32_0, 1f); } // ISSUE: reference to a compiler-generated method this.task_0 = Task.Delay(this.GClass32_0.System == GEnum3.const_1 ? 7000 : 1000).ContinueWith(new Action <Task>(class117.method_0)); } } else { Texture2D texture2D1 = this.texture2D_1; if (texture2D1 != null) { // ISSUE: explicit non-virtual call __nonvirtual(texture2D1.Dispose()); } this.texture2D_1 = (Texture2D)null; } }