bitmapfactory

BitmapFactory.decodeResource Bitmap not original size in pixels

点点圈 提交于 2019-12-05 20:56: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 original sizes. The image is scaled according to the dpi of the device you are using, you can put the

inDither = true Android

ⅰ亾dé卋堺 提交于 2019-12-05 13:12:04
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: options.inPreferredConfig = Config.RGB_565; options.inDither = true; So my question: how do one understand

BitmapFactory.decodeStream from Assets returns null on Android 7

谁都会走 提交于 2019-12-04 13:45:46
问题 How to decode bitmaps from Asset directory in Android 7? My App is running well on Android versions up to Marshmallow. With Android 7 it fails to load images from the Asset directory. My Code: private Bitmap getImage(String imagename) { // Log.dd(logger, "AsyncImageLoader: " + ORDNER_IMAGES + imagename); AssetManager asset = context.getAssets(); InputStream is = null; try { is = asset.open(ORDNER_IMAGES + imagename); } catch (IOException e) { // Log.de(logger, "image konnte nicht gelesen

BitmapFactory: Unable to decode stream: java.io.FileNotFoundException

a 夏天 提交于 2019-12-04 13:10:04
问题 I have a problem concerning the BitMapFactory.decodeFile. In my app, I want to user to be able to select an image from his/her device or take a photograph. This must then be displayed in an ImageView Here is code snippet: Uri selectedImage = data.getData(); String[] filePathColumn = {MediaStore.Images.Media.DATA}; Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null); cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String

Android Bitmap from URL always null

让人想犯罪 __ 提交于 2019-12-04 02:01:50
问题 I'm trying to download an image from a URL and convert it into a bitmap, but the line Bitmap myBitmap = BitmapFactory.decodeStream(input); always causes the debugger to skip to the following line return null; without ever actually printing out the stack trace and the Exception variable also doesn't exist in the variables listed in the Debugger. I read a lot about how there might be issues with urls not actually leading to images, not well formated images and the like but it still has the same

How can I specify the bitmap format (e.g. RGBA_8888) with BitmapFactory.decode*()?

血红的双手。 提交于 2019-12-03 19:52:38
问题 I'm making several calls to BitmapFactory.decodeFile() and BitmapFactory.decodeResource() , and I'd like to specify the format the bitmaps are decoded to, such as RGB_565 or RGBA_8888. Currently, the decoded bitmap format seems to depend on the incoming image. Alternatively, is there a way to convert an existing bitmap to a specific format? The reason this is important is that when I try to decode the image using jnigraphics , some images return an AndroidBitmapFormat of type ANDROID_BITMAP

BitmapFactory.decodeStream from Assets returns null on Android 7

為{幸葍}努か 提交于 2019-12-03 16:12:31
How to decode bitmaps from Asset directory in Android 7? My App is running well on Android versions up to Marshmallow. With Android 7 it fails to load images from the Asset directory. My Code: private Bitmap getImage(String imagename) { // Log.dd(logger, "AsyncImageLoader: " + ORDNER_IMAGES + imagename); AssetManager asset = context.getAssets(); InputStream is = null; try { is = asset.open(ORDNER_IMAGES + imagename); } catch (IOException e) { // Log.de(logger, "image konnte nicht gelesen werden: " + ORDNER_IMAGES + imagename); return null; } // First decode with inJustDecodeBounds=true to

Optimal use of BitmapFactory.Options.inSampleSize for speed

爱⌒轻易说出口 提交于 2019-12-03 14:57:00
问题 Thanks to Schermvlieger for asking this question on anddev.org , I'm just copying his question to SO as nobody replied on the other site and I'm also facing the same problem. I was wondering what would be the optimal use of BitmapFactory.Options.inSampleSize with regards to speed of displaying the image. The documentation mentions using values that are a power of 2, so I am working with 2, 4, 8, 16 etc. The things I am wondering about are: Should I resample down to the smallest size that is

BitmapFactory.Options.inBitmap causes tearing when switching ImageView bitmap often

筅森魡賤 提交于 2019-12-03 11:50:58
问题 I've encountered a situation where I have to display images in a slideshow that switches image very fast. The sheer number of images makes me want to store the JPEG data in memory and decode them when I want to display them. To ease on the Garbage Collector, I'm using BitmapFactory.Options.inBitmap to reuse bitmaps. Unfortunately, this causes rather severe tearing, I've tried different solutions such as synchronization, semaphores, alternating between 2-3 bitmaps, however, none seem to fix

BitmapFactory: Unable to decode stream: java.io.FileNotFoundException

試著忘記壹切 提交于 2019-12-03 08:58:53
I have a problem concerning the BitMapFactory.decodeFile. In my app, I want to user to be able to select an image from his/her device or take a photograph. This must then be displayed in an ImageView Here is code snippet: Uri selectedImage = data.getData(); String[] filePathColumn = {MediaStore.Images.Media.DATA}; Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null); cursor.moveToFirst(); int columnIndex = cursor.getColumnIndex(filePathColumn[0]); String picturePath = cursor.getString(columnIndex); cursor.close(); MyImage image = new MyImage(); image