在Couchbase lite中保存高分辨率图像

时间:2017-09-22 17:18:22

标签: android couchbase-lite

我正在拍照并在缓存中保存为图像。我还命名图像并保存名称以便稍后查找。

public class FragmentHome extends Fragment {
private SearchView search;
View view;
DatabaseReference dataRef;
private  FirebaseListAdapter<String> firebaseListAdapter;
ListView mListView;
private TextView text;
ArrayList<String> city=new ArrayList<String>();
private int i=0;
private String data,val,var;
ArrayAdapter<String> adapter;
ProgressBar progressBar;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable final Bundle savedInstanceState) {
    View v= inflater.inflate(R.layout.activity_fragment_home,container,false);
    if (container!=null){
        container.removeAllViews();
    }
    progressBar= (ProgressBar) v.findViewById(R.id.search_pro);
    search= (SearchView) v.findViewById(R.id.search);
    search.onActionViewExpanded();
    search.setIconified(false);
    search.setInputType(InputType.TYPE_NULL);
    search.setQueryHint("Search Docter By City Or Department");
    mListView= (ListView) v.findViewById(R.id.mList);
    mListView.setVisibility(View.INVISIBLE);
    dataRef=FirebaseDatabase.getInstance().getReference().child("Docters");
    adapter=new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, city);
    mListView.setAdapter(adapter);
    adapter.notifyDataSetChanged();
    dataRef.addChildEventListener(new ChildEventListener() {
        @Override
        public void onChildAdded(DataSnapshot dataSnapshot, String s) {
            data=dataSnapshot.child("city").getValue(String.class);
            val=dataSnapshot.child("department").getValue(String.class);
            if (!city.contains(data)){
                city.add(data);
            }
            if (!city.contains(val)){
                city.add(val);
            }
            search.setInputType(InputType.TYPE_CLASS_TEXT);
            progressBar.setVisibility(View.GONE);
            adapter.notifyDataSetChanged();

        }
        @Override
        public void onChildChanged(DataSnapshot dataSnapshot, String s) {
            data=dataSnapshot.child("city").getValue(String.class);
            val=dataSnapshot.child("department").getValue(String.class);
            city.add(data);
            city.add(val);
            city.add(var);
            adapter.notifyDataSetChanged();
        }

        @Override
        public void onChildRemoved(DataSnapshot dataSnapshot) {

        }

        @Override
        public void onChildMoved(DataSnapshot dataSnapshot, String s) {
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
    search.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String text) {

            return false;
        }

        @Override
        public boolean onQueryTextChange(String text) {
            if (!text.isEmpty()){
                adapter.notifyDataSetChanged();
            mListView.setVisibility(View.VISIBLE);
               adapter.getFilter().filter(text);
            }else{
                mListView.setVisibility(View.INVISIBLE);
            }
            return false;
        }

    });

    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String itemRef = (String) adapter.getItem(position);
            search.setVisibility(View.INVISIBLE);
            mListView.setVisibility(View.INVISIBLE);
            FragmentTransaction ft=getChildFragmentManager().beginTransaction();
            DocterList fragment=new DocterList();
            Bundle item=new Bundle();
            item.putString("item",itemRef);
            fragment.setArguments(item);
            ft.replace(R.id.activity_fragment_home,fragment);
            ft.addToBackStack(null);
            ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
            ft.commit();
        }
    });
    return v;
}

获取图像并另存为文档附件,图像名称存储在photos []数组中。

if ((requestCode == REQUEST_IMAGE_CAPTURE && resultCode == Activity.RESULT_OK)){
        Bitmap photo = (Bitmap) intent.getExtras().get("data");

        //save photo
        Date dTime = new Date();
        String pictureName = String.valueOf(dTime.getTime()).substring(1,10);
        // saved in internal program cache storage
        String extr = getCacheDir().toString();
        File myPath = new File(extr, "DVIR");

        if (!myPath.exists()) {
            myPath.mkdirs();
        }
        FileOutputStream fos;
        try {
            fos = new FileOutputStream(myPath + "/" + pictureName + ".png");
            assert photo != null;
            photo.compress(Bitmap.CompressFormat.PNG, 100, fos);
            fos.flush();
            fos.close();
            MediaStore.Images.Media.insertImage(getContentResolver(),
                    photo, myPath.getPath(), pictureName + ".png");

            photos.add(pictureName);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            Toast toast = Toast.makeText(getApplicationContext(),
                    String.valueOf(e), Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        } catch (Exception e) {
            e.printStackTrace();
            Toast toast = Toast.makeText(getApplicationContext(),
                    String.valueOf(e), Toast.LENGTH_SHORT);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }

当我检索照片时,400像素宽的图像会像素化。

有什么想法吗? 谢谢

0 个答案:

没有答案