Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android中将测验从文本类型转换为图像类型?_Android - Fatal编程技术网

如何在android中将测验从文本类型转换为图像类型?

如何在android中将测验从文本类型转换为图像类型?,android,Android,这些问题属于文本类型 我想把它们变成问题类型的图像 在解释的意义上 我想成为一个形象的问题,而不是(5+2),(2+15),。。。。 有可能吗??? 我从安卓开始 public void onCreate(SQLiteDatabase db){ dbase=db; String sql=“创建不存在的表格”+表格任务+”(“ +密钥ID+“整数主键自动递增”+“密钥” +“文本,”+按键+答案+“文本,”+按键+选项+文本,” +按键“OPTB+”文本“+按键“OPTC+”文本)”; exec

这些问题属于文本类型 我想把它们变成问题类型的图像 在解释的意义上 我想成为一个形象的问题,而不是(5+2),(2+15),。。。。 有可能吗??? 我从安卓开始

public void onCreate(SQLiteDatabase db){
dbase=db;
String sql=“创建不存在的表格”+表格任务+”(“
+密钥ID+“整数主键自动递增”+“密钥”
+“文本,”+按键+答案+“文本,”+按键+选项+文本,”
+按键“OPTB+”文本“+按键“OPTC+”文本)”;
execSQL(sql);
添加问题();
//db.close();
}
私人问题{
问题q1=新问题(“5+2=?”、“7”、“8”、“6”、“7”);
这个问题(q1);
问题q2=新问题(“2+18=?”、“18”、“19”、“20”、“20”);
这个问题(q2);
问题q3=新问题(“10-3=?”、“6”、“7”、“8”、“7”);
这个问题(第三季度);
问题q4=新问题(“5+7=?”、“12”、“13”、“14”、“12”);
这个问题(第四季度);
问题q5=新问题(“3-1=?”、“1”、“3”、“2”、“2”);
这个问题(q5);
问题q6=新问题(“0+1=?”、“1”、“0”、“10”、“1”);
这个问题(q6);
问题q7=新问题(“9-9=?”、“0”、“9”、“1”、“0”);
这个问题(q7);
问题q8=新问题(“3+6=?”、“8”、“7”、“9”、“9”);
这个问题(q8);
问题q9=新问题(“1+5=?”、“6”、“7”、“5”、“6”);
这个问题(q9);
问题q10=新问题(“7-5=?”、“3”、“2”、“6”、“2”);
本.补充质询(q10);
问题q11=新问题(“7-2=?”、“7”、“6”、“5”、“5”);
本问题(q11);
问题q12=新问题(“3+5=?”、“8”、“7”、“5”、“8”);
本条问题(q12);
问题q13=新问题(“0+6=?”、“7”、“6”、“5”、“6”);
本问题(第13题);
问题q14=新问题(“12-10=?”、“1”、“2”、“3”、“2”);
本.补充质询(问题14);
问题15=新问题(“12+2=?”、“14”、“15”、“16”、“14”);
本.补充质询(第15题);
问题16=新问题(“2-1=?”、“2”、“1”、“0”、“1”);
本.补充质询(第16题);
问题17=新问题(“6-6=?”、“6”、“12”、“0”、“0”);
本.补充质询(第17题);
问题q18=新问题(“5-1=?”、“4”、“3”、“2”、“4”);
本.补充质询(第18题);
问题19=新问题(“4+2=?”、“6”、“7”、“5”、“6”);
本.补充质询(第19题);
问题q20=新问题(“5+1=?”、“6”、“7”、“5”、“6”);
这个问题(q20);
问题q21=新问题(“5-4=?”、“5”、“4”、“1”、“1”);
这个问题(问题21);
//结束
}
@凌驾
public void onUpgrade(SQLiteDatabase db、intoldv、intnewv){
//删除旧表(如果存在)
db.execSQL(“如果存在删除表”+表任务);
//再次创建表
onCreate(db);
}
//添加新问题
公共问题(问题探索){
//SQLiteDatabase db=this.getWritableDatabase();
ContentValues=新的ContentValues();
value.put(KEY_QUES,quest.getQUESTION());
value.put(KEY_ANSWER,quest.getANSWER());
value.put(KEY_OPTA,quest.getOPTA());
value.put(KEY_OPTB,quest.getOPTB());
value.put(KEY_OPTC,quest.getOPTC());
//插入行
insert(TABLE_QUEST,null,value);
}
公共列表getAllQuestions(){
List quesList=new ArrayList();
//选择所有查询
String selectQuery=“SELECT*FROM”+表格任务;
dbase=this.getReadableDatabase();
Cursor Cursor=dbase.rawQuery(selectQuery,null);
//循环遍历所有行并添加到列表
if(cursor.moveToFirst()){
做{
问题探索=新问题();
setID(cursor.getInt(0));
setquest.setQUESTION(cursor.getString(1));
setANSWER(cursor.getString(2));
setOPTA(cursor.getString(3));
setOPTB(cursor.getString(4));
setOPTC(cursor.getString(5));
添加(任务);
}while(cursor.moveToNext());
}
//返回任务列表
返回任务列表;
}

}
您有几种选择。其中一些:

使用地图 保留一张地图,其中关键点是数据库中的问题ID。映射中存储的每个键的值可以是图像视图(例如,作为资源加载)

在DB中添加字段 添加带有图像相对路径的字段,并为每个问题加载相应的图像

您可以将路径作为字符串存储在数据库中,然后按照以下方式恢复图像:

File imgFile = new  File("/path/of/image/image.jpg");

if(imgFile.exists()){

    Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());

    // This image view is defined as a resource.... just set the bitmap
    ImageView myImage = (ImageView) findViewById(R.id.anyImageView);
    myImage.setImageBitmap(myBitmap);

}

你有几个选择。其中一些:

使用地图 保留一张地图,其中关键点是数据库中的问题ID。映射中存储的每个键的值可以是图像视图(例如,作为资源加载)

在DB中添加字段 添加带有图像相对路径的字段,并为每个问题加载相应的图像

您可以将路径作为字符串存储在数据库中,然后按照以下方式恢复图像:

File imgFile = new  File("/path/of/image/image.jpg");

if(imgFile.exists()){

    Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());

    // This image view is defined as a resource.... just set the bitmap
    ImageView myImage = (ImageView) findViewById(R.id.anyImageView);
    myImage.setImageBitmap(myBitmap);

}
试试这个代码

Bitmap src = BitmapFactory.decodeResource(getResources(), R.drawable.yourimage); // the original file yourimage.jpg i added in resources
Bitmap dest = Bitmap.createBitmap(src.getWidth(), src.getHeight(), Bitmap.Config.ARGB_8888);

String yourText = "3+5 = ?";

Canvas cs = new Canvas(dest);
Paint tPaint = new Paint();
tPaint.setTextSize(35);
tPaint.setColor(Color.BLUE);
tPaint.setStyle(Style.FILL);
cs.drawBitmap(src, 0f, 0f, null);
float height = tPaint.measureText("yY");
float width = tPaint.measureText(yourText);
float x_coord = (src.getWidth() - width)/2;
cs.drawText(yourText, x_coord, height+15f, tPaint); // 15f is to put space between top edge and the text, if you want to change it, you can
try {
    dest.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(new File("/sdcard/ImageAfterAddingText.jpg")));
    // dest is Bitmap, if you want to preview the final image, you can display it on screen also before saving
} catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
此代码从自定义文本生成图像
不要忘记在清单文件中添加权限

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

试试这段代码

Bitmap src = BitmapFactory.decodeResource(getResources(), R.drawable.yourimage); // the original file yourimage.jpg i added in resources
Bitmap dest = Bitmap.createBitmap(src.getWidth(), src.getHeight(), Bitmap.Config.ARGB_8888);

String yourText = "3+5 = ?";

Canvas cs = new Canvas(dest);
Paint tPaint = new Paint();
tPaint.setTextSize(35);
tPaint.setColor(Color.BLUE);
tPaint.setStyle(Style.FILL);
cs.drawBitmap(src, 0f, 0f, null);
float height = tPaint.measureText("yY");
float width = tPaint.measureText(yourText);
float x_coord = (src.getWidth() - width)/2;
cs.drawText(yourText, x_coord, height+15f, tPaint); // 15f is to put space between top edge and the text, if you want to change it, you can
try {
    dest.compress(Bitmap.CompressFormat.JPEG, 100, new FileOutputStream(new File("/sdcard/ImageAfterAddingText.jpg")));
    // dest is Bitmap, if you want to preview the final image, you can display it on screen also before saving
} catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
此代码从自定义文本生成图像
不要忘记在清单文件中添加权限

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />


如何在字段中添加图像?什么不起作用???您必须调整代码以从文件系统加载映像,并从配置中获得正确的资源。这是一个如何加载图像并在ImageView中显示的示例。由于您没有发布代码,我无法做任何其他事情,请尝试给您一个示例……String sql=“如果不存在创建表”+TABLE\u QUEST+”(“+KEY\u ID+”整数主键自动递增“+KEY\u QUES+”字符串“+KEY\u ANSWER+”文本“+KEY\u OPTA+”文本“+KEY\u OPTB+”文本“+KEY\u OPTC+”文本“+”KEY\u IMAGE+BLOB)”;execSQL(sql);添加问题();//db.close();File KEY_QUES=新文件(“/path/of/image/image.jpg”);如果(KEY_QUES.exists()){Bitmap myBitmap=BitmapFactory.decodeFile(KEY_QUES.getAbsolutePath());ImageView myImage=(ImageView)findViewById(