Kiểm tra xem hình ảnh được tham chiếu bên ngoài có tồn tại không và thay thế tham chiếu
Contents
[
Hide
]Cách chỉnh sửa liên kết trên các đối tượng
Vấn đề: Làm thế nào để kiểm tra xem hình ảnh được tham chiếu bên ngoài có tồn tại và thay thế tham chiếu (CADNET-8088).
Mẹo: Để thực hiện điều này, lấy một thực thể có loại CadObjectTypeName.IMAGEDEF từ các thực thể bản vẽ và sử dụng CadRasterImageDef để kiểm tra.
Ví dụ:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foreach (CadBaseObject baseObject in cadImage.Objects) | |
{ | |
if (baseObject.TypeName == CadObjectTypeName.IMAGEDEF) | |
{ | |
// the relation between CadRasterImageDef (in cadImage.Objects) and CadRasterImage (in cadImage.Entities) is by | |
// cadRasterImageDef.ObjectHandle == cadRasterImage.ImageDefReference | |
CadRasterImageDef rasterImageDef = (CadRasterImageDef)baseObject; | |
// path may be relative or absolute | |
if (!File.Exists(rasterImageDef.FileName)) | |
{ | |
// rasterImageDef.FileName = @"D:\Users\Oleksii\Desktop\c2.jpg"; | |
rasterImageDef.FileName = "13521951017666.jpg"; | |
cadImage.UpdateSize(); | |
} | |
} | |
} |