我正在使用一个新线程来发送文件,并使用一些代码片段将位图转换为文件。从位图到文件的转换真的很慢,似乎将信息发送到 clarifai 并没有做任何事情......
//Convert bitmap to byte array
Bitmap bitmap = mResultsBitmap;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 0 /*ignored for PNG*/, bos);
byte[] bitmapdata = bos.toByteArray();
//write the bytes in file
FileOutputStream fos = null;
try {
fos = new FileOutputStream(f);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
try {
fos.write(bitmapdata);
} catch (IOException e) {
e.printStackTrace();
}
try {
fos.flush();
} catch (IOException e) {
e.printStackTrace();
}
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
final File pFIle2 = f;
//TODO: clarifai stuff
//TODO: clarifai stuff
Log.e("this:"," this is running 0");
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
Log.e("this:", " this is running 1");
client = new ClarifaiBuilder("mykeyhere1234}").buildSync();
Log.e("this:", " this is running 2");
Thread th = new Thread(new Runnable() {
@Override
public void run() {
Log.e("this:", " this is running 3");
Log.e("this", client.getDefaultModels().generalModel().predict()
.withInputs(
ClarifaiInput.forImage(ClarifaiImage.of(pFIle2))
)
.executeSync().rawBody());
Log.e("this:", " this is running 4");
}
});
}
});
这段代码片段在 onActivityResult 方法中。除了“0”之外,没有任何日志消息正在打印