Xamarin Android - Bitmap Drawables To Int Array For Viewpager
I am storing some images locally on the device as compressed bitmaps. To retrieve them i get them from their file path, decode them, and then store them as BitmapDrawables. I now
Solution 1:
I solved it by passing in a Bitmap array to the adapter in the end. Like this:
public class ViewFragmentAdapter: FragmentPagerAdapter
{
Bitmap[] imageArray;
public ViewFragmentAdapter (Android.Support.V4.App.FragmentManager fm, Bitmap[] imageArray)
: base (fm)
{
this.imageArray = imageArray;
}
public override int Count {
get { return imageArray.Length; }
}
public override Android.Support.V4.App.Fragment GetItem (int position)
{
return new viewerFragment(imageArray[position]);
}
}
public class viewerFragment: Android.Support.V4.App.Fragment
{
Bitmap bm;
public viewerFragment(Bitmap bitmap)
{
bm = bitmap;
}
public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
var view = inflater.Inflate (Resource.Layout.myExhibitHistoryItem, container, false);
var image = view.FindViewById<ImageView> (Resource.Id.exhibitImage);
image.SetImageBitmap (bm);
return view;
}
}
Post a Comment for "Xamarin Android - Bitmap Drawables To Int Array For Viewpager"