1

I have a picture (bitmap) and I want to draw some shapes and rotated text on it.

This works fine as long as the picture doesn't get too large. However, when using a picture (2560 x 1920 pixels)taken with the build-in camera of my android 2.1 phone, the result is distorted. It looks like the rotation back, after drawing the rotated text, has not been completed. Also, the distortion point is not always the same, like it depends on the cpu usage.

You can see some resulting pictures here:
http://dl.dropbox.com/u/4751612/Result1.png
http://dl.dropbox.com/u/4751612/Result2.png

The code is executed inside a AsyncTask. The strange this is that this code works fine in one Activity, but not in another. In both activities the AsyncTask is executed when a button is clicked.

These are some excerpts of the code I'm using.

// Load the image from the MediaStore
c = MediaStore.Images.Media.query(context.getContentResolver(),
Uri.parse(drawing.fullImage), new String[] {MediaColumns.DATA});
if (c != null && c.moveToFirst()) {
       imageFilePath = c.getString(0);
       bitmap = ImageUtil.getBitmap(new File(imageFilePath), 10000);
}
c.close();

// Create a canvas to draw on
drawingBitmap = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Bitmap.Config.ARGB_8888);
canvas = new Canvas(drawingBitmap);

// Draw image
canvas.drawBitmap(bitmap, 0, 0,
MeasureFactory.getMeasurePaint(context));

// calculate text width
rect = new Rect();
paint.getTextBounds(text, 0, text.length(), rect);

// Draw rotated text
canvas.save();
canvas.rotate(-angle, centerPoint.x, centerPoint.y);
canvas.drawText(text, centerPoint.x-Math.abs(rect.exactCenterX()),
Math.abs(centerPoint.y-rect.exactCenterY()), paint);
canvas.restore();

// Upload the bitmap to the Media Library
Uri uri =
getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
values);
OutputStream outStream = getContentResolver().openOutputStream(uri);
drawingBitmap.compress(Bitmap.CompressFormat.JPEG, 90, outStream);
outStream.flush();
outStream.close();

Thanks in advance for any help.

4

2 回答 2

0

事实证明这是一个内存问题,尽管在日志中没有看到 OutOfMemoryException。

所以,如果分辨率太高,我通过缩放图像来“解决”它,正如 ingo 所建议的那样。问题是我不知道如何确定设备的限制。我想它们对于每个设备都是不同的,并且取决于当前的内存使用情况。

于 2011-02-25T08:37:52.527 回答
0

因为只要分辨率不太高,它就可以工作,我只需将所有图像重新缩放为可以工作的东西。

您可以使用
Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, 800 /* width */, 600 /* height */, true);

于 2011-02-23T12:17:19.673 回答