-1
私はMySqlに画像を挿入するプログラマーをAndroidスタジオに持っていますが、この画像を取得できるJavaFxのプログラムもあります。 DBはすべて動作しますが、スマートフォンから挿入した場合、JavaFxプログラムは自分のイメージを表示しません。それは何でしょうか?スマートフォンが非常に正しい方法で書くことはできませんが、どのJavaFxで読むことができませんか? JavaFXの中DBから画像を取得してjavaFXに表示
私のクラス:Android用
public class sample {
public void sample() throws SQLException, IOException {
ConnectionHelper ch=new ConnectionHelper();
ch.Connect();
String q="SELECT IMG FROM img_ins WHERE img_ins.id_booked_proj='21'";
Statement st=ch.con.createStatement();
ResultSet rs = st.executeQuery(q);
if (rs.next()) {
InputStream is= null;
try {
is = rs.getBinaryStream("IMG");
} catch (SQLException e) {
e.printStackTrace();
}
OutputStream os=new FileOutputStream(new File("img.jpg"));
byte [] content= new byte[1024];
int size=0;
while ((size=is.read(content))!=-1){
os.write(content, 0, size);
}
System.out.println(is.read(content));
os.close();
is.close();
javafx.scene.image.Image image1=new Image("file:img.jpg", Panel.image.getFitWidth(), Panel.image.getFitHeight(), true, true);
Panel.image.setImage(image1);
}
}}
私のクラス:
protected void onActivityResult(int requestCode, int resultCode, Intent
data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==RESULT_LOAD_IMAGE && resultCode==RESULT_OK && null!=data){
Bitmap originBitmap = null;
Uri selectedImage = data.getData();
InputStream imageStream;
try {
imageStream=getContentResolver().openInputStream(selectedImage);
originBitmap = BitmapFactory.decodeStream(imageStream);
} catch (FileNotFoundException e) {
textView.setText(e.getMessage().toString());
}
if (originBitmap!=null){
this.up.setImageBitmap(originBitmap);
Bitmap image= ((BitmapDrawable) up.getDrawable()).getBitmap();
ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
encodedImage= Base64.encodeToString(byteArrayOutputStream.toByteArray(), Base64.DEFAULT);
MyTask myTask=new MyTask();
myTask.execute("");
}
}
}
アンドロイドに画像を挿入する私の方法:あなたは、データベース内の画像を直接保存することができ
protected String doInBackground(String... params) {
String msq="";
try {
if (connection==null){
msq="connection is wrong, check the Internet permission";
}
else {
String sql = "Insert img_ins(IMG, id_booked_proj) values ('"+encodedImage+"', '"+mmA.C+"')";
PreparedStatement preSt = connection.prepareStatement(sql);
preSt.executeUpdate();
msq="Inserted successfully";
}} catch (SQLException ex) {
msq=ex.getMessage().toString();
Log.d("sql error 1", msq);
}
return msq;
}
? JavaFXPorts? Gluonプラグイン? –
@JoséPeredano)これは、JavaFxアプリとして作成されたものと、Anroidスタジオで作成されたものの2つの異なるプログラムです。 – Roshki
AndroidプロジェクトではそのままJavaFX *を使用しようとしていますか? –