• 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
12
Question by Dani · Mar 19, 2011 at 11:54 AM · drawing

Using drawing package like System.Drawing

I need to dynamically(in script) draw on texture.
I know I can use Texture2D.SetPixel, but I need shapes(which I can implement by my own) and text(which is much more complex).
I know I can do something like a camera drawing to texture and use GUI to draw on it, but GUI is rather lacking most of the drawing feature in package like System.Drawing.
What I thought of doing is writing to System.Drawing.Bitmap using System.Drawing.Graphics, save the Bitmap to memory stream and then using Texture2D.LoadImage to load the image. But then I noticed System.Drawing is disabled in Unity.
I found a similar problem in forums regarding this, but the answer was that its not compatible with OpenGL/DirectX.
What I need to do is not drawing to screen, I need to draw to memory stream which is fully compatible with both OpenGL and DirectX (I was using this in an DirectX project I'm trying to convert to Unity now).
What can I do?

Comment
Add comment · Show 7
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 Demigiant · Mar 19, 2011 at 04:30 PM 1
Share

I'm very curious about this. Hope someone will give you more details.

avatar image Honorsoft Demigiant · Dec 21, 2017 at 05:55 AM 0
Share

Yeah, I know it's over 6 years later but, this is for anyone still curious. I experimented with System.Drawing before, got it to work in the Editor, but compiled to android didn't work, and compiled to PC didn't work. No errors, but no "system drawings" showed up. I tried placing the DLL in different places and I tried various versions of the DLL required for System.Drawing, but no success in getting it to show up in compiled builds. I'm not surprised about Android builds, but the PC build should have worked. Anyways, I used the 'animated gif drawing' source found online(uses System.Drawing) and got it to work in Unity, it drew the gif with looping animation perfectly, except it draws it upside-down. It is possible to fix but my math is bad..lol(FOR loop data needs to be inverted), I had the same problem years ago doing AVI file manipulation in OpenGL. RealTimePainting's method of texture drawing uses an updated method to fully modify a texture in real-time, and does not use System.Drawing, so I recommend that.

avatar image danny.tequila · Mar 19, 2012 at 03:16 PM 1
Share

I need an answer to this one too! I want to draw a line from a 3d point up to a circle with some floating text, then drop that bitmap on the gui layer.

avatar image ikas · May 17, 2012 at 09:00 AM 0
Share

really baffling as to Unity doesn't support such a mechanism. Would love to get some workarounds for this.

avatar image DarkCloud14 · May 17, 2012 at 09:41 PM 0
Share

@ikas it could be, that it's not officially supported as System.Drawing has methods to draw things on screen using GDI but GDI is not compatible with OpenGL or DirectX as far as I know. Unity uses those to draw stuff and has it's own methods for those things. It is also possible, that System.Drawing is not supported from mono for the mobile platforms but I'm not sure about that. Did you read my answer on how to use System.Drawing anyway at least some of it's functionality like loading pictures with the Bitmap class and then convert it to Texture2D to draw it on screen with Unity.. I think some other functions should also work but don't ask me what else...

avatar image madhh · May 08, 2014 at 04:40 PM 0
Share

$$anonymous$$y only question would be, how come it draws one line just like I want it to, and at next line it uses the first coordinate as a middle point, and the second coordinate as a "width". Any ideas? So I wanted to draw a triangle, and this is what I get: alt text

Show more comments

5 Replies

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

Answer by DarkCloud14 · May 16, 2012 at 10:55 PM

Hi there,

not sure if still someone wants to know how to use System.Drawing even if it's not officially supported by Unity. Ok here is what I've found out for Unity 3.5.1f2 so far:

  1. If you wanna use it and don't want to get Errors in Unity Editor (not MonoDevelop) you must drag the file System.Drawing.dll into your Project tree. On default Windows Installation the file can be found in the following directory: %Unity Folder%\Editor\Data\Mono\lib\mono\2.0 on OSX it should be in the Unity.app in somewhere. You may also be able to use the current System.Drawing.dll of Mono 2.10.8 but I didn't test this yet.

  2. The Api Compatibility Level must be set to .NET 2.0!! The option ".NET 2.0 Subset" doesn't work.

  3. For a Windows only version you would be done now and it should work. I didn't test the whole functionality of System.Drawing!! I just tested some of the Bitmap functionality.

  4. Additional step for MacOSX: After you've build the Application you should open the .app/Contents directory. Create a Plugins directory there and the copy the file libgdiplus.dylib from the lib directory of Mono 2.10.8 for OSX (On windows you can use 7-zip and some other tools to get the libgdiplus.dylib from the OSX download image)! After another test the version of Unity at least the one shipped with Windows Unity doesn't work. Now rename the file libgdiplus.dylib to gdiplus.dll.bundle. After that it should also work under OSX.

As I'm new to Unity I'm not sure if it's possible to do the last step over the editor too so it'll do that step automatically.

Under OSX I used XCodes Instruments to find out where Unity application tries to load the gdiplus.dll from and has choosen a path that is inside the applications directory (Plugins). Don't ask me why it tries just to load a file or normally a bundle with the name gdiplus.dll.bundle instead of libgdiplus.dylib like it does in other directories.

Ok that's it so far hope this will help someone somehow. As I said I didn't use the full functionality of System.Drawing.dll nor did I test if really every class / function works.

Comment
Add comment · Show 8 · 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 DanSuper · Jan 09, 2013 at 08:14 PM 0
Share

I haven't been able to get this solution to work on OSX. The $$anonymous$$ono distribution (2.10.10) only contains an Alias for libgdiplus.dylib and the actual library appears to be named libgdiplus.0.dylib Regardless... after following your instructions with both files I continue to get the DLLNotFound Exception for gdiplus.dll

avatar image Fornoreason1000 · Aug 12, 2013 at 06:58 AM 0
Share

It tends to Crash alot when using conversion between Textures and Bitmap Classes.

avatar image LightStriker · Oct 12, 2013 at 04:36 PM 0
Share

We have the same issue here on OSX. System.Drawing is fine, but crash went trying to resolve gdiplus.dll. It's really annoying.

avatar image DaFox · Dec 16, 2013 at 01:24 PM 0
Share

This saved my ass. I have an array of bytes in RGBA32 format I was wanting to dump them to disk and the Bitmap class within System.Drawing seemed to be by far the easiest method.

And it worked wonders.

 static void DumpRGBA32ToDisk(byte[] rgba, uint width, uint height) {
     System.Drawing.Bitmap bmp = new System.Drawing.Bitmap((int)width, (int)height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
     System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), System.Drawing.Imaging.ImageLock$$anonymous$$ode.WriteOnly, bmp.PixelFormat);
     System.Runtime.InteropServices.$$anonymous$$arshal.Copy(rgba, 0, bmpData.Scan0, rgba.Length);
     bmp.UnlockBits(bmpData);
     bmp.Save("TESTING.png");
 }
avatar image italo.portinho · Aug 22, 2014 at 05:17 PM 0
Share

Thank you. Works great!

Show more comments
avatar image
2

Answer by mattleibow · Sep 24, 2017 at 10:48 PM

This is a super old answer, but I am looking at getting SkiaSharp to work with Unity. SlkiaSharp is a powerful, free, open-source 2D graphics engine that supports all .NET platforms.

It already works with Unity, but I am having a few issues in some areas on some platforms: http://answers.unity3d.com/questions/1411593/linux-build-is-putting-libnativeso-in-wrong-place.html

Information:

  • SkiaSharp: https://github.com/mono/SkiaSharp

  • Unity Demo: https://github.com/mattleibow/SkiaSharpUnityDemo

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
avatar image
0

Answer by noahmilam · Oct 19, 2016 at 10:13 PM

for mac download: http://www.search-dll.com/dll-files/download/system.drawing.dll.html place into assets folder. seemed to work for me.

Comment
Add comment · Show 1 · 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 BobBobson108 · Feb 09, 2018 at 01:41 AM 1
Share

You absolutely should never download a DLL from the internet unless it's from the company that made it (i.e., don't download a $$anonymous$$icrosoft DLL unless you're downloading it from $$anonymous$$icrosoft). The DLL you downloaded could easily have malicious code that runs on your computer - but you don't know because you didn't compile it. I don't know what search-dll is, but the name is sketchy enough that I'd be willing to be what you downloaded is not trusted.

avatar image
3

Answer by AltSoftLab · Aug 05, 2014 at 07:52 PM

WARNING: COMMERCIAL SOLUTION

You can use AltSketch Graphics Library that has System.Drawing like program interface and fully C# managed code (Mono, Mobile platforms supported too).

AltSketch project forum thread here: http://forum.unity3d.com/threads/on-sale-50-off-altsdk-altassets-altgui-altos-altsketch-altstudio-frameworks-editors.335966/#post-2182031

AltSketch Description:

AltSketch is a pure C# CLS compliant 100% managed, without unsafe blocks Vector Graphics Library with Software and Hardware Render Backends for Games, Scientific Applications & other uses of Computer Graphics. All core functionality collected in one lightweight library AltSketch.dll for Microsoft .NET Framework or Mono (including Silverlight / Moonlight). It depends only on System assembly (.NET Framework 2.0).

AltSketch has Software and Hardware Render Backends (solid and texure AA visual data triangulation), contains a subsystem AltNETType - port of wonderful font rendering library Freetype and subsystem AltNETImage for Image manipulations (loading, saving, transformations).

As AltSketch has several integrations with most popular GUI systems and Mobile platforms, you can develop and test a drawing part of your 3D application/game as independent program, and then easy integrate it into your main solution. Now you can draw Graphics in 3D with Brushes and Pens like you do it with any drawing library. It is flexible and useful development method in case of main project bulking and test complexity, or useful for team development process. Now you can develop graphics part of your Mobile applications without using an emulator as stand-alone application, only running on Mobile devices (or Emulator) for final tests.

AltSketch has Virtual File System support with Zip containers for resources loading. All AltSketch functionality & extensions works via VirtualFS and all resources can be loaded as from real file system, so from Zip containers (from files or memory streams).

AltSketch SDK includes wide variety of open source extensions: ported to AltSketch popular libraries (GUI, Plot, GIS, Computer Science, Physics, Graphics etc.): AForge, NPlot, OxyPlot, PieChart, ZedGraph, MigraDoc, PDFsharp, GMap, HTML Renderer, Box2D, Farseer Physics, etc.

AltSketch SDK includes many Integration Demos with a wide variety GUI-s & frameworks (all Integrations & HW Render Backends are open sourced, so you can easily adapt it to your applications or improve it if you need)

alt text

Comment
Add comment · Show 5 · 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 Alexander31 · Jun 28, 2015 at 06:34 PM 0
Share

Are you really ported full FreeType to C#? If yes, only because of this one thing you are amazing guys!!! And other tools looks great! What is the part of System.Drawing/GDI+ supported by AltSketch?

avatar image domiii · Jul 01, 2015 at 01:26 PM 0
Share

You might want to mention that this costs 50$US...

avatar image slippdouglas · Jul 01, 2015 at 08:25 PM 1
Share

@domiii Agreed. Stack Overflow's community-decided policy is that if you're promoting your own tool/library/framework/app/etc., your post should be prefixed with a warning. The intent is to keep SO from beco$$anonymous$$g just a bunch of advertisements. In that spirit, I'm downvoting this answer until an italicized warning is added to the top of it; I'll change my downvote to an upvote then.

avatar image AltSoftLab · Jul 01, 2015 at 09:11 PM 2
Share

Hi guys! No problem. Is it better now?

avatar image AltSoftLab · Jul 01, 2015 at 09:14 PM 0
Share

$$anonymous$$31 all information you can get on AltSD$$anonymous$$ Asset Unity forum thred

avatar image
1

Answer by slippdouglas · Apr 24, 2014 at 07:28 AM

A good portion of the AForge.NET graphics framework (AFAIK, all of AForge.Imaging) is Mono-compatible (according to this forum post).

I haven't yet taken the steps to build a DLL and try it in Unity— would love to hear if anyone else takes a stab at it.  And I'll update this answer if I get it working.

Comment
Add comment · Show 1 · 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 AltSoftLab · Jun 15, 2015 at 05:55 PM 0
Share

Some parts of pure C# AForge functionality have been ported to AltSketch http://forum.unity3d.com/threads/on-sale-50-off-altsdk-altassets-altgui-altos-altsketch-altstudio-frameworks-editors.335966/#post-2182031

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

22 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

DrawMesh always drawn before gameobjects 1 Answer

Rate an object is drawn 1 Answer

Debug.draw rect 2 Answers

Objects Appear in the wrong place when built 1 Answer

How to find out how much of a Polygon is filled? 0 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