bitmapfactory

Out of memory error in BitmapFactory

不羁岁月 提交于 2019-12-07 18:26:13
问题 Today I got my app crashed, Out of memory error. java.lang.OutOfMemoryError in android.graphics.BitmapFactory.nativeDecodeAsset I only used Bitmap Factory to make a backgroud to my action bar The code: BitmapDrawable background = new BitmapDrawable (BitmapFactory.decodeResource(getResources(), R.drawable.actionbar)); background.setTileModeX(android.graphics.Shader.TileMode.REPEAT); actionbar.setBackgroundDrawable(background); This error doesn't happend on activity start, it happens after

Android: Convert image object to bitmap does not work

a 夏天 提交于 2019-12-07 14:52:49
问题 I am trying to convert image object to bitmap, but it return null. image = reader.acquireLatestImage(); ByteBuffer buffer = image.getPlanes()[0].getBuffer(); byte[] bytes = new byte[buffer.capacity()]; Bitmap myBitmap = BitmapFactory.decodeByteArray(bytes,0,bytes.length,null); The image itself is jpeg image, I can save it to the disk fine, the reason I want to convert to bitmap is because I want to do final rotation before saving it to the disk. Digging in the Class BitmapFactory I see this

BitmapFactory.decodeResource Bitmap not original size in pixels

柔情痞子 提交于 2019-12-07 13:33:55
问题 I have this code that crop a portion of a image sheet. The problem is when I use BitmapFactory.decodeResource and when log the width and height, the size is not the same as the original. Bitmap spriteSheet = BitmapFactory.decodeResource(context.getResources(), R.drawable.imageSheet); Log.i("Sprite Sheet Size",spriteSheet.getWidth()+"w "+spriteSheet.getHeight()+"h"); This is the log 1536w 330h but the original size of the drawable(png) is 1024x220 How do decode my resources to bitmap in their

inDither = true Android

心已入冬 提交于 2019-12-07 07:35:13
问题 Could someone explain what is really happening when setting inDither = true in the context of configarating a bitmap in Android? At Developer.Android one can read about the static variable Config.RGB_565 This configuration can produce slight visual artifacts depending on the configuration of the source. For instance, without dithering, the result might show a greenish tint. To get better results dithering should be applied I had this problem until I followed this recommendation, that is:

BitmapFactory.Options详解

ε祈祈猫儿з 提交于 2019-12-06 23:52:26
public Bitmap inBitmap If set, decode methods that take the Options object will attempt to reuse this bitmap when loading content. public int inDensity The pixel density to use for the bitmap. public boolean inDither If dither is true, the decoder will attempt to dither the decoded image. public boolean inInputShareable This field works in conjuction with inPurgeable. public boolean inJustDecodeBounds If set to true, the decoder will return null (no bitmap), but the out… public boolean inMutable If set, decode methods will always return a mutable Bitmap instead of an immutable one. public

BitmapFactory.decodeResource() does not get my image from drawable

做~自己de王妃 提交于 2019-12-06 11:53:14
I want to get image in my bitmap like this : bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.bug); but this show me error on R.drawable.bug that bug can not be resolve or is not a field please tell where I'm doing things wrong. Do you have a bug graphic file present in the drawable folder? Have you tried to clean your project in order for R.drawable to be correctly generated? Try this: InputStream is = getResources().openRawResource(R.drawable.bug); Bitmap pisc = BitmapFactory.decodeStream(new BufferedInputStream(is)); Just copy Your Drawable in all the drawable folders in

Android decode Bitmap from Camera Preview

怎甘沉沦 提交于 2019-12-06 07:29:39
I am trying to get a Bitmap Image from Camera Preview on which I am going to do some processing and draw some overlays after performing Face detection. After looking around, I found out that the byte array that onPreviewFrame takes cannot be decoded into a bitmap directly, it needs to be converted to the correct pixel format using YuvImage, and that's exactly what I did: @Override public void onPreviewFrame(byte[] data, Camera camera) { YuvImage temp = new YuvImage(data, camera.getParameters().getPreviewFormat(), camera.getParameters().getPictureSize().width, camera.getParameters()

Cannot load image from a Url using BitmapFactory.decodeStream()

我是研究僧i 提交于 2019-12-06 06:06:50
I am trying to download an image from a URL to display as an ImageView. The download is done in the background using AsyncTask. However, the call to the decodeStream of the BitmapFactory always returns a null object. I verified that the Url provided for the connection is right, but it seems that BitmapFactory cannot read the image from the InputStream returned by the HTTP connection. Here is the code below: @Override protected Bitmap doInBackground(String... uri) { Bitmap bm = null; HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(Uri.encode(uri[0])); try {

Out of memory error in BitmapFactory

不问归期 提交于 2019-12-06 05:35:13
Today I got my app crashed, Out of memory error. java.lang.OutOfMemoryError in android.graphics.BitmapFactory.nativeDecodeAsset I only used Bitmap Factory to make a backgroud to my action bar The code: BitmapDrawable background = new BitmapDrawable (BitmapFactory.decodeResource(getResources(), R.drawable.actionbar)); background.setTileModeX(android.graphics.Shader.TileMode.REPEAT); actionbar.setBackgroundDrawable(background); This error doesn't happend on activity start, it happens after changing in activites a lot. Can someone show me how to fix this EDIT EDIT EDIT Here is the error message

Android: Convert image object to bitmap does not work

99封情书 提交于 2019-12-06 01:34:00
I am trying to convert image object to bitmap, but it return null. image = reader.acquireLatestImage(); ByteBuffer buffer = image.getPlanes()[0].getBuffer(); byte[] bytes = new byte[buffer.capacity()]; Bitmap myBitmap = BitmapFactory.decodeByteArray(bytes,0,bytes.length,null); The image itself is jpeg image, I can save it to the disk fine, the reason I want to convert to bitmap is because I want to do final rotation before saving it to the disk. Digging in the Class BitmapFactory I see this line. bm = nativeDecodeByteArray(data, offset, length, opts); This line return null. Further Digging