Raster image updating/modification

By Virupaksha Aithal

Below code shows the procedure to update/modify the image source of the raster image. Code, prompts the user to select a Raster image and from image, it finds the image definition to modify. Note, as image definition is getting modified, the change in image is reflected in all the references of the image definition.

[CommandMethod("updateImage")]
public static void updateImage()
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;
 
    PromptEntityOptions options =
        new PromptEntityOptions("nSelect Raster image to change");
    options.SetRejectMessage("nSelect only Raster image");
    options.AddAllowedClass(typeof(RasterImage), false);
 
    PromptEntityResult acSSPrompt = ed.GetEntity(options);
 
    if (acSSPrompt.Status != PromptStatus.OK)
        return;
 
    using (Transaction Tx = db.TransactionManager.StartTransaction())
    {
        //get the mleader
        RasterImage image = Tx.GetObject(acSSPrompt.ObjectId,
                                   OpenMode.ForRead) as RasterImage;
 
        RasterImageDef ImageDef = Tx.GetObject(image.ImageDefId,
                               OpenMode.ForWrite) as RasterImageDef;
 
        ImageDef.SourceFileName = "c:\temp\new.jpeg";
        ImageDef.ActiveFileName = "c:\temp\new.jpeg";
 
        ImageDef.Load();
 
        Tx.Commit();
    }
}

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading