Android Question QRGenerator: How to reduce the embedded image size


Well-Known Member
Licensed User
Longtime User
I use the library and example located here

I want to have an image appear at the center of generated QR code. The size of the image is about 1/4~1/5 of the QR code image size. For example I want to make the following logo image further smaller.


I tried the following code to make the logo's size is 1/5 of QR code image size and it didn't work. Obviously I did something wrong. Highlighted code are modified.

Could someone show what I did incorrectly, please?

Sub AddSomeColors(QRBmp As B4XBitmap, logo As B4XBitmap) As B4XBitmap
    Dim bc As BitmapCreator
    bc.Initialize(QRBmp.Width, QRBmp.Height)
    Dim LogoBC As BitmapCreator
    LogoBC.Initialize(QRBmp.Width/5, QRBmp.Height/5)
    Dim argb, largb As ARGBColor
    For x = 0 To bc.mWidth - 1
        For y = 0 To bc.mHeight - 1
            bc.GetARGB(x, y, argb)
            LogoBC.GetARGB(x/5, y/5, largb) 'this line caused error: java.lang.ArrayIndexOutOfBoundsException: length=37636; index=37639
            If largb.a > 0 Then
                largb.a = 200
                LogoBC.SetARGB(x/5, y/5, largb)
                bc.BlendPixel(LogoBC, x/5, y/5, x, y)
            End If
    Return bc.Bitmap
End Sub