Question by
hean · Jul 29, 2019 at 06:43 AM ·
c#unity 5scripting problemscript errorscriptingproblem
How do you copy an image from the clipboard into an ui image?
using UnityEngine;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
public class RetrieveTextureFromClipboard : MonoBehaviour
{
public UnityEngine.UI.Image imagee;
private Texture2D RetrieveFromClipboard()
{
System.Drawing.Image imagee = System.Windows.Forms.Clipboard.GetImage();
byte buff = (byte)(imagee.Width * imagee.Height);
System.IO.MemoryStream s = new System.IO.MemoryStream(buff);
imagee.Save(s, System.Drawing.Imaging.ImageFormat.Jpeg);
Texture2D texture = new Texture2D(imagee.Width, imagee.Height);
texture.LoadImage(s.ToArray());
s.Close();
s.Dispose();
return texture;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.C))
{
Texture2D texture = RetrieveFromClipboard();
imagee.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.one * 0.5f);
imagee.preserveAspect = true;
}
}
}
So i have that code here
which allows me to get an image from the clipboard. problem is that it stopped working when switching to unity 2019... Can anyone help me find a solution ? It worked perfectly on unity 2018
Comment
Your answer
Follow this Question
Related Questions
Having trouble deleting objects from a list after they reach a certain scale. 0 Answers
How to use the GPGS ISavedGameMetadata? 1 Answer
Problem with Score/Highscore script 0 Answers
Can't get script to repeat 0 Answers
Microphone Input to Spawn object 2 Answers