相关疑难解决方法(0)

在onPictureTaken之后旋转JPEG的字节数组

有没有办法旋转字节数组而不将其解码为Bitmap?

目前在jpeg PictureCallback中我只是将字节数组直接写入文件.但图片是旋转的.我想旋转它们而不解码到位图,希望这将节省我的记忆.

    BitmapFactory.Options o = new BitmapFactory.Options();
    o.inJustDecodeBounds = true;
    BitmapFactory.decodeByteArray(data, 0, data.length, o);

    int orientation;
    if (o.outHeight < o.outWidth) {
        orientation = 90;
    } else {
        orientation = 0;
    }

    File photo = new File(tmp, "demo.jpeg");

    FileOutputStream fos;
    BufferedOutputStream bos = null;
    try {
        fos = new FileOutputStream(photo);
        bos = new BufferedOutputStream(fos);
        bos.write(data);
        bos.flush();
    } catch (IOException e) {
        Log.e(TAG, "Failed to save photo", e);
    } finally {
        IOUtils.closeQuietly(bos);
    }
Run Code Online (Sandbox Code Playgroud)

android android-camera

14
推荐指数
2
解决办法
1万
查看次数

如何在Swing中逐渐旋转图像?

当用户点击按钮时,我有一个正在旋转的图像.但它没有用.

我想看到图像逐渐旋转到90度直到它停止但它没有.单击按钮时,图像必须逐渐旋转90度.

我创建了一个SSCCE来演示这个问题.请使用CrossingPanelSSCE您选择的任何图像替换班级中的图像.只需将图像放入您的images文件夹并命名即可images/railCrossing.JPG.

RotateButtonSSCE

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JPanel;

public class RotateButtonSSCE extends JPanel implements ActionListener{
      private JButton rotate = new JButton("Rotate");
      private VisualizationPanelSSCE vis = new VisualizationPanelSSCE();

    public RotateButtonSSCE() {
        this.setBorder(BorderFactory.createTitledBorder("Rotate Button "));
        this.rotate.addActionListener(this);
        this.add(rotate);
    }

    public void actionPerformed(ActionEvent ev) {
        vis.rotatetheCrossing();
    }

}
Run Code Online (Sandbox Code Playgroud)

CrossingPanelSSCE

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import …
Run Code Online (Sandbox Code Playgroud)

java swing rotation

13
推荐指数
3
解决办法
2万
查看次数

在java中将图像旋转90度

我设法旋转图像,180 degrees但希望旋转它90 degrees clockwise可以有人编辑我的代码,以便它做到这一点解释.谢谢.

 private void rotateClockwise()
    {
        if(currentImage != null){
            int width = currentImage.getWidth();
            int height = currentImage.getHeight();
            OFImage newImage = new OFImage(width, height);
            for(int y = 0; y < height; y++) {
                for(int x = 0; x < width; x++) {
                    newImage.setPixel( x, height-y-1, currentImage.getPixel(x, y));
                }
        }
            currentImage = newImage;
            imagePanel.setImage(currentImage);
            frame.pack();
    }
    }
Run Code Online (Sandbox Code Playgroud)

java image image-rotation

10
推荐指数
2
解决办法
4万
查看次数

如何将2d阵列旋转LESS超过90°,达到最佳近似值?

假设我有一个以0°旋转存储的数组:

0 0 1 0 0
0 0 1 0 0 
1 1 1 0 0 
0 0 0 0 0
0 0 0 0 0 
Run Code Online (Sandbox Code Playgroud)

如果我通过,我希望它以良好的近似值返回,例如30°作为参数,它将是这样的:

0 0 0 1 0
1 1 0 1 0
0 0 1 0 0 
0 0 0 0 0 
0 0 0 0 0 
Run Code Online (Sandbox Code Playgroud)

45°会

1 0 0 0 1
0 1 0 1 0
0 0 1 0 0 
0 0 0 0 0 
0 0 0 0 0
Run Code Online (Sandbox Code Playgroud)

我知道90°旋转的解决方案.但我不认为这会对我有帮助吗? …

c# java algorithm

5
推荐指数
1
解决办法
157
查看次数

如何在Java中旋转非正方形图像?

我最近看到这个问题,就如何在Java中旋转图像。我直接从该答案中复制/粘贴了它。在实现时,似乎只旋转正方形的图像(即具有相同的大小,宽度和高度)。当我尝试将其用于非正方形图像时,如果可以的话,似乎会切断将其变成矩形的部分。像这样

我该如何解决/解决这个问题?

编辑:我正在使用的代码。另外,我不会有滚动条,因为这将是“游戏”,也不会一直处于全屏状态。

public class Player extends Entity { //Entity has basic values such as (float) x & y values, along with some getters and setters
   double theta;    

   Reticle reticle; //draws a reticle where the cursor was(basically just replaces java.awt.Cursor due to something not neccessary for me to get into)
   Sprite currentImage; //basically just a BufferedImage that you can apply aspect ratios to

   //constructor

   @Override
   public void tick() {
      //(this line) gets the Reticle from the main-method class …
Run Code Online (Sandbox Code Playgroud)

java

4
推荐指数
1
解决办法
1203
查看次数