android-bitmap

Android - ImageView: setImageBitmap VS setImageDrawable

对着背影说爱祢 提交于 2019-11-27 19:17:44
What is the difference between setImageBitmap and setImageDrawable ? I have an image which I would like to set dynamically from file. The tutorial that I followed says to convert my Bitmap to a BitmapDrawable then set it using setImageDrawable . I've notice that setting the Bitmap directly with setImageBitmap also works but I don't notice any difference. Bitmap image = BitmapFactory.decodeFile(imgFile.getAbsolutePath()); BitmapDrawable bitmapDrawable = new BitmapDrawable(image); imageView.setImageDrawable(bitmapDrawable); OR Bitmap image = BitmapFactory.decodeFile(imgFile.getAbsolutePath());

Scale image keeping its aspect ratio in background drawable

怎甘沉沦 提交于 2019-11-27 18:40:24
How do I make a background image fit the view but keep its aspect ratio when using <bitmap /> as a background drawable XML? None of <bitmap> 's android:gravity values gives the desired effect. It is impossible to achieve manipulating background attribute within xml-files only. There are two options: You cut/scale the bitmap programmatically with Bitmap.createScaledBitmap(Bitmap src, int dstWidth, int dstHeight, boolean filter) and set it as some View 's background. You use ImageView instead of background placing it as the first layout's element and specify android:scaleType attribute for it:

Image loses it's original result when passing it to another activity

杀马特。学长 韩版系。学妹 提交于 2019-11-27 09:50:25
I am working on a camera feature in my application. I am capturing an image and passing it to another activity. The problem that I'm facing is when I display the image in another activity it loses its original result (gets pixilated) for some reason. This is how I'm doing it: private void takePhotoFromCamera() { if(ActivityCompat.checkSelfPermission(EnterDataView.this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED){ Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(cameraIntent, CAMERA_REQUEST); }else { String[]

Drawable to byte[]

二次信任 提交于 2019-11-27 06:35:50
I have an image from the web in an ImageView . It is very small (a favicon) and I'd like to store it in my SQLite database. I can get a Drawable from mImageView.getDrawable() but then I don't know what to do next. I don't fully understand the Drawable class in Android. I know I can get a byte array from a Bitmap like: Bitmap defaultIcon = BitmapFactory.decodeStream(in); ByteArrayOutputStream stream = new ByteArrayOutputStream(); defaultIcon.compress(Bitmap.CompressFormat.JPEG, 100, stream); byte[] bitmapdata = stream.toByteArray(); But how do I get a byte array from a Drawable ? Cristian

android get Bitmap or sound from assets

本小妞迷上赌 提交于 2019-11-27 05:33:00
问题 I need to get Bitmap and sound from assets. I try to do like this: BitmapFactory.decodeFile("file:///android_asset/Files/Numbers/l1.png"); And like this: getBitmapFromAsset("Files/Numbers/l1.png"); private Bitmap getBitmapFromAsset(String strName) { AssetManager assetManager = getAssets(); InputStream istr = null; try { istr = assetManager.open(strName); } catch (IOException e) { e.printStackTrace(); } Bitmap bitmap = BitmapFactory.decodeStream(istr); return bitmap; } But I get just free

How to load a Bitmap with Picasso without using an ImageView?

血红的双手。 提交于 2019-11-27 05:19:29
问题 With ImageView , I can use the following code to download image with callback Picasso.with(activity).load(url).into(imageView, new Callback() { @Override public void onSuccess() { // do something } @Override public void onError() { } ); Or simply get the Bitmap from this Picasso.with(activity).load(url).get(); . Is there anyway to add callback for just download the image? If possible please provide sample code, Cheers! 回答1: You can create a Target and then modify the Bitmap inside the Targets

Using Glide to load bitmap into ImageView

怎甘沉沦 提交于 2019-11-27 04:25:52
问题 How can i use Glide library to load Bitmap into my ImageView? I want to create a custom image with text and load it into imageview using Glide. This is my method to create custom bitmap with text public Bitmap imageWithText(String text) { TextView tv = new TextView(context); tv.setText(text); tv.setTextColor(Color.WHITE); tv.setBackgroundColor(Color.BLACK); tv.setTypeface(null, Typeface.BOLD); tv.setGravity(Gravity.CENTER); tv.setTextSize(20); tv.setPadding(0, 25, 0, 0); Bitmap testB = Bitmap

Android- how can I convert android.net.Uri object to java.net.URI object?

此生再无相见时 提交于 2019-11-27 03:47:23
I am trying to get a FileInputStream object on an image that the user selects from the picture gallery. This is the android URI returned by android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI content://media/external/images/media/3 When I try to construct a java URI object from this object, I get an IllegalArgumentException with the exception description Expected file scheme in URI: content://media/external/images/media/3 whereas the android URI shows the scheme as content Update : Never found a solution for the original question. But if you want the byte stream of an image in the

Scale image keeping its aspect ratio in background drawable

杀马特。学长 韩版系。学妹 提交于 2019-11-27 00:40:22
问题 How do I make a background image fit the view but keep its aspect ratio when using <bitmap /> as a background drawable XML? None of <bitmap> 's android:gravity values gives the desired effect. 回答1: It is impossible to achieve manipulating background attribute within xml-files only. There are two options: You cut/scale the bitmap programmatically with Bitmap.createScaledBitmap(Bitmap src, int dstWidth, int dstHeight, boolean filter) and set it as some View 's background. You use ImageView

How to convert Image to PDF?

笑着哭i 提交于 2019-11-26 22:48:57
问题 I am developing an application where I need to convert an Image to PDF. I tried something, but the issue is, Image size in that PDF is very very small. I need solution to fix this. Also I am looking for converting multiple Images into single PDF document. I will post the code which I tried. public void convertPDF(byte[] path) { String FILE = "mnt/sdcard/FirstPdf.pdf"; Document document=new Document(); try { PdfWriter.getInstance(document, new FileOutputStream(FILE)); document.open(); try {