Giacomo De Bacco
Giacomo De Bacco

Reputation: 723

Android apply custom sticker on image

I'm trying to fuond an image editor library that allow me to put a sticker on an image. I've found two libraries, one is Aviary , but I can't put my own stickers in it, then I've tried Android-image-edit but is very simple and it's not a library, it's an application. Anyone knows some good libraries that allow me to do what I'm trying to do? Thanks in advance.

Upvotes: 3

Views: 6462

Answers (2)

Ali Raza
Ali Raza

Reputation: 3177

I don't know, if anyone's still looking for this, but this library can you in every possible way, to add a sticker.

https://github.com/wuapnjie/StickerView

Upvotes: 0

StefanTo
StefanTo

Reputation: 1020

I don't know a library, but if I understand you right, you want to add one Drawable onto an image?

You can do this yourself: (untested!)

public void putSticker(File file, Bitmap overlay) {
    //Load bitmap from file:
    Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());       
    bitmap = bitmap.copy(Bitmap.Config.RGB_565, true);

    //Draw overlay:
    Canvas canvas = new Canvas(bitmap);
    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG);
    canvas.drawBitmap(overlay, 0, 0, paint);

    //Save to file:
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    bitmap.compress(CompressFormat.PNG, 40, bos);
    byte[] bitmapdata = bos.toByteArray();
    FileOutputStream fos;
    try {
        fos = new FileOutputStream(file);
        fos.write(bitmapdata);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
} 

Maybe there is a better way for loading and saving. But drawing is the interesting part for your question, anyway.

See http://developer.android.com/reference/android/graphics/Canvas.html for more drawBitmap() possibilities. (Offsets, Scaling, ...)

Upvotes: 1

Related Questions