大家好,我有一个问题,我想在我的项目中包含一个图像,当用户单击打印按钮时,图像将被打印出来,后面跟着其他信息,但我没有让它将图像路径传递到PrintTool
PrintTool.printPhotoWithPath(imagePath, this);printtool中的第一行是
public static void printPhotoWithPath(String filePath, Context context) {
// Get the picture based on the path
File mfile = new File(filePath/*path*/);
if (mfile.exists()) {
Bitmap bmp = BitmapFactory.decodeFile(filePath/*path*/);
byte[] command = decodeBitmap(bmp);
printPhoto(command, context);
}else{
Log.e("PrintTools_58mm", "the file isn't exists");
}
}所以我的问题是,我如何才能获得从可绘制文件夹中的图像到代码的路径?
发布于 2015-12-30 20:38:55
请删除此行
File mfile = new File(filePath/*path*/);假设图像当前在您的可绘制目录中,您可以像这样获取它:
if (mfile.exists()) {
Bitmap bmp = BitmapFactory.decodeFile(getResources(), R.drawable.<yourDrawableName>);
byte[] command = decodeBitmap(bmp);
printPhoto(command, context);
}else{
Log.e("PrintTools_58mm", "the file isn't exists");
}NB替换为您的绘图文件的名称。
如果需要位图的路径,则默认情况下为
String imageUri = "drawable://" + R.drawable.image;发布于 2015-12-30 20:45:49
我希望这对你有帮助
File file = new File(String.valueOf(R.mipmap.imgeName));
file.getPath();https://stackoverflow.com/questions/34529665
复制相似问题