Bitmap gets mangled if pluggin moved around

On 18/06/2014 at 14:56, xxxxxxxx wrote:

I'm drawing a bitmap to a user-area, but the image can get messed up if the dialogue window is dragged partially offscreen.  See pic: image
Hmm....the picture doesn't display below.  Can't you post images to this forum?

I can use re-draw to clean-up the image, but I can't find any system messages inside C4D that occur because a dialogue window is dragged around that I can use to trigger the re-draw.

Anyone know how to avoid this problem?

Thanks

Edit by NiklasR: Fixed image display, Edit 2 by NiklasR: Ok strange, it displayed in the WYSIWYG editor 😉

On 19/06/2014 at 08:11, xxxxxxxx wrote:

Hi terrachild,

can you please show the code you use to draw the bitmap?

-Niklas

On 19/06/2014 at 13:40, xxxxxxxx wrote:

Here is the draw function:

           
    def DrawMsg(self, x1, y1, x2, y2, msg) :
          w, h    = self._bmp.GetSize()
          destination = w, h
             
          drawType = c4d.BMP_NORMAL
          self._bmp = camera_image_1
               
          self.DrawBitmap(
          self._bmp,
          x1, y1, destination[0], destination[1],
          0, 0, w, h, c4d.BMP_NORMAL | c4d.BMP_ALLOWALPHA
          )
  

Also, I haven't been able to get an image drawn (.png) that displays the alpha.
Is there a trick to getting transparency to work properly?

Thanks

On 19/06/2014 at 19:17, xxxxxxxx wrote:

I can not reproduce this. What I tried:

import c4d
  
class UserArea(c4d.gui.GeUserArea) :
    
    def __init__(self, bmp) :
        super(UserArea, self).__init__()
        self.bmp = bmp
    
    def DrawMsg(self, x1, y1, x2, y2, msg) :
        self.SetClippingRegion(x1, y1, x2, y2)
        if not self.bmp:
            self.SetPen(c4d.COLOR_BG)
            self.DrawRectangle(x1, y1, x2, y2)
            return
        
        w, h = self.bmp.GetSize()
        self.DrawBitmap(
                self.bmp, x1, y1, w, h, x1, y1, w, h,
                c4d.BMP_NORMAL | c4d.BMP_ALLOWALPHA)
    
class Dialog(c4d.gui.GeDialog) :
    
    def __init__(self) :
        super(Dialog, self).__init__()
        self.ua = UserArea(None)
    
    def CreateLayout(self) :
        self.AddUserArea(1000, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, c4d.BFV_SCALEFIT)
        self.AttachUserArea(self.ua, 1000)
        return True
  
def main() :
    fn = c4d.storage.LoadDialog()
    if not fn:
        return
    dlg = Dialog()
    dlg.ua.bmp = c4d.bitmaps.BaseBitmap()
    dlg.ua.bmp.InitWith(fn)
    dlg.Open(c4d.DLG_TYPE_ASYNC)
    
    # Just make sure the dialog stays alive, nasty hack
    # and should not be done in production.
    c4d.__dlg = dlg
  
if __name__ == "__main__":
    main()

Does this version work for you?
Need to check on the alpha.

-Niklas

On 23/06/2014 at 17:33, xxxxxxxx wrote:

I tried that by running it in the 'Script Manager' and the same thing happens to the image if you drag the dialogue off the edge of your desktop, and then drag it back.  The image gets mangled.

Also, what is this line doing, and why should it be avoided in production?

c4d.__dlg = dlg

On 23/06/2014 at 20:32, xxxxxxxx wrote:

I did get the 'alpha' to work a little bit.

When you draw an image with an 'alpha' channel, it draws with the dialogue color where the transparency is.

But if you try to draw one image with transparency on top of another image with transparency it doesn't work.  The image on top has the dialogue color in the transparent parts not the underlying image.

Anyone ever tried this?