mirror of
https://github.com/opensim/opensim.git
synced 2026-08-06 01:06:30 +08:00
* Implements IGraphics interface for MRM Scripting.
* This allows you to utilize System.Drawing tools on textures within the region. * Example: use System.Drawing.Bitmap to make your texture, then use Host.Graphics.SaveBitmap to make an asset from it in JPEG2K. You can edit (but not overwrite) existing textures using Host.Graphics.LoadBitmap.
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
using System.Drawing;
|
||||
using OpenMetaverse;
|
||||
using OpenMetaverse.Imaging;
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Region.Framework.Scenes;
|
||||
|
||||
namespace OpenSim.Region.OptionalModules.Scripting.Minimodule
|
||||
{
|
||||
class Graphics : IGraphics
|
||||
{
|
||||
private readonly Scene m_scene;
|
||||
|
||||
public Graphics(Scene m_scene)
|
||||
{
|
||||
this.m_scene = m_scene;
|
||||
}
|
||||
|
||||
public UUID SaveBitmap(Bitmap data)
|
||||
{
|
||||
return SaveBitmap(data, false, true);
|
||||
}
|
||||
|
||||
public UUID SaveBitmap(Bitmap data, bool lossless, bool temporary)
|
||||
{
|
||||
AssetBase asset = new AssetBase();
|
||||
asset.FullID = UUID.Random();
|
||||
asset.Data = OpenJPEG.EncodeFromImage(data, lossless);
|
||||
asset.Name = "MRMDynamicImage" + Util.RandomClass.Next(1, 10000);
|
||||
asset.Type = 0;
|
||||
asset.Description = "MRM Image";
|
||||
asset.Local = false;
|
||||
asset.Temporary = temporary;
|
||||
m_scene.CommsManager.AssetCache.AddAsset(asset);
|
||||
|
||||
return asset.FullID;
|
||||
}
|
||||
|
||||
public Bitmap LoadBitmap(UUID assetID)
|
||||
{
|
||||
AssetBase bmp = m_scene.CommsManager.AssetCache.GetAsset(assetID, true);
|
||||
ManagedImage outimg;
|
||||
Image img;
|
||||
OpenJPEG.DecodeToImage(bmp.Data, out outimg, out img);
|
||||
|
||||
return new Bitmap(img);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user