On 19/11/2016 at 11:13, xxxxxxxx wrote:
Hi I would like to import tiff with alpha into a Geclip and still got this alpha but I didn't sucess.
Thanks in advance here is a little code for testing.
def main() :
path = "C:\\Program Files\\MAXON\\CINEMA 4D R17\\plugins\\MyPlugin\\res\\add2.tif"
#On init un bitmap ave l'image
temp = c4d.bitmaps.BaseBitmap()
if temp.InitWith(path) != c4d.IMAGERESULT_OK:
size = temp.GetBw()
alpha = temp.GetInternalChannel()
cm = c4d.bitmaps.GeClipMap()
#Some test for rewritting alpha
for y in xrange(size) :
for x in xrange(size) :
a = temp.GetAlphaPixel(alpha,x,y)
r,g,b = temp.GetPixel(x,y)
cm.SetPixelRGBA(x, y, r, g, b,a)
#draw a square
cm.SetColor(150, 150, 150, 150)
size_pic = cm.GetBw()
height_pic = cm.GetBh()
cm.FillRect(0, height_pic - (size/6), size_pic,height_pic )
bmp = cm.GetBitmap().GetClone()
On 21/11/2016 at 03:00, xxxxxxxx wrote:
the BaseBitmap returned by GetBitmap() does not include the alpha channel (see documentation). Also the Picture Viewer would not display the alpha channel.
So as far as I can see you have to copy the alpha channel manually.
# clone bitmap
bitmap = clipMap.GetBitmap().GetClone()
# add alpha channel
alphaChannel = bitmap.AddChannel(True, False)
# copy alpha
for x in xrange(clipMapWidth) :
for y in xrange(clipMapHeight) :
r,g,b,a = clipMap.GetPixelRGBA(x,y)
bitmap.SetAlphaPixel(alphaChannel, x, y, a)
# save bitmap with alpha
saveImageFile = c4d.storage.SaveDialog(type=c4d.FILESELECTTYPE_IMAGES,title="Save as PNG")
if saveImageFile is not None:
bitmap.Save(name = saveImageFile,format = c4d.FILTER_PNG,data = None, savebits =c4d.SAVEBIT_ALPHA)
On 21/11/2016 at 05:35, xxxxxxxx wrote:
Thanks you was a missunderstand from me.
I thinked alpha was not copied into the GeClip.
Anyway thanks you now all is working as excepted !