Comments (2)
At the moment that is not supported,
from avatarimagegenerator.
I have modified the avatarImageGenerate() function to display gradient background and it is working fine.
Hope this helps @kalpeshat20
private fun avatarImageGenerate(context: Context, size: Int, shape: Int, name: String, colorStr: String): BitmapDrawable {
uiContext = context
texSize = calTextSize(size)
val label = firstCharacter(name)
val textPaint = textPainter()
val painter = painter()
painter.isAntiAlias = true
val areaRect = Rect(0, 0, size, size)
if (shape == 0) {
val firstLetter = firstCharacter(name)
// val r = firstLetter[0]
//Random rnd = new Random();
//int color = generateRandomColor();// Color.argb(255, rnd.nextInt(100), rnd.nextInt(150), rnd.nextInt(256));
val color = if (!colorStr.isNullOrEmpty()) Color.parseColor(colorStr) else RandomColors().getColor()
painter.color = color
painter.shader = LinearGradient(size.toFloat() / 3, size.toFloat() / 4, 0F, size.toFloat(), color, Color.WHITE, Shader.TileMode.CLAMP)
} else {
painter.color = Color.TRANSPARENT
}
val bitmap = Bitmap.createBitmap(size, size, ARGB_8888)
val canvas = Canvas(bitmap)
canvas.drawRect(areaRect, painter)
//reset painter
if (shape == 0) {
painter.color = Color.TRANSPARENT
} else {
val firstLetter = firstCharacter(name)
val color = if (!colorStr.isNullOrEmpty()) Color.parseColor(colorStr) else RandomColors().getColor()
painter.color = color;
painter.shader = LinearGradient(size.toFloat() / 3, size.toFloat() / 4, 0F, size.toFloat(), color, Color.WHITE, Shader.TileMode.CLAMP);
}
val stringWidth = textPaint.measureText(label);
val xPosition = (canvas.clipBounds.width() / 2f) - (stringWidth / 2f);
val yPosition = (canvas.clipBounds.height() / 2f) - ((textPaint.ascent() + textPaint.descent()) / 2f);
canvas.drawCircle(size.toFloat() / 2, size.toFloat() / 2, size.toFloat() / 2, painter);
canvas.drawText(label, xPosition, yPosition, textPaint);
return BitmapDrawable(uiContext.resources, bitmap)
}
from avatarimagegenerator.
Related Issues (11)
- please add license HOT 1
- Can i add padding inside the circular generator? HOT 2
- notification HOT 3
- can not resolve method 'avatarImage' in 'AvatarGenerator' HOT 1
- Could not find com.first.avatargenerator:AvatarImageGenerator:1.5.0 HOT 1
- Moving to mavenCentral() HOT 1
- Gradle doesn't recognize v1.5.0 when I upgrade from v1.4 HOT 1
- Add support for Coil image loader HOT 1
- Memory Leak.
- Unable to resolve error ?? HOT 1
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 avatarimagegenerator.