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()