Comments (6)
You probably trying to create logo with zero size. Anyway i need a code snippet to reproduce
from custom-qr-generator.
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.
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.
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.
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.
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)
- Documentation unclear about features HOT 7
- Add QrVectorPixelShape.Square(size) shape modifier HOT 3
- How to use your library draw QR codes with 3 vertices and circles? Looking forward to your reply HOT 5
- Support the different standard encodings HOT 7
- Expose reserved areas HOT 15
- Customizing QR code after generation HOT 4
- Is the size of the positioning markings adjustable? HOT 4
- How to remove icon and background after choose them HOT 2
- How to custom gradient color and select background, logo from devices HOT 6
- Highlight anchor elements for better recognition seems break in Library version 2.0.0-alpha01 HOT 8
- add jetpack compose support to the library HOT 5
- Any Java samples? HOT 3
- Generated QR not scan-able HOT 6
- I run the app module of this project, and input "123" ,but it can't be scanned by other qr scanner. HOT 4
- [BUG] Documentation and Source Code is not published
- Publish apks on GitHub HOT 2
- [BUG] The code in example is invalid
- overlay image on qrCode HOT 8
- Change background and dots
- Help Implementing HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from custom-qr-generator.