android-bitmap

Convert GradientDrawable to Bitmap

雨燕双飞 提交于 2019-11-28 09:48:09
问题 I have the following gradient (generated dynamically): GradientDrawable dynamicDrawable = new GradientDrawable(); dynamicDrawable.setGradientType(GradientDrawable.LINEAR_GRADIENT); dynamicDrawable.setUseLevel(false); int colors[] = new int[3]; colors[0] = Color.parseColor("#711234"); colors[1] = Color.parseColor("#269869"); colors[2] = Color.parseColor("#269869"); dynamicDrawable.setColors(colors); and I want to set that drawable in a view using onDraw method. When I want to assign a Drawable

Get Video Thumbnail from Uri

空扰寡人 提交于 2019-11-28 08:44:28
问题 I want to select a video from my Gallery. It's working fine. But now I want to display a Bitmap, as a thumbnail.I tired this code it's not working, it always says: NullPointerException Bitmap bitmap2 = ThumbnailUtils.createVideoThumbnail(uri.getPath, MediaStore.Video.Thumbnails.MICRO_KIND); This is all in an onActivityResult. How can I get the Bitmap from the video Uri?? Thanks for your help 回答1: in onActivityResult String[] filePathColumn = {MediaStore.Images.Media.DATA}; Cursor cursor =

How to convert Image to PDF?

吃可爱长大的小学妹 提交于 2019-11-28 06:03:46
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 { image=Image.getInstance(path); document.add(new Paragraph("My Heading")); document.add(image); document

android get Bitmap or sound from assets

五迷三道 提交于 2019-11-28 05:18:32
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 space, not image. How to do this? Warpzit public static Bitmap getBitmapFromAsset(Context context, String

How to get the height and width of an ImageView/Bitmap in Android

落花浮王杯 提交于 2019-11-28 04:59:56
I want to get the height and width of an image bitmap that is either in ImageView or a background image. Please help me, any help will be appreciated. Pratik You can get height and width of ImageView by using getWidth() and getHeight() through while this will not give you the exact width and height of the image, for getting the Image width height first you need to get the drawable as background then convert drawable to BitmapDrawable to get the image as Bitmap from that you can get the width and height like here Bitmap b = ((BitmapDrawable)imageView.getBackground()).getBitmap(); int w = b

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

Deadly 提交于 2019-11-28 04:22:31
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! You can create a Target and then modify the Bitmap inside the Targets callback method onBitmapLoaded(...) . Here is how: // make sure to set Target as strong reference private

FAILED BINDER TRANSACTION while passing Bitmap from one activity to another

拜拜、爱过 提交于 2019-11-28 02:04:49
问题 I want to pass a image as a bitmap from one activity to another. And i want to know whether it is possible to do like that. Sending Activity Intent intent = new Intent(getApplicationContext(), BitmapActivity.class); Bundle b = new Bundle(); b.putParcelable("BITMAP", bitmap); intent.putExtras(b); startActivity(intent); Receiving Activity Bundle bb = this.getIntent().getExtras(); b = bb.getParcelable("BITMAP"); But i am getting !!! FAILED BINDER TRANSACTION !!! Error 回答1: You can use a global

Black edges around the taken screenshot

限于喜欢 提交于 2019-11-28 01:29:32
问题 I'm following this example : package com.mtsahakis.mediaprojectiondemo; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; import android.graphics.PixelFormat; import android.graphics.Point; import android.hardware.display.DisplayManager; import android.hardware.display.VirtualDisplay; import android.media.Image; import android.media.ImageReader; import android.media

Release Memory of Particular Activity when it is Destroyed

自古美人都是妖i 提交于 2019-11-27 21:10:43
问题 I have a launcher Activity that load and resize big bitmap as it's background when it opens. Whenever hit the back button, the Activity is destroyed . But I think the memory is not released yet. When I open back the app, hit the back button and open it again (repeatedly), I will get a OutOfMemoryError . I am sorry for this newbie question but I am wondering how do I release the memory whenever an Activity is destroyed ? @Override protected void onCreate(Bundle savedInstanceState) { super

Using Glide to load bitmap into ImageView

这一生的挚爱 提交于 2019-11-27 20:15:00
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.createBitmap(100, 100, Bitmap.Config.ARGB_8888); Canvas c = new Canvas(testB); tv.layout(0, 0, 100,