Jos*_*eph -4 android listview android-imageview
我已经分配了一个 textview 和一个 ImageView 如下,
Text = (TextView) findViewById(R.id.TextView01);
Image = (ImageView) findViewById(R.id.ImageView01);
Run Code Online (Sandbox Code Playgroud)
现在它们的值将在我的程序中动态更改(图像从在线 url 更改),最后我需要将它们的值存储在 db 中以备将来使用。在这里我得到文本值
String TextValue = Text.getText().toString();
Run Code Online (Sandbox Code Playgroud)
但是我如何从 ImageView 存储价值?
String ImageValue = Image.someFunctionThatReturnsImageReferenceInString();
Run Code Online (Sandbox Code Playgroud)
有没有这样的功能??
或如何做到这一点.. 请帮忙
您需要将图像视图转换为如下所示的 base64 字符串。
1]将图像视图转换为位图。
imageView.buildDrawingCache();
Bitmap bmap = imageView.getDrawingCache();
Run Code Online (Sandbox Code Playgroud)
2]位图到base64字符串。
public String getEncoded64ImageStringFromBitmap(Bitmap bitmap) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.JPEG, 70, stream);
byte[] byteFormat = stream.toByteArray();
// get the base 64 string
String imgString = Base64.encodeToString(byteFormat, Base64.NO_WRAP);
return imgString;
}
Run Code Online (Sandbox Code Playgroud)
3]base64 到位图。
byte[] decodedString = Base64.decode(Base64String.getBytes(), Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
Run Code Online (Sandbox Code Playgroud)
将此位图设置为 imageview。
| 归档时间: |
|
| 查看次数: |
9049 次 |
| 最近记录: |