我正在开发一个Android应用程序,它应该将图像发送到我的ASP.NET Web服务,其中图像将保存为文件.我见过一对夫妇的方式做到这一点,我就这一个:将图像转换为字节数组- >字节数组转换为字符串- >使用KSOAP2字符串发送到Web服务- >接收字符串在Web服务 - >将其转换为字节数组 - > 将其另存为图像:
IVtest = (ImageView)findViewById(R.id.carticon);
BitmapDrawable drawable = (BitmapDrawable) IVtest.getDrawable();
Bitmap bitmap = drawable.getBitmap();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] data = baos.toByteArray();
ImageView image=new ImageView(this);
image.setImageBitmap(bmp);
String strBase64 = Base64.encode(data);
Run Code Online (Sandbox Code Playgroud)
然后我将strBase64发送到Web服务.在Web服务中我有这个:
public Image ConvertToImage(byte[] image)
{
MemoryStream ms = new MemoryStream(image);
Image returnImage = Image.FromStream(ms);
return returnImage;
}
[WebMethod]
public String UploadImage(String image, String name)
{
byte[] image_byte = Encoding.Unicode.GetBytes(image);
Image convertedImage = ConvertToImage(image_byte);
try {
convertedImage.Save(Server.MapPath("generated_image.jpg"), System.Drawing.Imaging.ImageFormat.Jpeg); …Run Code Online (Sandbox Code Playgroud) 我的应用程序中有一个Android评级栏,它只显示int评级.
例如:
float ratingValue = 1.5f;
myRatingBar.setRating(ratingValue);
Run Code Online (Sandbox Code Playgroud)
而且评级栏显示2颗全星.如何让它显示一个半星,或两个半?