我想将EditText的字符串转换为位图。
我有一个像这样的字符串:
如何将该字符串转换为位图?
String str=edtext.getText().toString();
如何将该字符串转换为位图?
String str=edtext.getText().toString();
我不知道如何制作string
的图像,但是下面是从EditText
中创建Bitmap
的代码:
因此,您将获得整个EditText
的位图图像,而不仅仅是字符串。
mEditText.setCursorVisible(false);
mEditText.buildDrawingCache();
Bitmap bmp = Bitmap.createBitmap(mEditText.getDrawingCache());
我使用了以下解决方案来解决我的问题,这对我有用。
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;
}
"位图"是组成图像的像素集。
"字符串"是由字符组成的单词。
你能做的最好的事情就是根据位图的文件名来读取位图。这就是Ankit Awasthi上面所阐述的。
希望这正是您要寻找的内容...