从asp.net核心上的其余服务将图像加载到imageview android

时间:2019-03-22 07:45:45

标签: android asp.net-core-mvc asp.net-core-webapi

我如何从asp.net核心上的rest服务将图像加载到android上的imageview。 在asp.net核心,我有控制器MyController和方法:

[Route("api/[controller]")]  
[ApiController]  
public class MyController  : ControllerBase  
{  
    // GET api/values  
    [HttpGet]  
    public IActionResult Get(string type)  
    {  
        Byte[] b;  
        if(type == null)  
        {  
            return NotFound();  
        }  

        Image image = DrawText("My Example: " + type, new Font(FontFamily.GenericSansSerif, 15), Color.DarkBlue, Color.Cornsilk);  
        b = ImageToByteArray(image);  //Simulate loading images from the database

        return File(b, "image/jpeg");  
    } 

    public byte[] ImageToByteArray(System.Drawing.Image imageIn)  
    {              
            MemoryStream ms = new MemoryStream();  
            imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);  
            return ms.ToArray();              
    }  
}

1 个答案:

答案 0 :(得分:0)

我找到答案:图片必须使用jpg或bmp格式,但不能使用jpeg