2
我想捕捉圖像中的編輯文本內容。但文字可以滾動。如何在編輯文本中從可滾動內容創建位圖圖像?
如何從編輯文本中捕捉可滾動內容?
沒有滾動我使用下面的鏈接繼續做..
Create Bitmap Image from EditText & its content
請幫我解決這個問題
我想捕捉圖像中的編輯文本內容。但文字可以滾動。如何在編輯文本中從可滾動內容創建位圖圖像?
如何從編輯文本中捕捉可滾動內容?
沒有滾動我使用下面的鏈接繼續做..
Create Bitmap Image from EditText & its content
請幫我解決這個問題
下面是示例代碼
請盡你所能。 ...
Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(),
R.drawable.edittextimage);// get the image same as your EditText
bitmap = convertToMutable(bitmap);// converting the bitmap to mutable
Canvas cs = new Canvas(bitmap);
int h = bitmap.getHeight();
int w = bitmap.getWidth();
Paint pt = new Paint();
pt.setColor(Color.GREEN);
String iam = "your text that get from the Edit Text";
cs.drawText(iam, 0, iam.length(), (h/2) + 10, (w/2)/2, pt);
pt.setColor(Color.RED);
cs.drawText("this is praki", 0, 13, h/2, w/3, pt);
Save_to_SD(bitmap , path)//save the bitmap in to sdcard
convertToMutable(bit地圖)了Methode ....
public static Bitmap convertToMutable(Bitmap imgIn) {
try {
// this is the file going to use temporally to save the bytes.
// This file will not be a image, it will store the raw image data.
File file = new File(Environment.getExternalStorageDirectory()
+ File.separator + "temp.tmp");
// Open an RandomAccessFile
// Make sure you have added uses-permission
// android:name="android.permission.WRITE_EXTERNAL_STORAGE"
// into AndroidManifest.xml file
RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");
// get the width and height of the source bitmap.
int width = imgIn.getWidth();
int height = imgIn.getHeight();
Bitmap.Config type = imgIn.getConfig();
// Copy the byte to the file
// Assume source bitmap loaded using options.inPreferredConfig =
// Config.ARGB_8888;
FileChannel channel = randomAccessFile.getChannel();
MappedByteBuffer map = channel.map(FileChannel.MapMode.READ_WRITE,
0, imgIn.getRowBytes() * height);
imgIn.copyPixelsToBuffer(map);
// recycle the source bitmap, this will be no longer used.
imgIn.recycle();
System.gc();// try to force the bytes from the imgIn to be released
// Create a new bitmap to load the bitmap again. Probably the memory
// will be available.
imgIn = Bitmap.createBitmap(width, height, type);
map.position(0);
// load it back from temporary
imgIn.copyPixelsFromBuffer(map);
// close the temporary file and channel , then delete that also
channel.close();
randomAccessFile.close();
// delete the temp file
file.delete();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return imgIn;
}
Save_to_SD(位圖,路徑)梅索德....
public static void Save_to_SD(Bitmap bm, String image_name) {
// String extStorageDirectory =
// Environment.getExternalStorageDirectory()
// .toString();
// String meteoDirectory_path = extStorageDirectory +
// "/Weather_Belgium";
OutputStream outStream = null;
File file = new File(image_name);
try {
outStream = new FileOutputStream(file);
bm.compress(Bitmap.CompressFormat.PNG, 100, outStream);
outStream.flush();
outStream.close();
Log.i("Hub", "OK, Image Saved to SD");
Log.i("Hub",
"height = " + bm.getHeight() + ", width = " + bm.getWidth());
} catch (FileNotFoundException e) {
e.printStackTrace();
Log.i("Hub", "FileNotFoundException: " + e.toString());
} catch (IOException e) {
e.printStackTrace();
Log.i("Hub", "IOException: " + e.toString());
}
}
這個有用嗎? – prakash
你想創建編輯文本內容,圖片或編輯文字圖片? – prakash
將文本內容編輯爲圖像 – moDev
只需獲取edittext內容作爲字符串,並且可以使用畫布 – prakash