全部!我对这个问题完全不知所措。它可能已被回答,但我找不到任何人确切地要求我需要什么。
我有一个 jpeg 文件保存到 SDCARD,并希望以编程方式将其顺时针旋转 90 度,然后将其保存回卡中(覆盖原件或在编辑后删除原件)。JPEG被加载到
File myFile;
谁能告诉我如何去做?我想它与 BitmapFactory 和矩阵有关,但就像我说的:我有点过头了!
谢谢!
尝试这个。
public Bitmap rotate(String file)
{
Bitmap source = BitmapFactory.decodeFile("/sdcard/ChuckNorris.png");
Bitmap b = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Config.ARGB_8888);
Paint p = new Paint();
p.setColor(Color.BLACK);
Canvas f = new Canvas(b);
f.drawBitmap(source, 0, 0, p);
f.rotate(90);
return b;
}
注意:不要自己尝试
I found the answer!
For JPG files, apparently you can just niftily edit the exif data using the following method:
ExifInterface exif = new ExifInterface(myFile.getAbsolutePath());
exif.setAttribute(ExifInterface.TAG_ORIENTATION, "6");
exif.saveAttributes();
Are there any downsides to using this approach? It seems to work pretty well as far as I can determine..