While AutoCAD shows raster image inserted into Drawing in Xreference Manager, rasterimage is fundamentally/quite different from Xref, even user deals it in same/similar ways for inserting(attaching), load/reload... So, Database.Reload[Resulve]Xrefs() does nothing to RasterImage in drawing.
In your case, when RasterInageDef.SourceFileName is changed, RasterImage.IsLoaded property changes (i.e. if it was true, it changes to false). So, after changing SourceFileName property, if you want the RasterImage that references the RasterImageDef to be visible, you need to call RasterImageDef.Load() method.
See following code example:
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using CadApp = Autodesk.AutoCAD.ApplicationServices.Application;
[assembly: CommandClass(typeof(UpdateImagePath.MyCommands))]
namespace UpdateImagePath
{
public class MyCommands
{
[CommandMethod("ImgPath")]
public static void RunMyCommand()
{
var imgPath =
@"C:\Users\norman.yuan\Documents\Visual Studio 2019\Projects\AutoCAD2020\MiscTests\UpdateImagePath\Images";
var doc = CadApp.DocumentManager.MdiActiveDocument;
var ed = doc.Editor;
var imgId = SelectImage(ed);
if (!imgId.IsNull)
{
UpdateImagePath(imgId, imgPath);
ed.UpdateScreen();
}
}
private static ObjectId SelectImage(Editor ed)
{
var opt = new PromptEntityOptions(
"\nSelect raster image:");
opt.SetRejectMessage("\nNot raster image!");
opt.AddAllowedClass(typeof(RasterImage), true);
var res = ed.GetEntity(opt);
return res.Status == PromptStatus.OK ? res.ObjectId : ObjectId.Null;
}
private static void UpdateImagePath(ObjectId imgId, string imgPath)
{
using (var tran = imgId.Database.TransactionManager.StartTransaction())
{
var img = (RasterImage)tran.GetObject(imgId, OpenMode.ForRead);
var imgDef = (RasterImageDef)tran.GetObject(img.ImageDefId, OpenMode.ForWrite);
CadApp.ShowAlertDialog(
$"IsLoaded: {imgDef.IsLoaded}");
var fileName = System.IO.Path.GetFileName(imgDef.SourceFileName);
imgDef.SourceFileName = imgPath + "\\" + fileName;
CadApp.ShowAlertDialog(
$"IsLoaded after SourceFileName changed: {imgDef.IsLoaded}");
imgDef.Load();
tran.Commit();
}
}
}
}
Notice: the second alert dialog (after SourceFileName is changed) would show IsLoaded property becomes "false".