Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    GeClipMap alpha [SOLVED]

    Scheduled Pinned Locked Moved PYTHON Development
    3 Posts 0 Posters 357 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

      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.

      import c4d
        
      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)[0] != c4d.IMAGERESULT_OK:
                  return False
              
              size = temp.GetBw()
              alpha = temp.GetInternalChannel()
        
              #Initialize GeClipMap
              cm = c4d.bitmaps.GeClipMap()
              cm.InitWithBitmap(temp,alpha)
              cm.BeginDraw()
        
      	#Some test for rewritting alpha
              if 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.SetDrawMode(c4d.GE_CM_DRAWMODE_BLEND, 255)
              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 )
              
              cm.EndDraw()
              
              #Get bitmap
              bmp = cm.GetBitmap().GetClone()
              cm.Destroy()
        
              c4d.bitmaps.ShowBitmap(bmp)
        
      if __name__=='__main__':
          main()
      
      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        On 21/11/2016 at 03:00, xxxxxxxx wrote:

        Hello,

        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  
          
        clipMap.BeginDraw()  
          
        for x in xrange(clipMapWidth) :  
          for y in xrange(clipMapHeight) :  
                
              r,g,b,a = clipMap.GetPixelRGBA(x,y)  
              bitmap.SetAlphaPixel(alphaChannel, x, y, a)  
                
        clipMap.EndDraw()  
                
        # 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)   
        

        best wishes,
        Sebasitan

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          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 ! 🙂

          1 Reply Last reply Reply Quote 0
          • First post
            Last post