logo
down
shadow

Problem on some phones when encoding a bitmap to a byte[] array


Problem on some phones when encoding a bitmap to a byte[] array

By : user3849332
Date : October 23 2020, 11:12 AM
wish of those help I experienced similar problem on Android 1.5, while Android 1.6, 2.1 and 2.2 worked fine.
In my case bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputstream) failed only on bitmaps created from PNG images using BitmapFactory.decodeByteArray(...)
code :


Share : facebook icon twitter icon
byte array of default encoding to byte array of ISO-8859-1 encoding

byte array of default encoding to byte array of ISO-8859-1 encoding


By : user6834741
Date : March 29 2020, 07:55 AM
wish helps you i have a byte array having default encoding.
code :
byte[] isoBytes = new String(curBytes).getBytes("ISO-8859-1");
byte [] to String conversion and again back to byte [] using UTF-8 encoding is not giving same byte array

byte [] to String conversion and again back to byte [] using UTF-8 encoding is not giving same byte array


By : The Sixth Race
Date : March 29 2020, 07:55 AM
like below fixes the issue A sequence of bytes has to follow strict rules to be valid utf-8 encoded text. What you have in the array does not follow these rules, and can't be converted into a string without losing information.
The rules are explained for example in https://en.wikipedia.org/wiki/UTF-8
How to convert bitmap to byte array and byte array to bitmap in android?

How to convert bitmap to byte array and byte array to bitmap in android?


By : Emily Clark
Date : March 29 2020, 07:55 AM
help you fix your problem I convert bitmap to byte array and byte array to bitmap but when I have to show converted byte array in ImageView then it will show image with black corners not show in PNG format. I want to show image in PNG format, how can I do that?? , Try this code
code :
//For encoding toString
public String getStringImage(Bitmap bmp){
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bmp.compress(Bitmap.CompressFormat.PNG, 100, baos);
    byte[] imageBytes = baos.toByteArray();
    String encodedImage = android.util.Base64.encodeToString(imageBytes, Base64.DEFAULT);
    return encodedImage;
}
//For decoding
String str=encodedImage;
byte data[]= android.util.Base64.decode(str, android.util.Base64.DEFAULT);
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
Create a bitmap from a stored byte array and save to disk throws GDI+ exception when source of byte array was a jpg

Create a bitmap from a stored byte array and save to disk throws GDI+ exception when source of byte array was a jpg


By : user2792492
Date : March 29 2020, 07:55 AM
it fixes the issue You're disposing the MemoryStream before the image is written, try disposing the stream after the file has been saved. That worked for me :)
If you want to get the image format, try detecting it from the first few bytes of the stream:
Android : What is the difference between converting Bitmap to byte array and Bitmap.compress?

Android : What is the difference between converting Bitmap to byte array and Bitmap.compress?


By : Andrew Ngai
Date : March 29 2020, 07:55 AM
around this issue I am uploading an image (JPEG) from android phone to server. I tried these two methods - ,
I expected both to give the same result.
Related Posts Related Posts :
  • Unexpected token in JSON at position 1024 react native
  • How to make android.net.Uri encode & between query parameters to %26
  • How to simply save image to photo gallery
  • SQLite query to select one row and return it with 2 next rows
  • APK which I developed used to work fine earlier, but suddenly stopped working with "App not installed" error
  • Time Picker Fragments Differentiation
  • ExoPlayer Cant Play some audio streams
  • Start Activity for Result Request Code in Library Project
  • Getting a string value from the strings.xml resource file and set it in an interface class
  • Flutter, sign with both debug keys and release keys on Android
  • will an android service run code from the Xamarin Forms Project even when the app is closed?
  • Change boolean values on listviewitems in firebase
  • Android Studio 3.2.1: mixing versions can lead to runtime crashes when connect firebase
  • FCM migration without losing the old token
  • Change reported Version Number in Fabric Crashlytics
  • lateinit property mMap has not been initialized
  • Android - PWA does not open in standalone mode with service worker
  • Does LeakCanary has callback?
  • How to disable back button after splash screen in React Native
  • Assets Folder Not Including HTML Files In NativeScript Android Build
  • Dagger: What if I *WANT* a new instance every time?
  • How to get mailto working on android chrome?
  • SSO web login in android app with customtabs
  • how to make specific button side curved
  • remove item onlongclick from listview
  • header image alignment coming wrongly in NavigationView android
  • How to add many spaces after the text in TextView
  • how to set "Back Button" , closing activies except main activity in android?
  • Unable to run emulator on Android Studio || Windows 10
  • How can I achieve this requirement using Rx Java
  • How to tilt a Node(or TransformableNode)object downwards in Sceneform(Ar Core)?
  • When to use RTL and LTR?
  • How to create a tab view (category) similar to instagram's explore tab
  • Glide, RecyclerView: Glide returns the same picture over and over again even with different data inputs
  • how to stop open activity while splash screen killed
  • Changing the Color of the Dynamically loaded Buttons onclick
  • Listview: Add arrows as dividers
  • Show confirmation on back/up in Fragment with Navigation Architecture Component
  • How to find the corresponding maven artifact/gradle module of an Android class from the API Docs?
  • ZXing 3.6.0 in portrait mode?
  • Can't use Subversion command line client: svn The path to the Subversion executable is probably wrong android
  • how to set spinner list value first position showing empty
  • When using PersistableBundle in onCreate, it shows me a blank page
  • Failed to resolve Bintray dependency
  • jacoco code coverage not working for Android applications
  • How to change the color of the Android scroll bumper
  • Why run Handler in main Looper thread
  • Android Studio combined chart crashes
  • Setting suggested width and height to a custom view in android
  • How to set input type and format in EditText using kotlin?
  • how to define Android Oncreate optionmenu
  • Exception on orientation change from two-pane mode to one-pane mode
  • How to access members of nested struct and assign them the values read from device tree?
  • How to measure upload progress of a huge String with Retrofit 2?
  • Runtime app localization doesn't work with app bundles
  • How create View and Putting TextView inside it in kotlin
  • how to integrate app action using actions.xml?
  • ConstraintLayout - center TextView in the root but don't override Button
  • Android Studio Text not conforming to layout_margin when I run App on Emulator
  • verifyReleaseResources apk release - react native
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org