私のアプリでは、SDカードから特定の位置に画像を取得したいので、ギャラリーに表示する必要があります.
私が使用したコードは添付されています
private Gallery gallery;
private ImageView imgView;
int position;
private byte[] data = { };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gridview);
try{
String filepath = "/sdcard/data/Crak/";
File imagefile = new File(filepath +"abcd.jpg" );
FileInputStream fis = new FileInputStream(imagefile);
Bitmap bi = BitmapFactory.decodeStream(fis);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
System.out.println("cnvrtn");
}
catch(Exception e) {
e.printStackTrace();
}
final Bitmap bitmapimage = BitmapFactory.decodeByteArray(data, 0, data.length);
position = 0;
imgView = (ImageView) findViewById(R.id.ImageView01);
imgView.setImageBitmap(bitmapimage);
gallery = (Gallery) findViewById(R.id.examplegallery);
gallery.setAdapter(new AddImgAdp(this));
gallery.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView parent, View v, int position,
long id) {
imgView.setImageBitmap(bitmapimage);
DisplayImage.this.position = position;
}
});
System.out.println("Enter the activity//////////");
imgView.setOnClickListener(new View.OnClickListener() {
@SuppressWarnings("deprecation")
@Override
public void onClick(View paramView) {
// TODO Auto-generated method stub
}
});
}
public class AddImgAdp extends BaseAdapter {
int GalItemBg;
private Context cont;
@SuppressWarnings("null")
public AddImgAdp(Context c) {
cont = c;
TypedArray typArray = obtainStyledAttributes(R.styleable.GalleryTheme);
GalItemBg = typArray.getResourceId(
R.styleable.GalleryTheme_android_galleryItemBackground, 0);
typArray.recycle();
}
public int getCount() {
return data.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imgView = new ImageView(cont);
final Bitmap bitmapimage = BitmapFactory.decodeByteArray(data, 0, data.length);
imgView.setImageBitmap(bitmapimage);;
imgView.setLayoutParams(new Gallery.LayoutParams(100, 100));
imgView.setScaleType(ImageView.ScaleType.FIT_XY);
imgView.setBackgroundResource(GalItemBg);
return imgView;
}
}
問題は
1)SDカードの特定のフォルダにあるすべての画像を取得するにはどうすればよいですか
2)GalleryViewが不定または終わりのない長いものです