Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Nanashi91 · Jan 21, 2013 at 06:13 PM · c#arrayconvertstreambyte

C# convert Bytearray to System.Draw.Image

Hello,

I need to convert a Byte array back into an image. If I do that in the Unity IDE it is working but if I do it after I compiled it in windows it is not working anymore. I am converting the Byte array into a Stream and try to convert the Stream into an image afterwards.

 Stream tempstream;
 System.Drawing.Image tempimage = null;
 try{
             Byte[] ba;
             ba = (Byte[]) reader["FlagPng"];
             Debug.Log ("ByteArray: "+ba.ToString ());
             tempstream = new MemoryStream(ba);
             Debug.Log ("tempstream: "+tempstream.ToString ());
             tempimage = Image.FromStream(tempstream);
         }
         catch(Exception ex){
                 Debug.LogError ("Errormessage 100: \n "+ex.Message );
                 Debug.LogError ("Errorsource 100: \n "+ex.Source );
                 Debug.LogError ("Errorstacktrace 100: \n "+ex.StackTrace);
                 Debug.LogError ("Errortargetsite 100: \n "+ex.TargetSite);
                 
                 
         }

In my output_log is written: ByteArray: System.Byte[]

tempstream: System.IO.MemoryStream

Errormessage 100: Could not load type 'System.IO.InternalBufferOverflowException' from assembly 'System.Drawing'.

Errorsource 100: System.Drawing

Errorstacktrace 100: at System.Drawing.Image.InitFromStream (System.IO.Stream stream) [0x00000] in :0

at System.Drawing.Image.LoadFromStream (System.IO.Stream stream, Boolean keepAlive) [0x00000] in :0

at System.Drawing.Image.FromStream (System.IO.Stream stream) [0x00000] in :0

at SQLDatabase.ReadTblLanguages () [0x00000] in :0

Errortargetsite 100: IntPtr InitFromStream(System.IO.Stream)

I can tell that the problem should be the line: tempimage = Image.FromStream(tempstream);

All dlls I am using are mono dlls from the library directory of Unity.

Can anyone tell me how I can convert a stream into an image in Unity?

Thank you in advance.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Julien-Lynge · Jan 21, 2013 at 07:52 PM

I'm going to refer you to other questions - the problem is with System.Drawing:

http://answers.unity3d.com/questions/26576/why-is-the-systemdrawing-namespace-not-supported-i.html

http://forum.unity3d.com/threads/13191-System.Drawing-Question

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Nanashi91 · Jan 22, 2013 at 10:40 AM 0
Share

Thank you for your hint. I worked it out another way. Unity offers the function Texture2D.LoadImage which can handle a Byte array.

avatar image Julien-Lynge · Jan 22, 2013 at 03:36 PM 0
Share

Yep, as long as the bytes correspond with a jpg or png you're fine there.

avatar image
0

Answer by unity_Gf9sAXj5a0VNOg · Oct 30, 2017 at 02:48 PM

demonstrated how to convert byte array to image and save in c# and upload image on server in aspnet using c# with an example. Find the c# source code below to convert byte array to image c# here

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

String Parsing 1 Answer

Using an array instead 2 Answers

Help converting this to C# - a few issues 3 Answers

Convert to array. 1 Answer

Get JSON array object string value 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges