fix crash bug
parent
892c19130c
commit
7dd9bd8b64
@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2023. UnknownNetworkService Group
|
||||||
|
* This file is created by UnknownObject at 2023 - 6 - 17
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.uns.maincar.tools;
|
||||||
|
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.os.Environment;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
|
||||||
|
public class ImageSaver
|
||||||
|
{
|
||||||
|
private final String main_storage_path = Environment.getExternalStorageDirectory().getPath() + File.separator + "MainCar";
|
||||||
|
private final String storage_path = main_storage_path + File.separator + "Temp_OCR_Image";
|
||||||
|
private String saved_file;
|
||||||
|
|
||||||
|
private boolean PrepareDirectory()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File main_dir = new File(main_storage_path);
|
||||||
|
File cl_dir = new File(storage_path);
|
||||||
|
if (!main_dir.exists())
|
||||||
|
if (!main_dir.mkdirs())
|
||||||
|
return false;
|
||||||
|
if (!cl_dir.exists())
|
||||||
|
if (!cl_dir.mkdirs())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean CopyImage(Bitmap img, String storage_path, String file_name)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
saved_file = storage_path + File.separator + file_name;
|
||||||
|
File dir = new File(storage_path);
|
||||||
|
File file = new File(saved_file);
|
||||||
|
if (!dir.exists())
|
||||||
|
{
|
||||||
|
if (!dir.mkdirs())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (file.exists())
|
||||||
|
if (!file.delete())
|
||||||
|
return false;
|
||||||
|
FileOutputStream fos = new FileOutputStream(saved_file);
|
||||||
|
img.compress(Bitmap.CompressFormat.JPEG, 100, fos);
|
||||||
|
fos.flush();
|
||||||
|
fos.close();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean SaveImage(Bitmap img, String file_name)
|
||||||
|
{
|
||||||
|
if (PrepareDirectory())
|
||||||
|
return CopyImage(img, storage_path, file_name);
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String GetSavedFilePath()
|
||||||
|
{
|
||||||
|
return saved_file;
|
||||||
|
}
|
||||||
|
}
|
@ -1,2 +1,4 @@
|
|||||||
# C/C++ build system timings
|
# C/C++ build system timings
|
||||||
|
|
||||||
|
# C/C++ build system timings
|
||||||
|
|
||||||
|
@ -1,2 +1,4 @@
|
|||||||
# C/C++ build system timings
|
# C/C++ build system timings
|
||||||
|
|
||||||
|
# C/C++ build system timings
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
#Sat Sep 24 22:46:46 CST 2022
|
#Sat Jun 17 20:58:02 CST 2023
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue