Android GridView'a Kameradan Çekilen Resimi Atma
14.12.2017 - 07:43
Merhabalar. Programımda kameradan çektiğim resmi anlık olarak sayfamdaki gridview'a aktarmak istiyorum. Kodlarım şu şekilde:
public class Detaylar extends AppCompatActivity implements View.OnClickListener {
Button btn_fotoekle;
Integer list[]={1,2,3,4,5,6,7,8,9,10};
GridView gridView;
int[] images={R.drawable.kitap,R.drawable.kitap,R.drawable.kitap,R.drawable.kitap,R.drawable.kitap,R.drawable.kitap};
byte [] arr;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detaylar);
Intent intent = getIntent();
this.setTitle(intent.getStringExtra("mesaj").toString());
btn_fotoekle = (Button) findViewById(R.id.btn_fotocek);
btn_fotoekle.setOnClickListener(this);
gridView = (GridView) findViewById(R.id.mygridview);
Toast.makeText(this,images[1],Toast.LENGTH_LONG).show();
}
@Override
public void onClick(View v) {
Intent kamera=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(kamera,33);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode==33){
Bitmap image=(Bitmap)data.getExtras().get("data");
ImageView resim= new ImageView(this);
resim.setImageBitmap(image);
Toast.makeText(this,data.getExtras().get("data").toString(),Toast.LENGTH_LONG).show();
ImageAdapter imgadapter = new ImageAdapter(this,image);
gridView.setAdapter(imgadapter);
//gridView.addView(resim);
}
// super.onActivityResult(requestCode, resultCode, data);
}
}
public class ImageAdapter extends BaseAdapter {
Context c;
Bitmap bitmap;
public ImageAdapter(Context c,Bitmap bitmap) {
this.c=c;
this.bitmap=bitmap;
}
public int getCount() {
return 0;
}
@Override
public Object getItem(int position) {
return 0;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView img = new ImageView(c);
img.setLayoutParams(new GridView.LayoutParams(340,340));
img.setScaleType(ImageView.ScaleType.CENTER_CROP);
img.setImageBitmap(bitmap);
return img;
}
}
7
Görüntülenme
0 Beğeni