Jump to content
  • Advertisement
Gautti

C# MemoryStream use in Unity for System.Drawing.Image

Recommended Posts

Hi, I am really confused how to load System.Drawing.Image using MemoryStream in Unity.  My code is working in Unity Editor only but I can't get system image from Windows build

here is my code,

using UnityEngine;

using System.Drawing;

 public Image byteArrayToImage(byte[] byteArrayIn)
    {
        MemoryStream ms = new MemoryStream(byteArrayIn);
        Image returnImage = Image.FromStream(ms);
        return returnImage;

    }

I want to print image from this code i have attached the printer and i got image in editor but when I build in windows, I get an error with Object reference not set to instance of an object for an issue of MemoryStream. Any help will be appreciated.

Share this post


Link to post
Share on other sites
Advertisement

You know that System.Drawing is not officially supported in Unity standalone builds because it contains heavy platform depending code?

You could add a null check before using the MemoryStream if you think the error relates to the MemoryStream not being initialized properly to get if it is realy related to that or a problem of something inside the Image.FromStream function.

Also the exact error message would be helpfull.

Share this post


Link to post
Share on other sites

Thanks Shaarigan for your valuable reply, But how could I get my result ? Officially i need a system image using Unity for a printing purpose. As you know we can not convert system.image from Unity UI image.

Share this post


Link to post
Share on other sites

Ok Thank you Shaarigan, I got a print by saving my image file in certain folder and then I got working. By the way do you know how to get printer status like Paper Jammed, Paper Out, Start, ideal or running from Unity ? Actually I am working in printer base project and I want to show printer status before printing anything from Unity.

Share this post


Link to post
Share on other sites

How to know the Thermal USB Printer Status in Unity like paper jammed, paper out etc. ?

Share this post


Link to post
Share on other sites

You wont without a highly platform related extension. Unity isn't the best choice for doing "Office Work" as it is designed to provide platform independent game experiences and so just carries only game related features by design

Share this post


Link to post
Share on other sites

Thanks Shaarigan, But I need to print ticket out from thermal printer. Actually I am developing a slot game and for a ticket print I just want to attach a printer. There is a functionality from it I can get the status of a printer from Unity side.

Share this post


Link to post
Share on other sites

So you have certain platform set for that game or do you require for every user on every possible platform to have a printer attached?

Otherwise you know what platform this will run at and could write a Printer Plugin for that special kind of hardware by yourself and embedd it into Unity

Share this post


Link to post
Share on other sites

Yes, Exactly i just wanted to get appear the status of currently attached printer from Unity to windows build before printing document.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!