c# - Bitmap.Save() method is not working in Unity source -
i wanna implement 'bitmap texture2d' function in unity.
i learned make texture2d instance, use syntax below.
// **loadimage(byte[] arr)** can load byte array data , make texture2d var data = bitmaptobytemethod(bitmap); var texturecanvas = new texture2d(bitmap.width, bitmap.height, textureformat.argb32, false); texturecanvas.loadimage(data); texturecanvas.apply();
to make function did this.
using (memorystream memorystream = new memorystream()) { imagecodecinfo jpgencoder = getencoder(imageformat.jpeg); system.drawing.imaging.encoder myencoder = system.drawing.imaging.encoder.quality; encoderparameters myencoderparameters = new encoderparameters(1); encoderparameter myencoderparameter = new encoderparameter(myencoder, 100l); myencoderparameters.param[0] = myencoderparameter; // point error occurred. bitmap.save(memorystream, jpgencoder, myencoderparameters); //bitmap.save(memorystream, imageformat.jpeg); return memorystream.toarray(); }
first, have bitmap image. second, convert bitmap byte array. (it works in c# sample project.) when try run function in unity, unity program shut down after 'bitmap.save()' method.
i'm beginner of unity not easy solve problems.. below source sample code in project.
system.drawing
not supported unity3d. because it's based on gdi+ , unity multiplatform, couldn't used anywhere on windows (mono has own version of gdi+ *nix systems, doesn't work unity either). official reason seems "system.drawing doesn't work opengl/directx".
there seem hacks use make work, makes sense if want stick windows. if want go way, there's answer on unity3d forums should - http://answers.unity3d.com/answers/253571/view.html
Comments
Post a Comment