Java 图像未显示在库中
我从图像视图中获取图像并将其转换为位图,然后将其保存到目录中。图像已成功保存在我的目录中,但未显示在galley中 我在同一个目录中有一些其他的图片,这些图片是在从相机拍摄后保存的,并且是可见的。我只需保存Java 图像未显示在库中,java,android,image,file,gallery,Java,Android,Image,File,Gallery,我从图像视图中获取图像并将其转换为位图,然后将其保存到目录中。图像已成功保存在我的目录中,但未显示在galley中 我在同一个目录中有一些其他的图片,这些图片是在从相机拍摄后保存的,并且是可见的。我只需保存ImageView中的图像,并将其存储到一个目录中,然后在下一个屏幕中,我只想使用保存的图像获取信息 textToImage()方法用于创建编码图像 Bitmap TextToImageEncode(String Value) throws WriterException {
ImageView
中的图像,并将其存储到一个目录中,然后在下一个屏幕中,我只想使用保存的图像获取信息
textToImage()
方法用于创建编码图像
Bitmap TextToImageEncode(String Value) throws WriterException {
BitMatrix bitMatrix;
try {
bitMatrix = new MultiFormatWriter().encode(
Value,
BarcodeFormat.DATA_MATRIX.QR_CODE,
QRcodeWidth, QRcodeWidth, null
);
} catch (IllegalArgumentException Illegalargumentexception) {
return null;
}
int bitMatrixWidth = bitMatrix.getWidth();
int bitMatrixHeight = bitMatrix.getHeight();
int[] pixels = new int[bitMatrixWidth * bitMatrixHeight];
for (int y = 0; y < bitMatrixHeight; y++) {
int offset = y * bitMatrixWidth;
for (int x = 0; x < bitMatrixWidth; x++) {
pixels[offset + x] = bitMatrix.get(x, y) ?
getResources().getColor(R.color.QRCodeBlackColor) : getResources().getColor(R.color.QRCodeWhiteColor);
}
}
Bitmap bitmap = Bitmap.createBitmap(bitMatrixWidth, bitMatrixHeight, Bitmap.Config.ARGB_4444);
bitmap.setPixels(pixels, 0, 500, 0, 0, bitMatrixWidth, bitMatrixHeight);
if (bitmap != null)
saveImageToSdCard(bitmap);
} else {
Log.e("Test data image or not", "No bitmap given");
}
return bitmap;
}
只有在成功将图像保存到文件后,您才应该调用媒体扫描仪。此外,您还可以对我在处理相同问题的其他帖子上的评论作出反应。如果您请求帮助,则在得到帮助时做出反应。此外,您仍然没有检查返回值。不想学点什么吗?@greenapps我已经用saveImageToSdCard(位图位图位图1)方法返回了文件,但仍然没有显示在我的图库中。但是这个方法在我的代码中打印文件路径。我的问题仍然存在。我无法通过gallery获取存储的图像。存储的图像显示在我的目录中,但当我想从图库中选择它时不显示。您仍然对我的评论没有反应。如果这种情况持续下去,我怎么能帮你呢?只有在成功将图像保存到文件后,你才应该调用媒体扫描仪。此外,你还可以对我在处理相同问题的其他帖子上的评论作出反应。如果您请求帮助,则在得到帮助时做出反应。此外,您仍然没有检查返回值。不想学点什么吗?@greenapps我已经用saveImageToSdCard(位图位图位图1)方法返回了文件,但仍然没有显示在我的图库中。但是这个方法在我的代码中打印文件路径。我的问题仍然存在。我无法通过gallery获取存储的图像。存储的图像显示在我的目录中,但当我想从图库中选择它时不显示。您仍然对我的评论没有反应。如果这一切持续下去,我怎么能帮助你呢?
public void saveImageToSdCard(Bitmap bitmap1) {
File sdCard = Environment.getExternalStorageDirectory();
String ExternalStorageDirectoryPath = Environment
.getExternalStorageDirectory()
.getAbsolutePath();
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
Locale.getDefault()).format(new Date());
if (sdCard != null) {
> Create the directory here with path
File directory = new File(ExternalStorageDirectoryPath+"/My App");
if (directory.exists()) {
directory.delete();
Log.e("it run", "directory is exists");
}
directory.mkdirs();
String strImageName = File.separator + "IMG_" + timeStamp + ".jpg";
File file = new File(directory, strImageName);
// strFinalImage = file.getAbsolutePath();
// Log.e(TAG + "strFinalImage22", strFinalImage + "");
> here we just scan the media
MediaScannerConnection.scanFile(getActivity(),
new String[] { file.toString() }, null,
new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
Log.e("ExternalStorage", "Scanned " + path + ":");
Log.e("ExternalStorage", "-> uri=" + uri);
}
});
FileOutputStream fileOutputStream = null;
try {
fileOutputStream = new FileOutputStream(file);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap1.compress(Bitmap.CompressFormat.JPEG, 60, bytes);
fileOutputStream.write(bytes.toByteArray());
fileOutputStream.flush();
fileOutputStream.close();
// Toast.makeText(MainActivity.this, "Saved", Toast.LENGTH_SHORT).show();
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
} else {
Toast.makeText(getActivity(), "Sd card mount", Toast.LENGTH_SHORT).show();
}
}