V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
momosolaris
V2EX  ›  Android

.tif 的图像可以直接在A ndroid studio 里面显示出来吗?

  •  
  •   momosolaris · 2022-11-15 07:05:37 +08:00 · 4193 次点击
    这是一个创建于 518 天前的主题,其中的信息可能已经有所发展或是发生改变。

    大家好,我这个菜鸟又来了。 我之前得到一个任务, 就是在 android studio 里面加载一个.tif 文件格式的图像, 然后进行一个图像转换( python   code 处理 image   tranformation ,比如 gabor filter/transformation )的方法。 我的问题:  android studio 手机先要从真实手机里加载.tif 的图像 1.首先我在我的真实的手机下存储了.tif 的10个图像, 2.然后我现在我的 androidstudio 里设置了一个从手机里选择 galley 选取一张.tif 的图片, 3.然后用 imageview 展示在 app 里。

    我有个疑问,.tif 格式的图像真的能正常在手机屏幕上显示出来吗,因为我无法看到。tif 的图像显示在屏幕上?

    我的代码: M ainActivity.java import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView;

    import android.Manifest; import android.annotation.SuppressLint; import android.content.Intent; import android.content.pm.PackageManager; import android.graphics.Bitmap; import android.net.Uri; import android.os.Bundle; import android.os.ParcelFileDescriptor; import android.provider.MediaStore; import android.view.View; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView;

    import com.chaquo.python.PyObject; import com.chaquo.python.Python; import com.chaquo.python.android.AndroidPlatform;

    import org.beyka.tiffbitmapfactory.TiffBitmapFactory;

    import java.io.FileNotFoundException; import java.util.ArrayList;

    public class MainActivity extends AppCompatActivity {

    TextView textView8;
    
    //private static final int Read_Permission= 101;
    
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        Button gallery = findViewById(R.id.gallery);
        gallery.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
               startActivityForResult(intent,3);
            }
        });
    
    
        /*if (ContextCompat.checkSelfPermission(MainActivity.this,
                Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
    
            ActivityCompat.requestPermissions(MainActivity.this,
                    new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, Read_Permission);
        }
    

    */

        textView8 = (TextView) findViewById(R.id.textView8);
    
        if(!Python.isStarted()){
            Python.start(new AndroidPlatform(this));
        }
    
        Python py = Python.getInstance();
        PyObject pyobj = py.getModule("hello");
        // give python script name
        // now call this function
        PyObject obj = pyobj.callAttr("main");
        // now set return text to textview
        textView8.setText(obj.toString());
    
    
    
    }
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    
        super.onActivityResult(requestCode, resultCode, data);
        if(resultCode == RESULT_OK && data != null){
            try {
    
                // from the Beyla original code
                ParcelFileDescriptor parcelFileDescriptor = getContentResolver().openFileDescriptor(data.getData(), "r");
                Bitmap bmp = TiffBitmapFactory.decodeFileDescriptor(parcelFileDescriptor.getFd());
    
                ImageView imageView = findViewById(R.id.imageView);
                imageView.setImageBitmap(bmp);
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
           // Uri selectedImage = data.getData();
           // ImageView imageView = findViewById(R.id.imageView);
           // imageView.setImageURI(selectedImage);
        }
    }
    

    }

    activity_main.xml

    <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" tools:ignore="MissingClass">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:layout_centerInParent="true"
        tools:layout_editor_absoluteX="80dp"
        tools:layout_editor_absoluteY="194dp"
        tools:ignore="MissingConstraints" />
    
    <Button
        android:id="@+id/gallery"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="Pick Image"
        tools:ignore="MissingConstraints"
        tools:layout_editor_absoluteX="125dp"
        tools:layout_editor_absoluteY="556dp" />
    
    <TextView
        android:id="@+id/textView8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="33dp"
        android:text="TextView"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.436"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/pick"
        app:layout_constraintVertical_bias="0.2"
        tools:ignore="MissingConstraints" />
    

    </androidx.constraintlayout.widget.ConstraintLayout>

    3 条回复    2022-11-16 03:52:07 +08:00
    momosolaris
        1
    momosolaris  
    OP
       2022-11-15 07:07:54 +08:00
    kop1989smurf
        2
    kop1989smurf  
       2022-11-15 09:02:20 +08:00
    .tif 文件不能在原生图片选择器中预览(当然你可以自己实现一个,就可以预览了)
    除了以上,这个流程没什么问题。
    momosolaris
        3
    momosolaris  
    OP
       2022-11-16 03:52:07 +08:00
    @kop1989smurf 谢谢你的回答,我也查了一下,确实不能在 app 里呈现。我只能把它转成 png 的形式。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5384 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 09:22 · PVG 17:22 · LAX 02:22 · JFK 05:22
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.