Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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

    GeUserArea.DrawBitmap() issue

    PYTHON Development
    0
    4
    796
    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
      Helper
      last edited by

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 25/11/2011 at 09:34, xxxxxxxx wrote:

      Hi, I have problems when drawing alpha-containing Bitmaps onto a GeUserArea.

      The following code will open a Dialog that displays a bitmap with alpha values. Set SHOW_ISSUE to True and you will see what exactly is the problem. GeUserArea.DrawSetPen() seems to fill the background of the bitmap, but why ? I just can't figure out how to avoid this.

      Can you think of possible reasons why this is happening ? Or is it a bug ?
      Thank you.

      import c4d  
      import c4d.gui     as gui  
      import c4d.bitmaps as bitmaps  
        
      SHOW_ISSUE = False  
        
      class Area(gui.GeUserArea) :  
          
        def __init__(self, w = 20, h = 20, r = 1, g = 1, b = 1) :  
            self.bmp = bitmaps.BaseBitmap()  
            self.bmp.Init(w, h)  
            self.w   = w  
            self.h   = h  
              
            self.alpha = self.bmp.AddChannel(True, False)  
              
            r = int(r * 255)  
            g = int(g * 255)  
            b = int(b * 255)  
        
            for x in xrange(w) :  
                for y in xrange(h) :  
                    a = x*y / float(w*h)  
                    a = 1 - 2**a  
                    a = int(a * 255)  
                    self.bmp[x, y] = r, g, b  
                    self.bmp.SetAlphaPixel(self.alpha, x, y, a)  
                      
        def DrawMsg(self, x1, y1, x2, y2, msg) :  
            self.DrawSetPen(c4d.Vector(0, 0, 0))  
            self.DrawRectangle(x1, y1, x2, y2)  
              
            if SHOW_ISSUE:  
                self.DrawSetPen(c4d.Vector(.2, .6, .9))  
              
            w, h = self.w, self.h  
            self.DrawBitmap(self.bmp,  
                0, 0, w, h, 0, 0, w, h, c4d.BMP_NORMAL | c4d.BMP_ALLOWALPHA)  
                  
        def GetMinSize(self) :  
            return self.w, self.h  
              
      class Dialog(gui.GeDialog) :  
          
        def __init__(self, area) :  
            self.area = area  
          
        def CreateLayout(self) :  
            self.AddUserArea(1000, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT)  
            self.AttachUserArea(self.area, 1000)  
            return True  
          
      def main() :  
        area = Area(100, 100, 1.0, 0.66, 0.24)  
        dlg  = Dialog(area)  
        
        if c4d.GetC4DVersion() < 13000:  
            dlg.Open(c4d.DLG_TYPE_MODAL_RESIZEABLE)  
        else:  
            dlg.Open(c4d.DLG_TYPE_ASYNC)  
          
      if __name__ == "__main__":  
        main()
      
      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 27/11/2011 at 06:07, xxxxxxxx wrote:

        Does no one know about it ?

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

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 28/11/2011 at 13:08, xxxxxxxx wrote:

          Hi, this is intended. An alternative is the GeClipMap class. With this class you can construct the entire image which can then be drawn to the interface. This class can handle the requirements of your example.
          Btw, scripts should better not be used in asynchronous dialogs.

          Cheers, Sebastian

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

            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

            On 01/12/2011 at 09:59, xxxxxxxx wrote:

            Thank you for taking your time, Sebastian.
            But unfortunately, I still can't get it right.
            May you show me an example of how to use alpha-bitmaps / GeClipMap s on a GeUserArea ?

            I have modified the code above to use a GeClipMap, but I get the same result.

            import c4d  
            import c4d.gui     as gui  
            import c4d.bitmaps as bitmaps  
              
            SHOW_ISSUE = False  
              
            class Area(gui.GeUserArea) :  
                
              def __init__(self, w = 20, h = 20, r = 1, g = 1, b = 1) :  
                  self.bmp = bitmaps.GeClipMap()  
                  self.bmp.Init(w, h)  
                  self.bmp.BeginDraw()  
                  self.w   = w  
                  self.h   = h  
                    
                  r = int(r * 255)  
                  g = int(g * 255)  
                  b = int(b * 255)  
              
                  for x in xrange(w) :  
                      for y in xrange(h) :  
                          a = (x * 4 / float(w))**(y / float(h))  
                          try:  
                              a = 1 / (x**2 / float(w)**2) * a  
                          except:  
                              a = 0  
                          a = int(a * 255)  
                          self.bmp.SetPixelRGBA(x, y, r, g, b, a)  
                            
                  self.bmp.EndDraw()  
                            
              def DrawMsg(self, x1, y1, x2, y2, msg) :  
                  self.DrawSetPen(c4d.Vector(0, 0, 0))  
                  self.DrawRectangle(x1, y1, x2, y2)  
                    
                  if SHOW_ISSUE:  
                      self.DrawSetPen(c4d.Vector(.2, .6, .9))  
                    
                  w, h = self.w, self.h  
                  self.DrawBitmap(self.bmp.GetBitmap(),  
                      0, 0, w, h, 0, 0, w, h, c4d.BMP_NORMAL | c4d.BMP_ALLOWALPHA)  
                        
              def GetMinSize(self) :  
                  return self.w, self.h  
                    
            class Dialog(gui.GeDialog) :  
                
              def __init__(self, area) :  
                  self.area = area  
                
              def CreateLayout(self) :  
                  self.AddUserArea(1000, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT)  
                  self.AttachUserArea(self.area, 1000)  
                  return True  
                
            def main() :  
              area = Area(100, 100, 1.0, 0.66, 0.24)  
              dlg  = Dialog(area)  
              
              if c4d.GetC4DVersion() < 13000:  
                  dlg.Open(c4d.DLG_TYPE_MODAL_RESIZEABLE)  
              else:  
                  dlg.Open(c4d.DLG_TYPE_ASYNC)  
                
            if __name__ == "__main__":  
              main()
            

            Btw, I don't know if you already noticed, there are some new threads in the Bugs-section. For instance mines 😂 [ Script manager R13 bug, GeUserArea disappears in async dialog]

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