bitmapfactory

Saving canvas to bitmap on Android

夙愿已清 提交于 2019-11-27 06:16:11
问题 I'm having some difficulty with regards to placing the contents of a Canvas into a Bitmap. When I attempt to do this, the file gets written with a file size of around 5.80KB but it appears to be completely empty (every pixel is '#000'). The canvas draws a series of interconnected lines that are formed by handwriting. Below is my onDraw for the View. (I'm aware that it's blocking the UI thread / bad practices/ etc.., however I just need to get it working) Thank you. @Override protected void

Is there a way to set actionbar backgound by image in android?

非 Y 不嫁゛ 提交于 2019-11-27 05:48:06
问题 I need to change background of the action bar to a customized image, but every time I try to use this code it does not change a thing. Bitmap b = BitmapFactory.decodeResource(getResources(), R.drawable.navbarbg); BitmapDrawable bd = new BitmapDrawable(getResources(), b); bar.setBackgroundDrawable(bd); Also I tried this code but it didn't work. Resources res = getResources(); xpp =res.getXml(R.drawable.actionbar_background); bitmapDrawable = (BitmapDrawable) BitmapDrawable.createFromXml (res,

Pre-guess size of Bitmap from the actual Uri, before scale-loading

一笑奈何 提交于 2019-11-27 02:46:43
问题 If you have a Uri and you need the Bitmap , you could theoretically do this Bitmap troublinglyLargeBmp = MediaStore.Images.Media.getBitmap( State.mainActivity.getContentResolver(), theUri ); but it will crash every time, so you do this ......... BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 4; AssetFileDescriptor fileDescriptor =null; fileDescriptor = State.mainActivity.getContentResolver().openAssetFileDescriptor( theUri, "r"); Bitmap

Create a Bitmap/Drawable from file path

◇◆丶佛笑我妖孽 提交于 2019-11-27 00:59:46
I'm trying to create a Bitmap or Drawable from existing file path. String path = intent.getStringExtra("FilePath"); BitmapFactory.Options option = new BitmapFactory.Options(); option.inPreferredConfig = Bitmap.Config.ARGB_8888; mImg.setImageBitmap(BitmapFactory.decodeFile(path)); // mImg.setImageBitmap(BitmapFactory.decodeFile(path, option)); // mImg.setImageDrawable(Drawable.createFromPath(path)); mImg.setVisibility(View.VISIBLE); mText.setText(path); But setImageBitmap() , setImageDrawable() doesn't show an image from the path. I've printed path with mText and it looks like : /storage

BitmapFactory.decodeStream(InputStream is) returns null for non null InputStream on Android

一个人想着一个人 提交于 2019-11-26 23:30:29
问题 I'm developing an Android application, and it's view is containing multiple Gallerys. The content of the Gallerys (the Bitmaps) are red from the Internet. For the first gallery, everything works fine, but when trying to download the first image of the second Gallery, the BitmapFactory.decodeStream(InputStream) returns null, while the stream is NOT null. public void loadBitmap() throws IOException { for (int i = 0; i < images.size(); ++i) { URL ulrn = new URL(images.get(i).getThumbUrl());

BitmapFactory.decodeStream returns null without exception

泄露秘密 提交于 2019-11-26 23:16:05
问题 I try to load a remote image from a server and thanks to a lot of code examples on stackoverflow I have a solution which works in 2 out of 3 images. I don't really know what the problem is with the third picture and sometimes when letting the code run in the debugger the picture is loading. Also if I load the problem picture first the other two pictures are sometimes not loaded. Here is the code: public static Drawable getPictureFromURL(Context ctx, String url, final int REQUIRED_SIZE) throws

Displaying images from a specific folder on the SDCard using a gridview

南楼画角 提交于 2019-11-26 18:52:26
I'm attempting to create a gridview that is loaded with images from a specific folder that resides on an SDCard. The path to the folder is known, ("/sdcard/pictures") , but in the examples I've seen online I am unsure how or where to specify the path to the pictures folder I want to load images from. I have read through dozens of tutorials, even the HelloGridView tutorial at developer.android.com but those tutorials do not teach me what i am seeking. Every tutorial I have read so far has either: A) called the images as a Drawable from the /res folder and put them into an array to be loaded,

Why does BitmapFactory.decodeResource scale my image?

限于喜欢 提交于 2019-11-26 17:21:14
问题 I have an image that is 120x120px located in my /res/drawable/ directory. This is the size required for all devices. To load this Bitmap, I am using the following: Bitmap tmpBmp = BitmapFactory.decodeResource(getResources(), R.drawable.myimage); The issue is that when I measure tmpBmp , the size is 360x360px. I know how to scale this back down to the 120x120 that I need, but it is a waste of processing time, although minimal. I am assuming that this has something to do with screen densities,

How can I print an image on a Bluetooth printer in Android?

安稳与你 提交于 2019-11-26 11:13:49
I have to print some data on thermal bluetooth printer, I'm doing with this: String message="abcdef any message 12345"; byte[] send; send = message.getBytes(); mService.write(send); It works well for text, but not for images. I think I need to get the byte[] of the image data. I tried getting the data of the image this way: Bitmap bitmap=BitmapFactory.decodeResource(getResources(), R.drawable.qrcode); ByteArrayOutputStream stream=new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 90, stream); byte[] image=stream.toByteArray(); Unfortunately the printer prints a lot of

Create a Bitmap/Drawable from file path

£可爱£侵袭症+ 提交于 2019-11-26 09:31:20
问题 I\'m trying to create a Bitmap or Drawable from existing file path. String path = intent.getStringExtra(\"FilePath\"); BitmapFactory.Options option = new BitmapFactory.Options(); option.inPreferredConfig = Bitmap.Config.ARGB_8888; mImg.setImageBitmap(BitmapFactory.decodeFile(path)); // mImg.setImageBitmap(BitmapFactory.decodeFile(path, option)); // mImg.setImageDrawable(Drawable.createFromPath(path)); mImg.setVisibility(View.VISIBLE); mText.setText(path); But setImageBitmap() ,