Recently, I have been working on an OpenCV app for visible light positioning on Android. While contour recognition, I accidentally used a 2D image from my phone as a sample for testing and found that the lines were very clear, just like the image below:
Isn't this a line draft? Maybe I can create an app that can convert images into line drafts with just one click. It might be useful in the future and also convenient for art enthusiasts.
So, I made a copy of my visible light positioning project, changed the package name, logo, and background image, and then redesigned the UI. I added a long-press function to save the image and performed various tests and debugging. In just two days, I successfully created a stable version. Finally, I released the app and project on my Gitee repository.
Key parts of the code:#
Save image:#
// Save image on long press
public static void saveBitmap(ImageView view, String filePath) {
Drawable drawable = view.getDrawable();
if (drawable == null) {
return;
}
FileOutputStream outStream = null;
File file = new File(filePath);
if (file.isDirectory()) {
return;
}
try {
outStream = new FileOutputStream(file);
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (outStream != null) {
outStream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Refresh media gallery:#
// Refresh media gallery
private void updateGallery(String filename) {
MediaScannerConnection.scanFile(this,
new String[] { filename }, null,
new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
Log.i("ExternalStorage", "Scanned " + path + ":");
Log.i("ExternalStorage", "-> uri=" + uri);
}
});
}
Generate directory and random file name:#
// Generate random file name
private String generateFileName() {
String fileList = getExternalStorageDirectory().getAbsolutePath() + File.separator + "LineDraft" + File.separator;
File mkdir = new File(fileList);
if(!mkdir.exists()) mkdir.mkdir();
@SuppressLint("SimpleDateFormat") DateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
String formatDate = format.format(new Date());
int random = new Random().nextInt(10000);
return (fileList + formatDate + random + ".png");
}
Preview:
Welcome screen![]() | Main screen![]() | Conversion and save![]() |
Since only the ARM architecture of the OpenCV library is used, it runs smoothly on both Redmi Note 1 and Xiaomi 6X. Therefore, it is currently believed to support almost all Android smartphones. Compatibility with Android tablets is still unknown.