में फ़ोटो और वीडियो को सहेजना और पुनर्प्राप्त करना Parse Android docs पर देख रहा था और फ़ोटो और वीडियो को सहेजने के लिए आपको देखा गया था, आपको डेटा के नाम और बाइट [] के साथ new ParseFile
प्रारंभ करना होगा और इसे सहेजना होगा।पार्स (एंड्रॉइड)
छवि उरी और वीडियो उरी को बाइट सरणी में परिवर्तित करने का सबसे आसान तरीका क्या है?
यहाँ मेरी प्रयास किया समाधान हैं:
mPhoto = new ParseFile("img", convertImageToBytes(Uri.parse(mPhotoUri)));
mVideo = new ParseFile ("vid", convertVideoToBytes(Uri.parse(mVideoUri)));
private byte[] convertImageToBytes(Uri uri){
byte[] data = null;
try {
ContentResolver cr = getBaseContext().getContentResolver();
InputStream inputStream = cr.openInputStream(uri);
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return data;
}
private byte[] convertVideoToBytes(Uri uri){
byte[] videoBytes = null;
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
FileInputStream fis = new FileInputStream(new File(getRealPathFromURI(this, uri)));
byte[] buf = new byte[1024];
int n;
while (-1 != (n = fis.read(buf)))
baos.write(buf, 0, n);
videoBytes = baos.toByteArray();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return videoBytes;
}
private String getRealPathFromURI(Context context, Uri contentUri) {
Cursor cursor = null;
try {
String[] proj = { MediaStore.Video.Media.DATA };
cursor = context.getContentResolver().query(contentUri, proj, null,
null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
} finally {
if (cursor != null) {
cursor.close();
}
}
}
convertImageToBytes
और convertVideoToBytes
तरीके अब के लिए काम करते हैं, लेकिन मैं सिर्फ अगर मैं कर सही ढंग से इस कर रहा हूँ सोच रहा हूँ।
वहाँ एक कारण है कि आप चित्र को डीकोड और उसे फिर से सेक है? – harism
@harism मुझे सच में यकीन नहीं है - मुझे लगता है कि मुझे लगता है कि यह एक स्टैक ओवरफ़्लो उत्तर पर है। मुझे वास्तव में इसके साथ बहुत कम अनुभव है, लेकिन ऐसा इसलिए हो सकता है क्योंकि आपको छवि पथ को बिटमैप में परिवर्तित करना होगा। – lschlessinger
बस सोच रहा है क्योंकि यह मामला बहुत अच्छी तरह से हो सकता है कि अलग छवि और वीडियो बाइट सरणी पढ़ने के तरीकों की आवश्यकता नहीं है। – harism