bitmapfactory

BitmapFactory returns bigger image than source

老子叫甜甜 提交于 2019-11-29 03:05:45
问题 Hi i am creating a Bitmap from an png image named image.png . The image has the dimension 75 (width) x 92 (height). When I run this code: Bitmap bitmap = BitmapFactory.decodeResource(this.context.getResources(), R.drawable.image Log.d("image", "height: " + bitmap.getHeight() + " width: " + bitmap.getWidth()); the logger logs: DEBUG/image(3550): height: 138 width: 113 and the image on the screen is bigger than other images which have the dimension 75 x 92. What can I do to make android load

Saving canvas to bitmap on Android

与世无争的帅哥 提交于 2019-11-28 11:31:31
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 onDraw(Canvas canvas) { // TODO Auto-generated method stub super.onDraw(canvas); if (IsTouchDown) { //

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

試著忘記壹切 提交于 2019-11-28 09:09:31
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 actuallyUsableBitmap = BitmapFactory.decodeFileDescriptor( fileDescriptor.getFileDescriptor(), null, options); Utils.Log("

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

倖福魔咒の 提交于 2019-11-28 08:50:13
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, xpp); The contents of actionbar_background.xml are <?xml version="1.0" encoding="utf-8"?> <bitmap xmlns

Image isn't creating using the BitmapFactory.decodeByteArray

老子叫甜甜 提交于 2019-11-28 08:11:58
问题 Edit: When I save those bytes in the txt file and when I save it as png file , it shows the image, but it is not working here why...? I am using this code to create image from byte array on doInBackground() String base64data=StringEscapeUtils.unescapeJava(IOUtils.toString(resp.getEntity().getContent())); base64data=base64data.substring(1,base64data.length()-1); JSONObject obj=new JSONObject(base64data); JSONArray array=obj.getJSONArray("EMRTable"); JSONObject childobj=array.getJSONObject(0);

Why does BitmapFactory.decodeResource scale my image?

那年仲夏 提交于 2019-11-28 01:27:02
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, since my resource is in a density-less directory. What is the reason for decodeResource scaling my

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

别来无恙 提交于 2019-11-28 01:20:46
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()); HttpURLConnection con = (HttpURLConnection) ulrn.openConnection(); InputStream is = con.getInputStream();

BitmapFactory.decodeStream returns null without exception

五迷三道 提交于 2019-11-27 23:09:18
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 NullPointerException { //Decode image size BitmapFactory.Options o = new BitmapFactory.Options(); int

How to write Text on ImageView in android coding?

这一生的挚爱 提交于 2019-11-27 22:58:31
Hi I've been trying to write Numbers on Imageview. Images for N number of questions. If the user entered answer is correct, then it should be displayed with question number with tick mark image else question number with wrong mark image. I need to write the question number on the image. My code is here: LinearLayout l_layout = (LinearLayout) findViewById(R.id.linear_view_report); LayoutParams param = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f); ImageView[] imgview=new ImageView[questions.length]; for(int i=0;i<no_of_questions;i++) { if

Android: decodeFile always returns null for file in internal storage

青春壹個敷衍的年華 提交于 2019-11-27 15:47:15
问题 I have a file saved locally into the application's private storage. I have verified it exists, however whenever I call BitmapFactory.decodeFile it always returns null . If I save the file as a resource and use ImageView.setImageResource , it always shows up fine. What is the problem? Here is the snippet: filename = "test.png"; if (doesFileExist(filename)) Bitmap bMap = BitmapFactory.decodeFile(filename); I've also tried: Bitmap bMap = BitmapFactory.decodeFile(getFilesDir().getPath() +