首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在recipe android顶部打印徽标

在recipe android顶部打印徽标
EN

Stack Overflow用户
提问于 2015-12-30 20:34:02
回答 2查看 148关注 0票数 0

大家好,我有一个问题,我想在我的项目中包含一个图像,当用户单击打印按钮时,图像将被打印出来,后面跟着其他信息,但我没有让它将图像路径传递到PrintTool

代码语言:javascript
复制
PrintTool.printPhotoWithPath(imagePath, this);

printtool中的第一行是

代码语言:javascript
复制
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");
    }
}

所以我的问题是,我如何才能获得从可绘制文件夹中的图像到代码的路径?

EN

回答 2

Stack Overflow用户

发布于 2015-12-30 20:38:55

请删除此行

代码语言:javascript
复制
File mfile = new File(filePath/*path*/);

假设图像当前在您的可绘制目录中,您可以像这样获取它:

代码语言:javascript
复制
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替换为您的绘图文件的名称。

如果需要位图的路径,则默认情况下为

代码语言:javascript
复制
String imageUri = "drawable://" + R.drawable.image;

Refer to this.

票数 0
EN

Stack Overflow用户

发布于 2015-12-30 20:45:49

我希望这对你有帮助

代码语言:javascript
复制
File file  = new File(String.valueOf(R.mipmap.imgeName));
        file.getPath();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34529665

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档