search

Home  >  Q&A  >  body text

android - ColorDrawable不能强转BitmapDrawable???

ringa_leeringa_lee2772 days ago574

reply all(3)I'll reply

  • 天蓬老师

    天蓬老师2017-04-17 15:48:43


    The inheritance relationship is as above

    Directly inherit the same parent class and cannot be forced

    can be generated using the constructor of CanvasColorDrawable转成Bitmap,用 BitmapDrawable

    public BitmapDrawable (Bitmap bitmap)

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 15:48:43

    Can’t.

    This is not an Android problem, Java does not allow you to cast an object to an incompatible class

    reply
    0
  • 天蓬老师

    天蓬老师2017-04-17 15:48:43

    Refer to Java class object type conversion knowledge, ColorDrawable and BitmapDrawable are in a horizontal relationship, and there is no possibility of forced conversion to each other. The class object conversion mechanism exists between class objects with a parent-child relationship. When forced conversion, only the parent class object can be forced to be converted into a child class object.

    reply
    0
  • Cancelreply