Guys anyone please help me how to get video thumbnail from server side video?..
I Searched alot in stack but didn't get any useful solution?..
I used FFmpegMediaMetadataRetriever this library.. I faced few errors..
video thumbnail to server
final File myFile = new File(selectedPath);
Bitmap bitmap = ThumbnailUtils.createVideoThumbnail(selectedPath, MediaStore.Video.Thumbnails.MINI_KIND);
String thumbnail = getStringImage(bitmap);
//Server side
params.put("thumnails",thumbnail);
public String getStringImage(Bitmap bmp){
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] imageBytes = baos.toByteArray();
String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);
return encodedImage;
}
Related
I want to upload my gallery image to localhost database in the form of string from android but i did not found any relevant topic. Please guide me
you can convert you Image bitmap to base64 String by this code :`
`ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
byte[] byteArray = byteArrayOutputStream .toByteArray();
String encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
I'm going to convert file to base64 so I send file and convert it to bitmap and when i want to compress it, it give me error null point exception
this is what everything that i did.
public static String getFileToByte(String path){
Bitmap bm = null;
ByteArrayOutputStream baos = null;
byte[] b = null;
String encodeString = null;
try{
bm = BitmapFactory.decodeFile(path);
baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, baos);
b = baos.toByteArray();
encodeString = Base64.encodeToString(b, Base64.DEFAULT);
}catch (Exception e){
e.printStackTrace();
}
return encodeString;
}
I got error on this error:
bm.compress(Bitmap.CompressFormat.JPEG, 100, baos);
and pass:
getFileToByte(image.getAbsolutePath());
Do not convert the file to a bitmap first. Your bitmap is null as there is not enough memory to construct a bitmap for that image file with big resolution.
Instead you should directly base64 encode the bytes of the file.
Then your code is the same for all kind of files too.
How can i retrieve images from firebase . i am converting my images to base64 string first then saving it to firebase string code below.
Bitmap bm = BitmapFactory.decodeFile(imgDecodableString);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG,100,baos);
byte[] byteArray = baos.toByteArray();
String encodedImage = Base64.encodeBytes(byteArray,Base64.ENCODE);
ref.push().setValue(encodedImage);
Now how can i show this image in my activity.
byte[] decodeImage = Base64.decode(encodedImage,Base64.ENCODE);
Bitmap bitmap = BitmapFactory.decodeByteArray(decodeImage);
imageView.setImageBitmap(bitmap);
I have an Android application which sends an image to a web service. I want to send the same photo back from the web service to Android.
I made a test program to compare the base64 data that's sent from Android to the server and the base64 that's sent back from server to Android -- they are exactly equal.
I want to use the base 64 string to create a bitmap, so I tried this:
String image = client1.getBaseURI("restaurantFoods/OneFood/"
+ this.getID() + "/getImage");
byte[] decodedString = Base64.decode(image, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0,
decodedString.length);
if(decodedByte == null){
Log.d(this.getFoodItem().getName(), image);
Log.d("isNull", "Yes");
}
else{
Log.d("isNull", "No");}
I keep getting null because the log just prints "YES".
Can anyone please help?
If you want to know how I encode the image it is as follows:
private String getBase64(Bitmap bitmap) {
String imgString = Base64.encodeToString(getBytesFromBitmap(bitmap),
Base64.NO_WRAP);
return imgString;
}
private byte[] getBytesFromBitmap(Bitmap bitmap) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.JPEG, 70, stream);
return stream.toByteArray();
}
Bitmap icon = BitmapFactory.decodeResource(this.getResources(),
R.drawable.pizza);
String iconBase64 = this.getBase64(icon);
Try this to bitmap;
public Bitmap convert(String img){
byte[] b = Base64.decode(img, Base64.DEFAULT);
return BitmapFactory.decodeByteArray(b, 0, b.length);
}
And this to String
public String convert(Bitmap bm, int quality){
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, quality, baos);
byte[] byt = baos.toByteArray();
bm.recycle();
return Base64.encodeToString(byt, Base64.DEFAULT);
}
Really I don't see any real problems with your code, but these have worked for me so I suggest that you try them and see if that is actually your problem.
In my application I have faced a small issue in encoding and decoding images to String and pass it to web service.
After getting the bitmap image, I convert it into byte[] and encode to String value but in Some cases it shows error I don't know why it comes.
And one more doubt is Base64 class only supports to convert Bitmap image to String or any other tools available to do the same.
Thanks in advance...
In the case of OutOfMemoryError, below code helps me.
public String BitMapToString(Bitmap bitmap){
ByteArrayOutputStream baos=new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG,100, baos);
byte [] b=baos.toByteArray();
String temp=null;
try{
System.gc();
temp=Base64.encodeToString(b, Base64.DEFAULT);
}catch(Exception e){
e.printStackTrace();
}catch(OutOfMemoryError e){
baos=new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG,50, baos);
b=baos.toByteArray();
temp=Base64.encodeToString(b, Base64.DEFAULT);
Log.e("EWN", "Out of memory error catched");
}
return temp;
}
Basically what i did is : i catch OutofMemoryError and in that catch block i resize it by 50% and then i encode it to string.
Try My Below Sample Code Of Project
Bitmap bmp = (Bitmap) data.getExtras().get("data");
img.setImageBitmap(bmp);
btnadd.requestFocus();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] b = baos.toByteArray();
encodedImageString = Base64.encodeToString(b, Base64.DEFAULT);
byte[] bytarray = Base64.decode(encodedImageString, Base64.DEFAULT);
Bitmap bmimage = BitmapFactory.decodeByteArray(bytarray, 0,
bytarray.length);