mirror of
https://github.com/opensim/opensim.git
synced 2026-05-20 15:25:47 +08:00
* 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.
49 lines
1.4 KiB
C#
49 lines
1.4 KiB
C#
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);
|
|
}
|
|
}
|
|
}
|