我有一个列表视图,每行有几个图像按钮.单击列表行时,将启动新活动.由于相机布局有问题,我不得不建立自己的标签.为结果启动的活动是地图.如果我单击我的按钮启动图像预览(从SD卡加载图像),应用程序将从活动返回到活动返回到listview结果处理程序以重新启动我的新活动,这只是一个图像小部件.
列表视图上的图像预览正在使用光标和ListAdapter.这使得它非常简单,但我不确定如何放置一个经过调整大小的图像(即小的像素大小不像动态src图像按钮那样.所以我只是调整了从手机摄像头下来的图像.
问题是当我试图返回并重新启动第二个活动时,我收到内存不足错误.
这是更好的,因为我还需要对每行中的小部件/元素的属性进行一些更改,因为焦点问题我无法选择带触摸屏的行.(我可以用滚球.)
一旦我在列表视图上禁用了图像,它再次正常工作.
仅供参考:这就是我的做法:
String[] from = new String[] { DBHelper.KEY_BUSINESSNAME,DBHelper.KEY_ADDRESS,DBHelper.KEY_CITY,DBHelper.KEY_GPSLONG,DBHelper.KEY_GPSLAT,DBHelper.KEY_IMAGEFILENAME + ""};
int[] to = new int[] {R.id.businessname,R.id.address,R.id.city,R.id.gpslong,R.id.gpslat,R.id.imagefilename };
notes = new SimpleCursorAdapter(this, R.layout.notes_row, c, from, to);
setListAdapter(notes);
Run Code Online (Sandbox Code Playgroud)
哪里R.id.imagefilename是ButtonImage.
这是我的LogCat:
01-25 05:05:49.877: ERROR/dalvikvm-heap(3896): 6291456-byte external allocation too large for this process.
01-25 05:05:49.877: ERROR/(3896): VM wont let us allocate 6291456 bytes
01-25 05:05:49.877: ERROR/AndroidRuntime(3896): Uncaught handler: thread main exiting due to …Run Code Online (Sandbox Code Playgroud) 有人能告诉我将图像(最大200KB)转换为Base64字符串的代码吗?
我需要知道如何使用android,因为我必须添加上传图像的功能到我的主应用程序中的远程服务器,将它们作为字符串放入数据库的一行.
我在谷歌和StackOverflow中搜索,但我找不到我能负担得起的简单示例,而且我找到了一些例子,但他们并没有谈到转换成字符串.然后我需要转换为字符串以通过JSON上传到我的远程服务器.
我在Android的编程新和我,说我的应用程序运行的内存,这所示例我从一本书上抄,它正在与小图片的分辨率,但一个错误,当我加了几张照片具有更大的分辨率出来出现内存错误,可能是我做错了或者只是不知道我还应该使用图像,如果有人知道我应该改变什么,以便这个错误不再出现,请求帮助.谢谢期待!
源代码:
public class ImageViewsActivity extends Activity {
//the images to display
Integer[] imageIDs={
R.drawable.pic1,
R.drawable.pic2,
R.drawable.pic3,
R.drawable.pic4,
R.drawable.pic5
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final ImageView iv=(ImageView) findViewById(R.id.image1);
Gallery gallery=(Gallery) findViewById(R.id.gallery);
gallery.setAdapter(new ImageAdapter(this));
gallery.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> parent, View v, int position, long id){
Toast.makeText(getBaseContext(), "pic"+(position+1)+" selected", Toast.LENGTH_SHORT).show();
//display the image selected
try{iv.setScaleType(ImageView.ScaleType.FIT_CENTER);
iv.setImageResource(imageIDs[position]);}catch(OutOfMemoryError e){
iv.setImageBitmap(null);
}
}
});
}
public class ImageAdapter extends BaseAdapter{
private …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我遇到了一个小问题,即将图像编码和解码为String并将其传递给Web服务.获取位图图像后,我将其转换为byte []并编码为String值但在某些情况下它显示错误我不知道它为什么会出现.还有一个疑问是Base64类仅支持将Bitmap图像转换为String或任何其他可用的工具.
提前致谢...
基本上我是为Android 4.4.2锁屏背景添加一个壁纸选择器,当图像设置后我关闭屏幕然后重新开启以查看锁屏我的屏幕变黑并且logcat给我一个内存不足分配错误.到目前为止,我已经尝试使用Bitmap decodeFile(String pathName),我也重新使用Bitmap decodeFile(String pathName,Options opts),但结果是每次都相同...
以下是用于设置图像的原始方法:
private static final String WALLPAPER_IMAGE_PATH =
"/data/data/com.android.settings/files/lockscreen_wallpaper.png";
private KeyguardUpdateMonitorCallback mBackgroundChanger = new KeyguardUpdateMonitorCallback() {
@Override
public void onSetBackground(Bitmap bmp) {
if (bmp != null) {
mKeyguardHost.setCustomBackground(
new BitmapDrawable(mContext.getResources(), bmp));
}
else {
File file = new File(WALLPAPER_IMAGE_PATH);
if (file.exists()) {
mKeyguardHost.setCustomBackground(
new BitmapDrawable(mContext.getResources(), WALLPAPER_IMAGE_PATH));
}
else {
mKeyguardHost.setCustomBackground(null);
}
}
updateShowWallpaper(bmp == null);
}
};
Run Code Online (Sandbox Code Playgroud)
这是从案例1中调用的:
public void setCustomBackground(Drawable d) {
if (!mAudioManager.isMusicActive()) {
int mBackgroundStyle = Settings.System.getInt(mContext.getContentResolver(),
Settings.System.LOCKSCREEN_BACKGROUND_STYLE, 2);
int mBackgroundColor …Run Code Online (Sandbox Code Playgroud)