2012-06-25 10 views
-1

从Java中开发的一些代码中想要在Android中使用的代码出现错误。如何转换在Android中使用的ImageIO.write(输入,文件,余弦)

ImageIO.write(input, file, cos) 

这些都是我在安卓下面的代码错误,代码工作中的Java: 的BufferedImage不能被解析为一个类型 的ImageIO不能得到解决

public void decryptFile(String key, String typeFile) throws InvalidKeyException, 
                  NoSuchAlgorithmException, 
                 InvalidKeySpecException, 
                  NoSuchPaddingException, 
                     IOException 
    { 

     DESKeySpec dks = new DESKeySpec(key.getBytes()); 
     SecretKeyFactory skf = SecretKeyFactory.getInstance("DES"); 
     SecretKey desKey = skf.generateSecret(dks); 
     Cipher pbeCipher = Cipher.getInstance("DES"); // DES/ECB/PKCS5Padding for SunJCE 

     pbeCipher.init(Cipher.DECRYPT_MODE, desKey);  


     // Decrypt the ciphertext and then print it out.  
     FileInputStream output = null; 

     File encryptedFile = new File(Environment.getExternalStorageDirectory() + "/images/Et1.jpg"); 
     File decryptedFile = new File(Environment.getExternalStorageDirectory() + "/images/Dt1.jpg"); 


     try 
     { 

     output = new FileInputStream(encryptedFile); 
     } 
     catch (FileNotFoundException e) 
     { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
     } 

    CipherInputStream cis = new CipherInputStream(output, pbeCipher); 
    BufferedImage input = null; 

    try 
    { 
     input = ImageIO.read(cis); 
    } 
    catch (IOException e) 
    { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

    FileOutputStream out = null; 

    try 
    { 
     out = new FileOutputStream(decryptedFile); 
    } 
    catch (FileNotFoundException e) 
    { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

    try 
    { 
     ImageIO.write(input,typeFile, out); 
    } 
    catch (IOException e) 
    { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

    try 
    { 
     cis.close(); 
    } 
    catch (IOException e) 
    { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 


    } 

回答

1

我有类似的问题,

import javax.sound.sampled.*; 

您需要找到相应的导入(可能是ImageIO) 并找到替换 对我来说是

import android.media.AudioFormat; 
import android.media.AudioRecord; 
import android.media.MediaRecorder; 

如果那不是的话,那么发表您的错误。
还要记住它不仅仅是切换导入的问题,我必须将代码移植到新库中。