图片显示问题

gesanri 2009-11-18 10:33:12
现在要显示从网络上下载的图片,我找了个程序,发现用程序那个url的图片就能显示,但我把url换成我要显示的图片却看不见,不知为何

完整程序如下:
ActivityMain.java

package com.TestImg;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.Button;
import android.widget.ImageView;

public class ActivityMain extends Activity {
/** Called when the activity is first created. */

String imageUrl = "http://i.pbase.com/o6/92/229792/1/80199697.uAs58yHk.50pxCross_of_the_Knights_Templar_svg.png";
Bitmap bmImg;
ImageView imView;

Button button1;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imView = (ImageView) findViewById(R.id.imview);
imView.setImageBitmap(returnBitMap(imageUrl));
}

public Bitmap returnBitMap(String url) {
URL myFileUrl = null;
Bitmap bitmap = null;

try {
myFileUrl = new URL(url);
} catch (MalformedURLException e) {
e.printStackTrace();
}

try {
HttpURLConnection conn = (HttpURLConnection)myFileUrl.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
bitmap = BitmapFactory.decodeStream(is);
is.close();
} catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}
}



AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.TestImg" android:versionCode="1"
android:versionName="1.0.0">
<uses-permission android:name="android.permission.INTERNET" />
<application android:icon="@drawable/icon"
android:label="@string/app_name">
<activity android:name=".ActivityMain"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>



main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<ImageView android:id="@+id/imview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>


这个程序是可以正确显示的,但我把url换成http://www.9251.com/DownLoad/File/Game/Part/PreViewFile/mini_幻剑奇侠之鬼城风云.jpg,就看不到我要看的图片了,不知为何,这个链接地址在IE中也是有图的
...全文
221 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
gesanri 2009-11-18
  • 打赏
  • 举报
回复
既然解决了,我问个别的问题吧,我要存储一些值,应用打开的时候就自动读取这些值并显示在屏幕上,在j2me中是用rms,我不知道android是用什么?难道要写文件里去吗,写文件的话保存在哪个路径呢
gesanri 2009-11-18
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 zhouyongyang 的回复:]
android中不支持.jpg的图片
图片名称中不能出现中文
[/Quote]
。。。 不是吧,我解决了,进行url编码就好了,确实不能为中文,但支持jpg
zhouyongyang 2009-11-18
  • 打赏
  • 举报
回复
android中不支持.jpg的图片
图片名称中不能出现中文
yili_xie 2009-11-18
  • 打赏
  • 举报
回复
显示不出来无外乎两个问题,一个是没取到图片,二就是取到的图片没法解析~~
yili_xie 2009-11-18
  • 打赏
  • 举报
回复
呵呵,没时间帮你调试~~但你可以打几个log看问题出在哪里
1、 InputStream is = conn.getInputStream();
bitmap = BitmapFactory.decodeStream(is);
看取过来的图是否有值,或者是NULL~~
2、看是不是图片格式的问题~~
kinghua_q 2009-11-18
  • 打赏
  • 举报
回复
public class Bmi extends Activity {
private static final String TAG= "Bmi";
public static final String PREF= "BMI_PREF";
public static final String PREF_HEIGHT= "BMI_Height";
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
findViews();
restorePrefs();
setListensers();
} private void restorePrefs(){ // Restore preferences
SharedPreferences settings= getSharedPreferences(PREF, 0);
String pref_height= settings.getString(PREF_HEIGHT, "");
if(pref_height!=""){
field_height.setText(pref_height);
field_weight.requestFocus(); }
} @
Override
protected void onStop(){
super.onStop();
// Save user preferences. use Editor object to make changes.
SharedPreferences settings= getSharedPreferences(PREF, 0);
settings.edit().putString(PREF_HEIGHT,
field_height.getText().toString()).commit();
}}

private void restorePrefs(){ // Restore preferences
SharedPreferences settings= getSharedPreferences(PREF, 0);
String pref_height= settings.getString(PREF_HEIGHT, "");
if(pref_height!=""){
field_height.setText(pref_height);
field_weight.requestFocus();} }

这有个例子
kinghua_q 2009-11-18
  • 打赏
  • 举报
回复
没有什么限制
gesanri 2009-11-18
  • 打赏
  • 举报
回复
SharedPreference的限制是什么,比如大小,个数等等
biaozai06 2009-11-18
  • 打赏
  • 举报
回复
如果值相对简单的话可以用SharedPreference

80,362

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧