Retreiving images with transparancy from revit document
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
A plugin we use generates rebar shape images with transparancy. (They're basically just black lines with some numbers or letters). For example:
I want to retreive said image from revit and save it to a .png file
Finding the image is no problem.
ButI have found that ImageType.GetImage() will always return an image with alpha channel set to 255.
In other words, I get the image data, WITHOUT transprancy.
I'm experimenting in Revit Python Console before commiting it to C#
#imports
clr.AddReference('System.Drawing')
from System.Drawing import Imaging
from System.Drawing import Bitmap
from System.Drawing import Graphics
from System.Drawing import Color
from System.Drawing import Rectangle
from System.Drawing import Image as sysImage
from System.Drawing.Imaging import ImageFormat
from System.Drawing.Imaging import *
clr.AddReference('System.IO')
from System.IO import FileStream
from System.IO import FileMode
# some base params
col = DB.FilteredElementCollector(doc)
imids = col.OfCategory(DB.BuiltInCategory.OST_RasterImages)
ims = [doc.GetElement(x) for x in imids.ToElementIds()]
#Write to file using filestream
def exportbmp(bmp, path):
fs = FileStream(path, FileMode.Create)
try:
bmp.Save(fs, ImageFormat.Png)
except:
print('something went wrong saving the png')
fs.Close()
fs.Close()
print('imageType found')
for i in ims:
if(i.GetType() == DB.ImageType):
#print image name
print(i.LookupParameter('Type Name')).AsString()
bmp = i.GetImage()
path = 'C:/TEMP/'+ i.LookupParameter('Type Name').AsString()
# save Rasted image to path
exportbmp(bmp, path)
Any thoughts?
What i've tried:
I tried using 'MakeTransparent()
I tried convering the pixel format from bppRgb to bppArgh using System.Drawing.Graphic
I've noticed that ALL the pixels of the image provided by GetImage() are A=255, R=0; G=0; B=0, not a single exception
Bitmaps and Jpg's without transparancy and color export just fine.