在Android中将字符串转换为字节[]
我想将路径图像的字符串转换为字节数组,然后将其转换为位图 我有一个错误:在Android中将字符串转换为字节[],android,android-bitmap,Android,Android Bitmap,我想将路径图像的字符串转换为字节数组,然后将其转换为位图 我有一个错误: 09-25 09:38:11.050: W/System.err(21261): java.lang.IllegalArgumentException: bad base-64 09-25 09:38:11.350: W/System.err(21261): at android.util.Base64.decode(Base64.java:161) 09-25 09:38:11.350: W/System.err(2
09-25 09:38:11.050:
W/System.err(21261): java.lang.IllegalArgumentException: bad base-64
09-25 09:38:11.350:
W/System.err(21261): at android.util.Base64.decode(Base64.java:161)
09-25 09:38:11.350:
W/System.err(21261): at android.util.Base64.decode(Base64.java:136)
09-25 09:38:11.350:
W/System.err(21261): at com.up.upload.MainActivity.UploadImage(MainActivity.java:186)
09-25 09:38:11.350:
W/System.err(21261): at com.up.upload.MainActivity$2.run(MainActivity.java:149)
09-25 09:38:11.350:
W/System.err(21261): at java.lang.Thread.run(Thread.java:841)
我想我做得不对,但我知道为什么
我将非常感谢你的帮助
提前谢谢
我的代码如下:
String lStr = "/storage/emulated/0/image.jpg"
byte[] data = Base64.decode(lStr.getBytes(), 0);
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
Request.addProperty("docbinaryarray", bmp);
你做错了,伙计。您的代码仅转换字符串,而不是该路径中的图像数据。试试这个:
File imgFile = new File("/storage/emulated/0/image.jpg");
if(imgFile.exists()){
Bitmap bmp = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
Request.addProperty("docbinaryarray", bmp);
}
你做错了,伙计。您的代码仅转换字符串,而不是该路径中的图像数据。试试这个:
File imgFile = new File("/storage/emulated/0/image.jpg");
if(imgFile.exists()){
Bitmap bmp = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
Request.addProperty("docbinaryarray", bmp);
}
你做错了,伙计。您的代码仅转换字符串,而不是该路径中的图像数据。试试这个:
File imgFile = new File("/storage/emulated/0/image.jpg");
if(imgFile.exists()){
Bitmap bmp = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
Request.addProperty("docbinaryarray", bmp);
}
你做错了,伙计。您的代码仅转换字符串,而不是该路径中的图像数据。试试这个:
File imgFile = new File("/storage/emulated/0/image.jpg");
if(imgFile.exists()){
Bitmap bmp = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
Request.addProperty("docbinaryarray", bmp);
}
如果您使用的api级别<8,请下载Base64Utility.java
如果您使用的api级别<8,请下载Base64Utility.java
如果您使用的api级别<8,请下载Base64Utility.java
如果您使用的是api级别<8,那么请下载Base64Utility.java您完全错了: 使用:
你完全错了: 使用:
你完全错了: 使用:
你完全错了: 使用:
如果要从映像获取字节数组,请尝试下一个代码:
Bitmap bm = BitmapFactory.decodeFile("/path/image.jpg");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); //bm is the bitmap object
byte[] b = baos.toByteArray();
如果要从映像获取字节数组,请尝试下一个代码:
Bitmap bm = BitmapFactory.decodeFile("/path/image.jpg");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); //bm is the bitmap object
byte[] b = baos.toByteArray();
如果要从映像获取字节数组,请尝试下一个代码:
Bitmap bm = BitmapFactory.decodeFile("/path/image.jpg");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); //bm is the bitmap object
byte[] b = baos.toByteArray();
如果要从映像获取字节数组,请尝试下一个代码:
Bitmap bm = BitmapFactory.decodeFile("/path/image.jpg");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); //bm is the bitmap object
byte[] b = baos.toByteArray();
你喜欢这样吗
File imgFile = new File("/sdcard/Images/test_image.jpg");
if(imgFile.exists()){
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
//for drawable
//Drawable d = new BitmapDrawable(getResources(), myBitmap);
ImageView myImage = (ImageView) findViewById(R.id.imageview);
myImage.setImageBitmap(myBitmap);
}
你喜欢这样吗
File imgFile = new File("/sdcard/Images/test_image.jpg");
if(imgFile.exists()){
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
//for drawable
//Drawable d = new BitmapDrawable(getResources(), myBitmap);
ImageView myImage = (ImageView) findViewById(R.id.imageview);
myImage.setImageBitmap(myBitmap);
}
你喜欢这样吗
File imgFile = new File("/sdcard/Images/test_image.jpg");
if(imgFile.exists()){
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
//for drawable
//Drawable d = new BitmapDrawable(getResources(), myBitmap);
ImageView myImage = (ImageView) findViewById(R.id.imageview);
myImage.setImageBitmap(myBitmap);
}
你喜欢这样吗
File imgFile = new File("/sdcard/Images/test_image.jpg");
if(imgFile.exists()){
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
//for drawable
//Drawable d = new BitmapDrawable(getResources(), myBitmap);
ImageView myImage = (ImageView) findViewById(R.id.imageview);
myImage.setImageBitmap(myBitmap);
}
您试图使用字符串的字节作为位图的数据,这非常奇怪。你不应该在给定的路径上打开图像吗?除非你正在尝试一些扭曲的方式来传递隐藏的数据…你在做什么?图像的字符串路径不会生成位图图像您试图使用字符串的字节作为位图的数据,这非常奇怪。你不应该在给定的路径上打开图像吗?除非你正在尝试一些扭曲的方式来传递隐藏的数据…你在做什么?图像的字符串路径不会生成位图图像您试图使用字符串的字节作为位图的数据,这非常奇怪。你不应该在给定的路径上打开图像吗?除非你正在尝试一些扭曲的方式来传递隐藏的数据…你在做什么?图像的字符串路径不会生成位图图像您试图使用字符串的字节作为位图的数据,这非常奇怪。你不应该在给定的路径上打开图像吗?除非你正在尝试一些扭曲的方式来传递隐藏的数据…你在做什么?图像的字符串路径不会生成位图图像