
from libavg import app, avg
from PIL import Image

# Demonstrates interoperability with pillow (https://pillow.readthedocs.org/index.html)

class MyMainDiv(app.MainDiv):
    def onInit(self):
        self.toggleTouchVisualization()
        srcbmp = avg.Bitmap("rgb24-64x64.png")
        pixels = srcbmp.getPixels(False)
        image = Image.frombytes("RGBA", (64,64), pixels)
        # Need to swap red and blue.
        b,g,r,a = image.split()
        image = Image.merge("RGBA", (r,g,b,a))

        image.save("foo.jpg")

        destbmp = avg.Bitmap((64,64), avg.B8G8R8A8, "")
        destbmp.setPixels(image.tobytes())
        node = avg.ImageNode(parent=self)
        node.setBitmap(destbmp)

    def onExit(self):
        pass

    def onFrame(self):
        pass

app.App().run(MyMainDiv())




from libavg import app, avg
from PIL import Image

# Demonstrates interoperability with pillow (https://pillow.readthedocs.io)

class MyMainDiv(app.MainDiv):
    def onInit(self):
        self.toggleTouchVisualization()
        srcbmp = avg.Bitmap("rgb24-64x64.png")
        pixels = srcbmp.getPixels(False)
        image = Image.frombytes("RGBA", (64,64), pixels)
        # Need to swap red and blue.
        b,g,r,a = image.split()
        image = Image.merge("RGBA", (r,g,b,a))

        image.save("foo.png")

        destbmp = avg.Bitmap((64,64), avg.B8G8R8A8, "")
        destbmp.setPixels(image.tobytes())
        node = avg.ImageNode(parent=self)
        node.setBitmap(destbmp)

    def onExit(self):
        pass

    def onFrame(self):
        pass

app.App().run(MyMainDiv())



Update link in the comment and change saved image format to .png
Update link in the comment and change saved image format to .png

  
  from libavg import app, avg
  from PIL import Image
  
- # Demonstrates interoperability with pillow (https://pillow.readthedocs.org/index.html)
+ # Demonstrates interoperability with pillow (https://pillow.readthedocs.io)
  
  class MyMainDiv(app.MainDiv):
      def onInit(self):
          self.toggleTouchVisualization()
          srcbmp = avg.Bitmap("rgb24-64x64.png")
          pixels = srcbmp.getPixels(False)
          image = Image.frombytes("RGBA", (64,64), pixels)
          # Need to swap red and blue.
          b,g,r,a = image.split()
          image = Image.merge("RGBA", (r,g,b,a))
  
-         image.save("foo.jpg")
+         image.save("foo.png")
  
          destbmp = avg.Bitmap((64,64), avg.B8G8R8A8, "")
          destbmp.setPixels(image.tobytes())
          node = avg.ImageNode(parent=self)
          node.setBitmap(destbmp)
  
      def onExit(self):
          pass
  
      def onFrame(self):
          pass
  
  app.App().run(MyMainDiv())
  
  
  
Update link in the comment and change saved image format to .png
## Code Before:

from libavg import app, avg
from PIL import Image

# Demonstrates interoperability with pillow (https://pillow.readthedocs.org/index.html)

class MyMainDiv(app.MainDiv):
    def onInit(self):
        self.toggleTouchVisualization()
        srcbmp = avg.Bitmap("rgb24-64x64.png")
        pixels = srcbmp.getPixels(False)
        image = Image.frombytes("RGBA", (64,64), pixels)
        # Need to swap red and blue.
        b,g,r,a = image.split()
        image = Image.merge("RGBA", (r,g,b,a))

        image.save("foo.jpg")

        destbmp = avg.Bitmap((64,64), avg.B8G8R8A8, "")
        destbmp.setPixels(image.tobytes())
        node = avg.ImageNode(parent=self)
        node.setBitmap(destbmp)

    def onExit(self):
        pass

    def onFrame(self):
        pass

app.App().run(MyMainDiv())



## Instruction:
Update link in the comment and change saved image format to .png
## Code After:

from libavg import app, avg
from PIL import Image

# Demonstrates interoperability with pillow (https://pillow.readthedocs.io)

class MyMainDiv(app.MainDiv):
    def onInit(self):
        self.toggleTouchVisualization()
        srcbmp = avg.Bitmap("rgb24-64x64.png")
        pixels = srcbmp.getPixels(False)
        image = Image.frombytes("RGBA", (64,64), pixels)
        # Need to swap red and blue.
        b,g,r,a = image.split()
        image = Image.merge("RGBA", (r,g,b,a))

        image.save("foo.png")

        destbmp = avg.Bitmap((64,64), avg.B8G8R8A8, "")
        destbmp.setPixels(image.tobytes())
        node = avg.ImageNode(parent=self)
        node.setBitmap(destbmp)

    def onExit(self):
        pass

    def onFrame(self):
        pass

app.App().run(MyMainDiv())


