android-bitmap

How to check if a Bitmap is empty (blank) on Android

对着背影说爱祢 提交于 2019-11-26 21:10:15
问题 How can I check if a Bitmap object is completely blank, i.e. all its pixels are transparent, without a x-y loop on every pixel? 回答1: You can check your Bitmap instance (in the example myBitmap ) against an empty one with: Bitmap emptyBitmap = Bitmap.createBitmap(myBitmap.getWidth(), myBitmap.getHeight(), myBitmap.getConfig()); if (myBitmap.sameAs(emptyBitmap)) { // myBitmap is empty/blank } 回答2: This is not an efficient way to solve the problem but it does its purpose cause I didn't find a

Drawable vs. Bitmap [duplicate]

六眼飞鱼酱① 提交于 2019-11-26 20:06:17
问题 This question already has answers here : What is the difference between Bitmap and Drawable in Android? (4 answers) Closed 3 years ago . I am writing a real-time game for Android, and after looking at some code from the samples provided in the SDK, I am confused as to when I should use Bitmap or Drawable for my sprites in my game. What's the difference? Which one is better (faster) for sprites and which one is better for a static background? 回答1: To get an idea which is better you may want to

What is the difference between Bitmap and Drawable in Android?

假装没事ソ 提交于 2019-11-26 17:59:28
问题 I googled but i couldn't find any article to describe about the difference between Bitmap and Drawable in Android. 回答1: A Bitmap is a representation of a bitmap image (something like java.awt.Image). A Drawable is an abstraction of "something that can be drawn". It could be a Bitmap (wrapped up as a BitmapDrawable ), but it could also be a solid color, a collection of other Drawable objects, or any number of other structures. Most of the Android UI framework likes to work with Drawable

Android - ImageView: setImageBitmap VS setImageDrawable

流过昼夜 提交于 2019-11-26 15:58:16
问题 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

Android Bitmap to Base64 String

◇◆丶佛笑我妖孽 提交于 2019-11-26 12:14:13
How do I convert a large Bitmap (photo taken with the phone's camera) to a Base64 String? jeet use following method to convert bitmap to byte array: ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream); byte[] byteArray = byteArrayOutputStream .toByteArray(); to encode base64 from byte array use following method String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT); I have fast solution. Just create a file ImageUtil.java import android.graphics.Bitmap; import android.graphics.BitmapFactory;

Drawable to byte[]

喜夏-厌秋 提交于 2019-11-26 12:06:30
问题 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)

Get Bitmap attached to ImageView

浪尽此生 提交于 2019-11-26 11:59:56
Given ImageView image = R.findViewById(R.id.imageView); image.setImageBitmap(someBitmap); Is it possible to retrieve the bitmap? Bitmap bitmap = ((BitmapDrawable)image.getDrawable()).getBitmap(); Sarwar Erfan This will get you a Bitmap from the ImageView . Though, it is not the same bitmap object that you've set. It is a new one. imageView.buildDrawingCache(); Bitmap bitmap = imageView.getDrawingCache(); === EDIT === imageView.setDrawingCacheEnabled(true); imageView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));

“Bitmap too large to be uploaded into a texture”

这一生的挚爱 提交于 2019-11-26 09:58:31
I'm loading a bitmap into an ImageView, and seeing this error. I gather this limit relates to a size limit for OpenGL hardware textures (2048x2048). The image I need to load is a pinch-zoom image of about 4,000 pixels high. I've tried turning off hardware acceleration in the manifest, but no joy. <application android:hardwareAccelerated="false" .... > Is it possible to load an image larger than 2048 pixels into an ImageView? jptsetung All rendering is based on OpenGL, so no you can't go over this limit ( GL_MAX_TEXTURE_SIZE depends on the device, but the minimum is 2048x2048, so any image

How to get Bitmap from an Uri?

為{幸葍}努か 提交于 2019-11-26 03:15:35
问题 How to get a Bitmap object from an Uri (if I succeed to store it in /data/data/MYFOLDER/myimage.png or file///data/data/MYFOLDER/myimage.png ) to use it in my application? Does anyone have an idea on how to accomplish this? 回答1: . . IMPORTANT: See answer from @Mark Ingram below and @pjv for at better solution. . . You could try this: public Bitmap loadBitmap(String url) { Bitmap bm = null; InputStream is = null; BufferedInputStream bis = null; try { URLConnection conn = new URL(url)

Get Bitmap attached to ImageView

烂漫一生 提交于 2019-11-26 02:39:55
问题 Given ImageView image = R.findViewById(R.id.imageView); image.setImageBitmap(someBitmap); Is it possible to retrieve the bitmap? 回答1: Bitmap bitmap = ((BitmapDrawable)image.getDrawable()).getBitmap(); 回答2: This will get you a Bitmap from the ImageView . Though, it is not the same bitmap object that you've set. It is a new one. imageView.buildDrawingCache(); Bitmap bitmap = imageView.getDrawingCache(); === EDIT === imageView.setDrawingCacheEnabled(true); imageView.measure(MeasureSpec