我制作了一个小型的C#应用程序来创建.jpg格式的图像.
pictureBox.Image.Save(name,ImageFormat.Jpeg);
Run Code Online (Sandbox Code Playgroud)
图像成功创建.我输入原始图片,用它做一些事情并保存.然而,这张新照片的质量低于原始照片的质量.
有没有办法设定所需的质量?
使用AffineTransform类在Java中旋转图像时遇到一些问题.
我有以下方法来创建图像的旋转(90度)副本:
private BufferedImage createRotatedCopy(BufferedImage img, Rotation rotation) {
int w = img.getWidth();
int h = img.getHeight();
BufferedImage rot = new BufferedImage(h, w, BufferedImage.TYPE_INT_RGB);
double theta;
switch (rotation) {
case CLOCKWISE:
theta = Math.PI / 2;
break;
case COUNTERCLOCKWISE:
theta = -Math.PI / 2;
break;
default:
throw new AssertionError();
}
AffineTransform xform = AffineTransform.getRotateInstance(theta, w / 2, h / 2);
Graphics2D g = (Graphics2D) rot.createGraphics();
g.drawImage(img, xform, null);
g.dispose();
return rot;
}
Run Code Online (Sandbox Code Playgroud)
旋转是一个简单的枚举,值为NONE,CLOCKWISE和COUNTERCLOCKWISE.
我的问题的症状显示在这里:
http://perp.se/so/rotate_problems.html
因此,旋转工作正常,但生成的图像不会锚定到正确的坐标(或应该如何放置).因为我真的不知道我在做什么(我的线性代数很弱),我不知道如何自己解决这个问题.
我尝试了一些随机摆弄AffineTransform实例,但它没有帮助我(当然).我试过谷歌搜索(并搜索SO),但我见过的所有例子基本上都使用与我相同的方法...这对我不起作用.
感谢您的建议.
我在那里看过很多帖子?但我找不到正确答案.
我尝试做一些事情:
@Override
public void onPictureTaken(byte[] paramArrayOfByte, Camera paramCamera) {
try {
Bitmap bitmap = BitmapFactory.decodeByteArray(paramArrayOfByte, 0,
paramArrayOfByte.length);
int width = bitmap.getWidth();
int height = bitmap.getHeight();
FileOutputStream os = new ileOutputStream(Singleton.mPushFilePath);
Matrix matrix = new Matrix();
matrix.postRotate(90);
Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0, width,
height, matrix, false);
resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 95, os);
os.close();
...
Run Code Online (Sandbox Code Playgroud)
有没有办法旋转图片,而不使用BitmapFactory?我想要旋转图片而不会损失质量!