【发布时间】:2015-10-18 02:45:54
【问题描述】:
我有一个应用程序,可以在 potrait 模式下单击图像并将它们保存在 SDCARD 中并带有 exyension png。我在图像上使用了额外的叠加层,然后将其保存。我的图像以横向模式保存。
我尝试使用矩阵,但无法得到正确的解决方案。
代码:此函数从包含所有图像字节数据的数组生成 png。
public void generatePng(byte[][] global) {
for (int i = 1; i < 25; i++) {
// Matrix matrix = new Matrix();
// matrix.postRotate();
// createa matrix for the manipulation
Bitmap cameraBitmap = BitmapFactory.decodeByteArray(global[i], 0, global[i].length);
int wid = cameraBitmap.getWidth();
int hgt = cameraBitmap.getHeight();
Matrix matrix = new Matrix();
// resize the bit map
// matrix.postScale(scaleWidth, scaleHeight);
// rotate the Bitmap
matrix.postRotate(45);
Bitmap newImage = Bitmap.createBitmap
(cameraBitmap,0,0,wid, hgt, matrix,true);
Canvas canvas = new Canvas(newImage);
canvas.drawBitmap(cameraBitmap, 0f, 0f, null);
Drawable drawable = getResources().getDrawable(R.drawable.overlay11);
// drawable.
// drawable.setBounds(40, 40, drawable.getIntrinsicWidth() + 40, drawable.getIntrinsicHeight() + 40);
drawable.setBounds(0, 0, wid, hgt);
drawable.draw(canvas);
File mediaStorageDir = new File("/sdcard/", "pics");
File myImage = new File(mediaStorageDir.getPath() + File.separator + "pic" + glo + ".png");
Log.d("naval", "File path :" + myImage);
glo++;
try {
FileOutputStream out = new FileOutputStream(myImage);
newImage.compress(Bitmap.CompressFormat.JPEG, 80, out);
out.flush();
out.close();
} catch (FileNotFoundException e) {
Log.d("In Saving File", e + "");
} catch (IOException e) {
Log.d("In Saving File", e + "");
}
}
counter =0;
// camera.startPreview();
}
我认为我使用的叠加层会产生问题。 有 2 个问题
- 我们可以旋转保存的图像而不是在保存时。我的图片完美保存在横向视图中。只想将它们旋转到 Potrait。
- 我正在尝试从所有这些图像中创建一个 gif。我们可以旋转gif吗?
【问题讨论】:
-
matrix.postRotate(45);应该是matrix.postRotate(90);(或matrix.postRotate(270);,以另一种方式旋转)!!
标签: java android rotation android-camera