Android 使用Glide,我可以更直接地获取字节数据吗?

Android 使用Glide,我可以更直接地获取字节数据吗?,android,android-glide,Android,Android Glide,仅滑翔4.11+ 使用Glide,我可以这样做并获得位图,这非常棒 protected void onActivityResult(int requestCode, int resultCode, Intent tent){ super.onActivityResult(requestCode, resultCode, data); Glide.with(this).asBitmap() .load(tent.getData()) .apply(new RequestOption

仅滑翔4.11+

使用Glide,我可以这样做并获得位图,这非常棒

protected void onActivityResult(int requestCode, int resultCode, Intent tent){
  super.onActivityResult(requestCode, resultCode, data);
  Glide.with(this).asBitmap()
  .load(tent.getData())
  .apply(new RequestOptions().override(300, 400))
  .into(new CustomTarget<Bitmap>() {
    @Override
    public void onResourceReady(@NonNull Bitmap glideBitmap,
              @Nullable Transition<? super Bitmap> transition) {

      Log.i("c", "BAM! Just like that, a bitmap ...");

也许我是XY,滑翔真的能返流吗?正如您所知,要发送到Firebase,您需要流或字节数据。如果是这样的话,很抱歉成为一个蹩脚的ios开发人员。

在本文中,您应该将
asBitmap
替换为
as(byte[].class)

在这里:向下滚动到部分或搜索
转码
,您将看到
toBytes
方法。也许这对你有帮助。谢谢你@MayurGajra-啊,但是没有办法告诉Glide“jpeg,70%”?再次感谢-我问Mayur,你知道有没有办法告诉Glide“jpeg,70%”?(或PNG等?@Fattie我想您需要定制
ResourceDecoder
。检查这个问题
protected void onActivityResult(int requestCode, int resultCode, Intent tent){
  super.onActivityResult(requestCode, resultCode, data);
  Glide.with(this).asBitmap()
  .load(tent.getData())
  .apply(new RequestOptions().override(300, 400))
  .into(new CustomTarget<Bitmap>() {
    @Override
    public void onResourceReady(@NonNull Bitmap glideBitmap,
              @Nullable Transition<? super Bitmap> transition) {

      // convert badly to a byte array...

      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      glideBitmap.compress(Bitmap.CompressFormat.JPEG, 70, baos);
      byte[] byteData = baos.toByteArray();

      Log.i("c", "had to work for bytes :/ ...");
  UploadTask uploadTask = storeRef.putBytes(byteData);