Code Monkey home page Code Monkey logo

Comments (6)

alexzhirkevich avatar alexzhirkevich commented on August 18, 2024

You probably trying to create logo with zero size. Anyway i need a code snippet to reproduce

from custom-qr-generator.

hardikbhalodi avatar hardikbhalodi commented on August 18, 2024

The error from production app.
Here is my code but i could not reproduce it!.


 public QrVectorLogo addLogo(final Context context, final String logoPath){
Drawable drawable = buildDrawableFromPath(context,logoPath);
     
             float size = .16f;
            if (drawable != null) {
                QrVectorLogoShape shape = QrVectorLogoShape.Circle.INSTANCE;

           QrVectorLogo.Builder builder =
                        new QrVectorLogo.Builder().size(size).drawable(drawable).shape(shape);
                builder.setBackgroundColor(getQRVectorColor(Color.parseColor("#FFFFFF")));
                return builder.build();
            }
            return new QrVectorLogo.Builder().build();
   }

from custom-qr-generator.

hardikbhalodi avatar hardikbhalodi commented on August 18, 2024

Again got the same issue in following models

Android 13
Model: Galaxy F62

Android 12
Model: Galaxy M21, Moto G31

Android 11
Model: Galaxy A30s, Redmi Note 10T 5G

Library version:
'com.github.alexzhirkevich:custom-qr-generator:1.6.2'

Code Snippet

 public QrVectorLogo addLogo(final Context context, final String logoPath){
Drawable drawable = buildDrawableFromPath(context,logoPath);
     
             float size = .16f;
            if (drawable != null) {
                QrVectorLogoShape shape = QrVectorLogoShape.Circle.INSTANCE;

           QrVectorLogo.Builder builder =
                        new QrVectorLogo.Builder().size(size).drawable(drawable).shape(shape);
                builder.setBackgroundColor(getQRVectorColor(Color.parseColor("#FFFFFF")));
                return builder.build();
            }
            return new QrVectorLogo.Builder().build();
   }

Exception caught

Fatal Exception: java.lang.IllegalArgumentException: width and height must be > 0
at android.graphics.Bitmap.createBitmap(Bitmap.java:1118)
at android.graphics.Bitmap.createBitmap(Bitmap.java:1085)
at android.graphics.Bitmap.createBitmap(Bitmap.java:1035)
at android.graphics.Bitmap.createBitmap(Bitmap.java:996)
at androidx.core.graphics.drawable.DrawableKt.toBitmap(Drawable.kt:68) <=== Seems problem is here
at com.github.alexzhirkevich.customqrgenerator.style.BitmapScale$FitXY.scale(BitmapScale.java:24)
at com.github.alexzhirkevich.customqrgenerator.vector.QrCodeDrawableImpl.createLogo(QrCodeDrawable.kt:522)
at com.github.alexzhirkevich.customqrgenerator.vector.QrCodeDrawableImpl.resize(QrCodeDrawable.kt:734)
at com.github.alexzhirkevich.customqrgenerator.vector.QrCodeDrawableImpl.setBounds(QrCodeDrawable.kt:159)

from custom-qr-generator.

hardikbhalodi avatar hardikbhalodi commented on August 18, 2024

val logoSize = size * options.logo.size <== **here logoSize can be 0?**

    val logoBgSize = (logoSize * (1 + options.logo.padding.value)).roundToInt()
    if (options.logo.padding is QrVectorLogoPadding.Natural) {
        applyNaturalLogo(logoBgSize, size, pixelSize)
    }

    val logoBackgroundPath =
        options.logo.shape.createPath(logoBgSize.toFloat(), Neighbors.Empty)

    val logoPaint = when {
        options.logo.padding is QrVectorLogoPadding.Empty -> null
        options.logo.backgroundColor is QrVectorColor.Unspecified -> options.background.color
        else -> options.logo.backgroundColor
    }?.createPaint(logoBgSize.toFloat(), logoBgSize.toFloat())

    createMainElements(pixelSize, framePath, ballPath, darkPixelPath, lightPixelPath, darkTimingPath, lightTimingPath)

    val logo = createLogo(logoSize)  <= and zero size will be passed through this parameter without checking

from custom-qr-generator.

IbrahimSayed94 avatar IbrahimSayed94 commented on August 18, 2024

Put a default size

private const val DEFAULT_SIZE = 400

Because if you're dealing with a Drawable generated dynamically and not from a resource, obtaining intrinsic dimensions might not be straightforward. In such cases, we can use a default size or set a reasonable size for the bitmap if intrinsic dimensions are not available

from custom-qr-generator.

hardikbhalodi avatar hardikbhalodi commented on August 18, 2024

Yes but that code from SDK, so @alexzhirkevich can fix it.

This is my code

 public QrVectorLogo addLogo(final Context context, final String logoPath){
Drawable drawable = buildDrawableFromPath(context,logoPath);
     
             float size = .16f; <= Giving size for logo
            if (drawable != null) {
                QrVectorLogoShape shape = QrVectorLogoShape.Circle.INSTANCE;

           QrVectorLogo.Builder builder =
                        new QrVectorLogo.Builder().size(size).drawable(drawable).shape(shape);
                builder.setBackgroundColor(getQRVectorColor(Color.parseColor("#FFFFFF")));
                return builder.build();
            }
            return new QrVectorLogo.Builder().build();
   }

from custom-qr-generator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.