我希望能够允许用户拍照并将其保存为ParseFile在ParseObject中解析,我已经完成了,但我也希望将它作为PasreFile或位图保存在我的数据库中。我无法将其保存为URI,因为我必须从解析中查询它,在最初保存它时我不能这样做。
数据库
public class Note {
private String id;
private String title;
private String content;
Note(String noteId, String noteTitle, String noteContent) {
id = noteId;
title = noteTitle;
content = noteContent;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
@Override
public String toString() {
return this.getTitle();
}
}
Activityone
note = new Note(post.getObjectId(), postTitle, postContent);
和
note = new Note(intent.getStringExtra("noteId"), intent.getStringExtra("noteTitle"), intent.getStringExtra("noteContent"));
答案 0 :(得分:1)
要在数据库中保存ParseFile,请使用
ParseFile file = new ParseFile(fileName, byte[]);
file.save();
保存文件时,将在服务器上创建文件中的URL,稍后您将可以检索该文件。您只会看到您在数据库中保存的文件名。
要将其另存为解析文件,如果您没有位图,请首先将drawable转换为位图。然后,将Bitmap转换为字节数组。
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(compressFormat, quality, stream);
byte[] bitmapBytes = stream.toByteArray();
ParseFile image = new ParseFile("myImage", bitmapBytes);
try {
image.save();
} catch (ParseException e) {
return null;
}