gpt4 book ai didi

java - 将可绘制对象保存到解析中

转载 作者:行者123 更新时间:2023-12-02 02:45:15 25 4
gpt4 key购买 nike

我将一个可绘制的 R.drawable.descarga 保存到我的项目中,我需要做的是,当没有要上传的文件来解析时,它会上传这个文件。

这是我的代码。

    if (requestCode == REQUEST_GALLERY_PHOTO7 && resultCode == RESULT_OK) {
Uri imageUri = data.getData();

InputStream inputStream;
try {
inputStream = getActivity().getApplicationContext().getContentResolver().openInputStream(imageUri);
Bitmap image = BitmapFactory.decodeStream(inputStream);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
ParseFile fileInmoFotoPrinci = new ParseFile("image.jpg", byteArray);
inmoFoto8.setImageBitmap(image);
if(fileInmoFotoPrinci!=null) {
grabarImagenPrinc.put("imagen7", fileInmoFotoPrinci);
}else{
Drawable myDrawable = getResources().getDrawable(R.drawable.descarga);
Bitmap myLogo = ((BitmapDrawable) myDrawable).getBitmap();
// FileOutputStream fos = new FileOutputStream(myDrawable);
//
// File file=myLogo.compress(Bitmap.CompressFormat.PNG, 100, fos);

grabarImagenPrinc.put("imagen7", myDrawable);


}
grabarImagenPrinc.saveInBackground();

} catch (FileNotFoundException e) {
e.printStackTrace();
Toast.makeText(getActivity(), "No fue posible abrir la imagen", Toast.LENGTH_LONG).show();
}

}

我在这部分会遇到麻烦......

Drawable myDrawable = getResources().getDrawable(R.drawable.descarga);
Bitmap myLogo = ((BitmapDrawable) myDrawable).getBitmap();
// FileOutputStream fos = new FileOutputStream(myDrawable);
//
// File file=myLogo.compress(Bitmap.CompressFormat.PNG, 100, fos);

grabarImagenPrinc.put("imagen7", myDrawable);

我尝试在这部分应用许多 StackOverflow 帖子,但似乎没有任何效果。

文档是这么说的,但我不太明白......

    byte[] data = "Working at Parse is great!".getBytes();
ParseFile file = new ParseFile("resume.txt", data);

还在 else 语句中尝试了此代码。

 Drawable d = null; // the drawable (Captain Obvious, to the rescue!!!)
Bitmap bitmap = ((BitmapDrawable)d).getBitmap();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
byte[] bitmapdata = stream.toByteArray();
ParseFile file = new ParseFile("image.jpeg", bitmapdata);
grabarImagenPrinc.put("imagen7",file);

我的问题是可绘制对象没有保存来解析它应该如何做。

这是代码更新!

private void queryEmpresa() {
/**Ojo no es que no este sirviendo el metodo sino que el tipo de empresa asignado al usuario
* no concuerda para que llene el recycler*/
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("objectId", ParseUser.getCurrentUser().getObjectId());
query.include("Empresa");
query.getInBackground(ParseUser.getCurrentUser().getObjectId(), new GetCallback<ParseUser>() {
public void done(ParseUser object, ParseException e) {
if (e == null) {
// object will be your user and you should be able to retrieve Empresa like this
empresa = object.getParseObject("Empresa");
if (empresa != null) {
ParseObject grabarImagenPrinc = new ParseObject("PropiedadesInmobiliarias");

stringEmpresa = empresa.getObjectId();
ParseObject entity = new ParseObject("PropiedadesInmobiliarias");
Bitmap bm = ((BitmapDrawable) inmoFotoPrincipal.getDrawable()).getBitmap();

if(bm.equals("")) {
ByteArrayOutputStream myLogoStream = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, myLogoStream);
byte[] myLogoByteArray = myLogoStream.toByteArray();
bm.recycle();
ParseFile myLogoFile = new ParseFile("mylogo.png", myLogoByteArray);
grabarImagenPrinc.put("imagen7", myLogoFile);
grabarImagenPrinc.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {

}
});
}
entity.put("numeroBanos", edittextNumeroDeBanos.getText().toString().trim());
entity.put("descripcionAdicionalPropiedad", edittextDescripcion.getText().toString().trim());
entity.put("Empresa", ParseObject.createWithoutData("Empresa", stringEmpresa));
entity.put("NombrePropiedad", edittextNombrePropiedad.getText().toString().trim());
entity.put("Precio", edittextPrecio.getText().toString().trim());
String xx=edittextNumeroHabitaciones.getText().toString().trim();
entity.put("numeroDeHabitaciones", edittextNumeroHabitaciones.getText().toString().trim());
String xy=edittextMetrosCuadrados.getText().toString().trim();
entity.put("metrosCuadrados", edittextMetrosCuadrados.getText().toString().trim());
entity.put("valorAdministracion", edittextValorAdmin.getText().toString().trim());
entity.put("Parqueaderos", edittextParqueaderos.getText().toString().trim());
entity.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {

Log.i("XX","este es el error de porque no salva",e);
Intent intent = new Intent(getActivity(), MainActivity.class);
getActivity().startActivity(intent);
}
});

} else {
// something went wrong. It would be good to log.
}
}
}


});
}

这用于按钮中以通过单击监听器进行保存...

看看这个,我根据你的建议davi采取了不同的方法。

Look that the value for bm is "" but i dont know how to do the if it is always skipping it

最佳答案

尝试:

...
Drawable myDrawable = getResources().getDrawable(R.drawable.descarga);
Bitmap myLogo = ((BitmapDrawable) myDrawable).getBitmap();
ByteArrayOutputStream myLogoStream = new ByteArrayOutputStream();
myLogo.compress(Bitmap.CompressFormat.PNG, 100, myLogoStream);
byte[] myLogoByteArray = myLogoStream.toByteArray();
myLogo.recycle();
ParseFile myLogoFile = new ParseFile("mylogo.png", myLogoByteArray);
grabarImagenPrinc.put("imagen7", myLogoFile);
...

关于java - 将可绘制对象保存到解析中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57150380/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com