i think read of answers on regarding bitmaps , memory problems, couldn't find solution problem:
i creating 4 solid background bitmaps , draw text on them (see code below) using bitmap.createbitmap. problem on devices low memory, outofmemoryexception, bitmaps take more 30mb on heap. think pretty solid color , text. recycle bitmaps when not needed more need have 4 of them in memory.
my question: there way reduce memory consumption of these bitmaps?
tried reducing width , height in createbitmap, text size not right more. tried compressing image after creating it:
bytearrayoutputstream out = new bytearrayoutputstream(); bitmap.compress(bitmap.compressformat.jpeg, 0, out); bitmap decoded = bitmapfactory.decodestream(new bytearrayinputstream(out.tobytearray()));
but not decrease heap size @ all.
bitmap bitmap = bitmap.createbitmap(width, height, bitmap.config.argb_8888); bitmap.erasecolor(mcolor); canvas canvas = new canvas(bitmap); textpaint paint = new textpaint(); canvas.drawbitmap(bitmap, 0, 0, paint); paint.setantialias(true); paint.setxfermode(new porterduffxfermode(porterduff.mode.clear)); paint.settextalign(paint.align.center); paint.settypeface(fontmanager.gettypefacegeogrotesquemedium()); float fontsize = typedvalue.applydimension(typedvalue.complex_unit_dip, 55, getresources().getdisplaymetrics()); float fontsizereason = typedvalue.applydimension(typedvalue.complex_unit_dip, 20, getresources().getdisplaymetrics()); paint.settextsize(fontsize); int margin = (int) typedvalue.applydimension(typedvalue.complex_unit_dip, 100, getresources().getdisplaymetrics()); int distance = (int) typedvalue.applydimension(typedvalue.complex_unit_dip, 20, getresources().getdisplaymetrics()); float xpos = canvas.getwidth() / 2; float ypos = (canvas.getheight() - distance) / 2; canvas.drawtext((string) textutils.ellipsize(mtext, paint, canvas.getwidth() - margin, textutils.truncateat.end), xpos, ypos, paint); ypos -= paint.ascent() + paint.descent(); ypos += distance; paint.settypeface(fontmanager.gettypefacegeogrotesqueregular()); canvas.drawtext((string) textutils.ellipsize(mothertext, paint, canvas.getwidth() - margin, textutils.truncateat.end), xpos, ypos, paint);
Comments
Post a Comment