lukas
lukas

Reputation: 495

Add logo to jpeg in Android

I want to add a business logo from a company to jpeg files [photos] in Android. I tried it several times to convert the photos into bitmaps and add then add the logo, it resulted in OutOfMemoryError.

EDIT: it works now, but take realy much time and memory... my code is that:

Bitmap logo = BitmapFactory.decodeResource(
            mainActivity.getResources(), R.drawable.logo);
    Bitmap photo =BitmapFactory.decodeByteArray(jpeg[0], 0, jpeg[0].length);

    Bitmap combination = Bitmap.createBitmap(photo.getWidth(), photo.getHeight(), Bitmap.Config.RGB_565);

    Canvas comboImage = new Canvas(combination); 

    comboImage.drawBitmap(photo, 0f, 0f, null); 
    comboImage.drawBitmap(logo, 0f, 200, null); 



    try {
        FileOutputStream out = new FileOutputStream(mediaFile);
        combination.compress(Bitmap.CompressFormat.PNG, 100, out);
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

Output from Logcat:

01-29 15:40:44.154: I/dalvikvm-heap(5065): Grow heap (frag case) to 109.067MB for 25560592-byte allocation


01-29 15:40:44.184: I/Choreographer(5065): Skipped 36 frames!  The application may be doing too much work on its main thread.

What do you suggest?

Thanks a lot. Lukas

Upvotes: 1

Views: 383

Answers (1)

lukas
lukas

Reputation: 495

If someone has the same problems, i suggest to read this, with its five Lessons Displaying Bitmaps Efficiently - Android Developers

Thanks all for help!

Upvotes: 1

Related Questions