2525
2626using System ;
2727using System . Collections . Generic ;
28- using System . Drawing ;
29- using System . Drawing . Imaging ;
3028using Newtonsoft . Json ;
3129using Newtonsoft . Json . Converters ;
3230using Newtonsoft . Json . Serialization ;
31+ using SixLabors . ImageSharp ;
32+ using SixLabors . ImageSharp . PixelFormats ;
3333
3434namespace MiNET . Utils . Skins
3535{
@@ -87,7 +87,7 @@ public SkinResourcePatch SkinResourcePatch
8787 public string GeometryName { get ; set ; }
8888 public string GeometryData { get ; set ; }
8989 public string GeometryDataVersion { get ; set ; }
90-
90+
9191 public string ArmSize { get ; set ; }
9292
9393 public string SkinColor { get ; set ; }
@@ -103,11 +103,12 @@ public SkinResourcePatch SkinResourcePatch
103103
104104 public static byte [ ] GetTextureFromFile ( string filename )
105105 {
106- Bitmap bitmap = new Bitmap ( filename ) ;
106+ var bitmap = Image . Load < Rgba32 > ( filename ) ; // new Image<Rgba32> (filename);
107107
108108 var size = bitmap . Height * bitmap . Width * 4 ;
109109
110- if ( size != 0x2000 && size != 0x4000 && size != 0x10000 ) return null ;
110+ if ( size != 0x2000 && size != 0x4000 && size != 0x10000 )
111+ return null ;
111112
112113 byte [ ] bytes = new byte [ size ] ;
113114
@@ -116,7 +117,7 @@ public static byte[] GetTextureFromFile(string filename)
116117 {
117118 for ( int x = 0 ; x < bitmap . Width ; x ++ )
118119 {
119- var color = bitmap . GetPixel ( x , y ) ;
120+ var color = bitmap [ x , y ] ;
120121 bytes [ i ++ ] = color . R ;
121122 bytes [ i ++ ] = color . G ;
122123 bytes [ i ++ ] = color . B ;
@@ -134,15 +135,7 @@ public static void SaveTextureToFile(string filename, byte[] bytes)
134135 int width = size == 0x10000 ? 128 : 64 ;
135136 var height = size == 0x2000 ? 32 : ( size == 0x4000 ? 64 : 128 ) ;
136137
137- var bitmap = new Bitmap ( width , height ) ;
138-
139- BitmapData bmpData = bitmap . LockBits ( new Rectangle ( 0 , 0 , bitmap . Width , bitmap . Height ) , ImageLockMode . ReadWrite , bitmap . PixelFormat ) ;
140-
141- int bytesPerPixel = Bitmap . GetPixelFormatSize ( bitmap . PixelFormat ) / 8 ;
142- int byteCount = bmpData . Stride * bitmap . Height ;
143- byte [ ] rgbValues = new byte [ byteCount ] ;
144-
145- System . Runtime . InteropServices . Marshal . Copy ( bmpData . Scan0 , rgbValues , 0 , byteCount ) ;
138+ var bitmap = new Image < Rgba32 > ( width , height ) ;
146139
147140 int i = 0 ;
148141 for ( int y = 0 ; y < bitmap . Height ; y ++ )
@@ -154,19 +147,10 @@ public static void SaveTextureToFile(string filename, byte[] bytes)
154147 byte b = bytes [ i ++ ] ;
155148 byte a = bytes [ i ++ ] ;
156149
157- int index = y * bmpData . Stride + x * bytesPerPixel ;
158-
159- rgbValues [ index ] = r ;
160- rgbValues [ index + 1 ] = g ;
161- rgbValues [ index + 2 ] = b ;
162- if ( bytesPerPixel == 4 ) { rgbValues [ index + 3 ] = a ; }
150+ bitmap [ x , y ] = new Rgba32 ( r , g , b , a ) ;
163151 }
164152 }
165153
166- System . Runtime . InteropServices . Marshal . Copy ( rgbValues , 0 , bmpData . Scan0 , byteCount ) ;
167-
168- bitmap . UnlockBits ( bmpData ) ;
169-
170154 bitmap . Save ( filename ) ;
171155 }
172156
@@ -190,7 +174,7 @@ public static string ToJson(GeometryModel geometryModel)
190174 settings . MissingMemberHandling = MissingMemberHandling . Error ;
191175 //settings.Formatting = Formatting.Indented;
192176 settings . ContractResolver = new CamelCasePropertyNamesContractResolver ( ) ;
193- settings . Converters . Add ( new StringEnumConverter { NamingStrategy = new CamelCaseNamingStrategy ( ) } ) ;
177+ settings . Converters . Add ( new StringEnumConverter { NamingStrategy = new CamelCaseNamingStrategy ( ) } ) ;
194178
195179 return JsonConvert . SerializeObject ( geometryModel , settings ) ;
196180 }
0 commit comments