bitmapfactory

Android how to scale an image with BitmapFactory Options

旧时模样 提交于 2019-12-18 05:37:31
问题 I want to decode an image from the SD card with BitmapFactory.decodeFile(path, options). I also want images that are larger than 2048x2048 pixels to be scaled down to at most 2048x2048 (maintaining the proportions). I could do this manually after getting the bitmap, but that would require allocating a large amount of bytes in addition to the ones already allocated. How should i set up my BitmapFactory.Options object to get that effect? Thanks 回答1: Use BitmapFactory.Options.inSampleSize when

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

蹲街弑〆低调 提交于 2019-12-17 02:27:20
问题 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

How to show image preview while downloading it on Android?

☆樱花仙子☆ 提交于 2019-12-14 04:21:47
问题 i want to write an app that displays images from a Cherokee webserver. I do download the images with the following code: @Override protected Bitmap doInBackground(URL... params) { URL urlToDownload = params[0]; String downloadFileName = urlToDownload.getFile(); downloadFile = new File(applicationContext.getCacheDir(), downloadFileName); new File(downloadFile.getParent()).mkdirs(); // create all necessary folders // download the file if it is not already cached if (!downloadFile.exists()) {

BitmapFactory.decodeFile() returns null in some devices

三世轮回 提交于 2019-12-13 18:32:28
问题 I'm using following code from here. I want to compress image. BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; Bitmap bmp = BitmapFactory.decodeFile(filePath, options); int actualHeight = options.outHeight; int actualWidth = options.outWidth; After choose image from Camera, Gallery and Photos, i'm getting different type of paths in different devices based on OS type and device model. like: 1) /storage/emulated/0/Android/data/... 2) /raw//storage

File does exists when calling .exists() but can't find it later

不羁的心 提交于 2019-12-13 04:22:29
问题 I'm trying to create a file that is eventually going to hold a picture (EXTRA_OUTPUT) like this: File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES), "scouthouse"); if(!mediaStorageDir.exists()) { mediaStorageDir.mkdirs(); } SimpleDateFormat s = new SimpleDateFormat("ddMMyyyyhhmmss"); String format = s.format(new Date()); File file = new File(mediaStorageDir.getPath() + File.separator + format + ".jpg"); try { file.createNewFile(); }

Android ImageView setImageBitmap

萝らか妹 提交于 2019-12-12 21:42:35
问题 I'm trying to better understand how Android handle images in order to use memory more efficiently. I have an image stored in the Bitmap and I'm using ImageView.setImageBitmap() to display it. Now the question is - will it use the Bitmap I've passed it in the future, or it's making a copy of it and the Bitmap I've created isn't used anymore after the call to setImageBitmap ? Asuming it's gonna keep reference to the Bitmap I've passed, how is it gonna behave when Bitmap was created via

Loading Bitmap to ImageView from URL in android

久未见 提交于 2019-12-12 21:22:36
问题 I am using following method to retrieve a bitmap from the url and pass it on to the imageview , but the imageview is not being updated. public static Bitmap LoadImageFromWebOperations(String url) { Bitmap bitmap; try { InputStream is = new URL(url).openStream(); bitmap = BitmapFactory.decodeStream(is); return bitmap; } catch (Exception e) { return null; } call - mov1_poster.setImageBitmap(VPmovies.LoadImageFromWebOperations(mov_details[0][7])); //doesn't work Toast.makeText(this,"url is \n"

BitmapFactory﹕ Unable to decode stream - null

无人久伴 提交于 2019-12-12 10:29:54
问题 I want to add an image uploader to my app, I can choose an image from the image folder, but when I chose an image, the image path is only displayed as "null", and when I click upload, I get this Error: BitmapFactory﹕ Unable to decode stream: java.lang.NullPointerException: This is my code: package com.test.mysqltest; import java.io.DataOutputStream; import java.io.File; import java.io.FileInputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net

Creating bitmap from canvas java

一个人想着一个人 提交于 2019-12-12 04:05:32
问题 SOLUTION Thanks to @ChandraSekhar's suggestions the issue was that I was passing in an Immutable Bitmap to the canvas constructor. The solution is to create a copy of it when using BitmapFactory.decodeFile(); Bitmap bmp = BitmapFactory.decodeFile(imageURL).copy(Bitmap.Config.ARGB_8888, true); So I have a bitmap that I am using bitmapFactory.decodeFile() for and this works. I am able to create the bitmap, then I need to create a canvas and this is where things get weird. Here's the flow of

Android - Setting background on canvas using PNG file

半世苍凉 提交于 2019-12-12 02:54:40
问题 I'm trying to set a .PNG file as background on Canvas in my app. I've made an image 480 x 800 and used this method: canvas.drawBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.image_1), 0, 0, null); I've started an emulator (WVGA800) but my image looks greater than screen of the device. How do I resize this image or what kind of methods should I use to make this image well-matched. Secondly, is there any way to make backgrounds like this universal for devices with different