bitmap - Android load resized image from asset -
bitmap - Android load resized image from asset -
i getting memory error in android game , think caused image loading function. working fine on mobile on tablet memory exceed error.
i using matrix because need resize image float value. in case have load image in total size first , resize matrix , think causes memory error.
is right way handle image resize?
public class sprite { private bitmap bitmap = null; private float scalex, scaley; public sprite(string path, float targetwidth, float targetheight, context context) { inputstream istr; assetmanager assetmanager = context.getassets(); matrix scalematrix = new matrix(); seek { istr = assetmanager.open(path); bitmap = bitmapfactory.decodestream(istr); scalex = targetwidth / bitmap.getwidth(); scaley = targetheight / bitmap.getheight(); scalematrix.postscale(scalex, scaley); bitmap = bitmap.createbitmap(bitmap, 0, 0, bitmap.getwidth(), bitmap.getheight(), scalematrix, true); } grab (ioexception e) { e.printstacktrace(); } { } } }
bitmapfactory.options has public int insamplesize
-- if set value > 1, requests decoder subsample original image, returning smaller image save memory.
you may seek utilize bitmapfactory.decodexxx(..., bitmapfactory.options opts)
(decodefile() etc.)
android bitmap resize scale assets
Comments
Post a Comment