Skip to content

Instantly share code, notes, and snippets.

@KKorvin
KKorvin / Blinker.java
Created June 22, 2017 22:51
libGDX how to make sprite blinking x seconds
public class Blinker {
private float BLINK_TIME = 1f;
private int BLINKING_FRAMES = 4;
private boolean isBlinking;
private int blinkFrameCounter;
private float blinkTimer;
public Blinker() {
this.blinkTimer = 0;
@KKorvin
KKorvin / ScaleBitmapExamples.java
Created August 24, 2016 13:36
Scaling Bitmap on the fly. For Android, including main thread, background thread and Glide examples.
//Scale function:
/**
* Creates new bitmap by scaling given one
*
* @param scaleFactor
* @param bitmap
* @return new bitmap
*/
public static Bitmap createScaledBitmap(Bitmap bitmap, float scaleFactor) {
@KKorvin
KKorvin / LetterBitmap.java
Last active November 8, 2018 07:39
Create multi color squares with letter. For Android.
/**
* Orginal http://stackoverflow.com/questions/23122088/colored-boxed-with-letters-a-la-gmail
* Used to create a {@link Bitmap} that contains a letter used in the English
* alphabet or digit, if there is no letter or digit available, a default image
* is shown instead.
*
* Only English language supported.
*/
public class LetterBitmap {
@KKorvin
KKorvin / PickDominantColor.java
Last active August 3, 2021 16:07
How to pick dominant color from image on Android. Palette Google library used.
// Don't forget to add Palette library to your build.gradle
// compile 'com.android.support:palette-v7:+'
public static int getDominantColor(Bitmap bitmap) {
List<Palette.Swatch> swatchesTemp = Palette.from(bitmap).generate().getSwatches();
List<Palette.Swatch> swatches = new ArrayList<Palette.Swatch>(swatchesTemp);
Collections.sort(swatches, new Comparator<Palette.Swatch>() {
@Override
public int compare(Palette.Swatch swatch1, Palette.Swatch swatch2) {
return swatch2.getPopulation() - swatch1.getPopulation();