1

Webサービスによって丁寧に提供されたデータセットから取得したbase64文字列を画像に変換し、その後グリッドビューに表示することに問題があります。

Web サービスからの受信データ

<NewDataSet xmlns="">
    <AvailableUsers diffgr:id="AvailableUsers1" msdata:rowOrder="0">
        <sUserId>1</sUserId>
        <UserDesc>Mr. Someone</UserDesc>
    </AvailableUsers>
    <AvailableUsers diffgr:id="AvailableUsers2" msdata:rowOrder="1" diffgr:hasChanges="modified">
        <sUserId>2</sUserId>
        <UserDesc>Mr. Someone 2</UserDesc>
        <UserIMG>
        // A base64 string is here but let's not bother ourselves with that here...
        </UserIMG>
    </AvailableUsers>
</NewDataSet>

マイ イメージ アダプター

class ImageAdapter : BaseAdapter
{
    Context context;

    public ImageAdapter(Context c)
    {
        context = c;
    }

    public override int Count
    {
        get { return thumbIds.Length; }
    }

    public override Java.Lang.Object GetItem(int position)
    {
        return null;
    }

    public override long GetItemId(int position)
    {
        return 0;
    }

    // create a new ImageView for each item referenced by the Adapter
    public override View GetView(int position, View convertView, ViewGroup parent)
    {
        ImageView imageView;

        if (convertView == null)
        {  // if it's not recycled, initialize some attributes
            imageView = new ImageView(context);
            imageView.LayoutParameters = new GridView.LayoutParams(150, 150);
            imageView.SetScaleType(ImageView.ScaleType.CenterCrop);
            imageView.SetBackgroundColor(Color.Aqua);
        }
        else
        {
            imageView = (ImageView)convertView;
        }

        imageView.SetImageResource(thumbIds[position]);
        return imageView;
    }

    int[] thumbIds = {
    Resource.Drawable.sample_0, Resource.Drawable.sample_1, Resource.Drawable.sample_2, Resource.Drawable.sample_3
};
}

ここで、私の現在の知識と理解が止まります(私はこの分野の初心者です-以前にいくつかのWeb関連と軽いJavaScriptを行いましたが、これと比較して何もありません). 私は丁寧に誰かに例を書いてもらうか、少なくともこの特定の問題に実際に手を出すチュートリアルを教えてくれるように頼むでしょう。

お時間をいただきありがとうございます。

4

2 に答える 2

0

listvew とカスタム配列アダプターを使用して問題を解決しました。

画像については:

string base64 = item.UserIMG;

if (item.UserIMG != null) // If there's actually a string inside item.UserIMG
{
    System.IO.Stream s = new MemoryStream(Convert.FromBase64String(base64));

    byte[] arr = Convert.FromBase64String(base64);
    Drawable img = Drawable.CreateFromStream(s, null);

    ImageView UserAvatar = view.FindViewById<ImageView>(Resource.Id.imgView);
    UserAvatar.SetImageDrawable(img);
 }
 else  // If item.UserIMG is "" or null
    {
       ImageView UserAvatar = view.FindViewById<ImageView>(Resource.Id.imgView);
    }   
于 2013-01-08T08:11:54.547 に答える
0

http://github.com/redth/wshlstを見ると、彼がそこで Base64 画像変換を使用していることがわかります。

具体的には、https://github.com/Redth/WshLst/blob/master/WshLst.MonoForAndroid/Views/EntryView.csおよび: https://github.com/Redth/WshLst/blob/master/WshLst.MonoForAndroid/を参照してください。 NativeConveters.cs

画像は、次のようなコードを使用して文字列から読み込まれます。

var bytes = System.Convert.FromBase64String(base64);
var drawable = BitmapFactory.DecodeByteArray(bytes, 0, bytes.Length);
于 2013-01-03T10:55:28.907 に答える