optional default image if cannot find avatar

This commit is contained in:
Tommy Parnell
2014-01-26 04:14:15 -05:00
parent 9364a3e4ea
commit 8662b0a5ea
3 changed files with 9 additions and 9 deletions

View File

@@ -30,19 +30,22 @@ namespace GravatarWrapper
return sBuilder.ToString(); // Return the hexadecimal string.
}
public static Bitmap Request(string email, int size)
public static Bitmap Request(string email, int size, bool ShowDefaultImage)
{
var client = new RestClient("http://www.gravatar.com/avatar/" + HashEmailForGravatar(email));
var req = new RestRequest(Method.GET);
req.AddParameter("d", "%22%22" );
if (ShowDefaultImage) req.AddParameter("d", "%22%22" );
req.AddParameter("s", size);
var res = client.Execute(req);
if (res != null)
{
var imagebytes = res.RawBytes;
var ms = new MemoryStream(imagebytes);
return new Bitmap(ms);
//img.Save(@"c:\bmp.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
//IDisposable implementation
using (var ms = new MemoryStream(imagebytes))
{
return new Bitmap(ms);
}
}
return null;
}

View File

@@ -30,9 +30,6 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="RestSharp">
<HintPath>..\packages\RestSharp.104.4.0\lib\net4\RestSharp.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />