/ / Mainactivity based on a very simple connection to display a picture, but if the picture is a Chinese name, then it can not be displayed, how does this need to deal with in order to make it appear
public class GetAPictureFromInternetActivity extends Activity {
private EditText pathText;
private ImageView imageView;
@ Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.main);
pathText = (EditText) this.findViewById (R.id.path);
imageView = (ImageView) this.findViewById (R.id.imageView);
}
public void showimage (View v) {
String path = pathText.getText () toString ();.
try {
Bitmap bitmap = ImageService.getImage (path);
imageView.setImageBitmap (bitmap);
} Catch (Exception e) {
e.printStackTrace ();
Toast.makeText (getApplicationContext (), R.string.error, 1) show ();.
}
}
}
/ / Get the picture
public class ImageService {
/ **
* Get the picture
* @ Param path path
pictures* @ Return
* /
public static Bitmap getImage (String path) throws Exception {
URL url = new URL (path);
HttpURLConnection conn = (HttpURLConnection) url.openConnection ();
conn.setConnectTimeout (5000);
conn.setRequestMethod ("GET");
if (conn.getResponseCode () == 200) {
InputStream inStream = conn.getInputStream ();
Bitmap bitmap = BitmapFactory.decodeStream (inStream);
return bitmap;
/ * Byte [] data = StreamTool.read (inStream);
Bitmap bitmap = BitmapFactory.decodeByteArray (data, 0, data.length);
return bitmap; * /
}
return null;
}
}
public class StreamTool {
/ **
* Read data from the stream
* @ Param inStream
* @ Return
* /
public static byte [] read (InputStream inStream) throws Exception {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream ();
byte [] buffer = new byte [1024];
int len = 0;
while ((len = inStream.read (buffer))! = -1) {
outputStream.write (buffer, 0, len);
}
inStream.close ();
return outputStream.toByteArray ();
}
}
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
Design algorithms, downloaded in English, translated into Chinese in
Reply:
design algorithms? ? ? Well not readily available, the Chinese on the server, where to download the English ah
Reply:
You can build an English folder, which put Chinese pictures, compressed and then decompressed downloaded to the mobile terminal
Reply:
URL is regular, ah, Chinese, and special symbols are to be converted.
Reply:
While not help the landlord, but still top. . . .
Reply:
that each time you download a picture on the entire folder should get down ah? Transcoding Chinese characters has been resolved, thank you
Reply:
Thank you, ah, then find a way refers to the Chinese character can be transcoded
Reply:
ah thank you for this reason was conducted by dropping Kazakhstan
Reply:
I ask the landlord to solve this problem yet, I have encountered this problem? Seeking help! Thanks!
No comments:
Post a Comment