Search code examples
c#winformsimagepdfsharpmigradoc

How to use bitmap from resources instead of the file (migradoc)?


How to use e.g. bitmap from resources instead of physical image file in class MigraDoc.DocumentObjectModel.Tables.Cell

in method public Image AddImage(string fileName); ?


Solution

  • If you've added an image with the name "myImage" to your projects resources use this code:

    Properties.Resources.myImage
    

    In your example adjust the parameter:

    public Image AddImage(Image img);
    

    And call it like this:

    AddImage(Properties.Resources.myImage);
    

    If it is required to pass a filename just write the Image to a file first (perhaps to the temp directory):

        string fileName = "C:\\image.jpg";
    
        ((Bitmap)Properties.Resources.myImage).Save(fileName, ImageFormat.Jpeg);
    
        AddImage(fileName);