我正在通过网络服务在运行时从服务器下载一些图像,我如何将文本放在它上面。
我已经使用了这段代码,但这给出了异常。
网址 = 新网址(imgUrl);
HttpURLConnection urlConnection = (HttpURLConnection) url
.openConnection();
urlConnection.connect();
iStream = urlConnection.getInputStream();
File cacheDirectory = getBaseContext().getCacheDir();
// Temporary file to store the downloaded image
File tmpFile = new File(cacheDirectory.getPath() + "/wpta_"
+ position + ".png");
// The FileOutputStream to the temporary file
FileOutputStream fOutStream = new FileOutputStream(tmpFile);
// Creating a bitmap from the downloaded inputstream
Bitmap b = BitmapFactory.decodeStream(iStream);
// Writing the bitmap to the temporary file as png file
b.compress(Bitmap.CompressFormat.PNG, 50, fOutStream);
Canvas g = new Canvas(b);
Paint p = new Paint();
p.setColor(Color.BLACK);
p.setAntiAlias(true);
g.drawText("Text", 10, 10, p);
// Flush the FileOutputStream
fOutStream.flush();
// Close the FileOutputStream
fOutStream.close();
// Create a hashmap object to store image path and its position
// in the listview
HashMap<String, Object> hmBitmap = new HashMap<String, Object>();
// Storing the path to the temporary image file
hmBitmap.put("flag", tmpFile.getPath());
// Storing the position of the image in the listview
hmBitmap.put("position", position);