我想将EditText的字符串转换为Bitmap。 有这样的字符串
String str=edtext.getText().toString();
如何将该字符串转换为位图?
答案 0 :(得分:6)
我不知道如何制作string
的图像,但这里是代码Bitmap
和EditText
因此,您将获得整个EditText的Bitmap图像,而不仅仅是String,
mEditText.setCursorVisible(false);
mEditText.buildDrawingCache();
Bitmap bmp = Bitmap.createBitmap(mEditText.getDrawingCache());
答案 1 :(得分:2)
我使用以下解决方案来解决我的问题,这对我有用。
Bitmap bmp = Bitmap.createBitmap(edtext.getDrawingCache());
System.out.println("ashish"+edtext.getText().toString());
Bitmap bm = BitmapFactory.decodeResource(r, R.drawable.balloon_overlay_focused);
Bitmap bmw=combineImages( bm,bmp);
CompositeImageViewText.setImageBitmap(bmw);
// combineimages()的代码
public Bitmap combineImages(Bitmap c, Bitmap s) { // can add a 3rd parameter 'String loc' if you want to save the new image - left some code to do that at the bottom
Bitmap cs = null;
int width, height = 0;
if(c.getWidth() > s.getWidth()) {
width = c.getWidth();
height = s.getHeight()+30 ;
} else {
width = s.getWidth();
height = s.getHeight()+30 ;
}
cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas comboImage = new Canvas(cs);
comboImage.drawBitmap(c, 0f, 0f, null);
comboImage.drawBitmap(s, 0f, 0f, null);
// this is an extra bit I added, just incase you want to save the new image somewhere and then return the location
/*String tmpImg = String.valueOf(System.currentTimeMillis()) + ".png";
OutputStream os = null;
try {
os = new FileOutputStream(loc + tmpImg);
cs.compress(CompressFormat.PNG, 100, os);
} catch(IOException e) {
Log.e("combineImages", "problem combining images", e);
}*/
return cs;
}
希望有其他帮助!
答案 2 :(得分:0)
“位图”是构成图像的像素集。
“字符串”是组成单词的一组字符。
根据位图的文件名,您可以做的最好的事情是读取位图。这就是Ankit Awasthi在上面所说明的内容。
希望这就是你要找的......