.tif 的图像可以直接在A ndroid studio 里面显示出来吗? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
momosolaris
V2EX    Android

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

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

    大家好,我这个菜鸟又来了。 我之前得到一个任务, 就是在 android studio 里面加载一个.tif 文件格式的图像, 然后进行一个图像转换( python   code 处理 image   tranformation ,比如 gaor 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     Solana     2624 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 28ms UTC 08:57 PVG 16:57 LAX 00:57 JFK 03:57
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86