Tag: 图像

Java – 将JTextArea中的字符串转换为图像

我有一个字符串,显示在我的程序中,但我想知道如何将字符串的输出转换为与原始字符串相同的图像。 不知道是否可以这样做。 我希望输出正好是JTextArea。 这是可能的,如果可以的话,我应该研究什么?

每当我开始运行程序时如何制作随机位置?

我有一个随机移动的图像。 我的问题是每次我开始运行程序时,图像总是出现在左上角并移动一个对角线方向,在撞到墙壁后,它开始随机移动方向。 每次执行或运行程序时,如何使图像显示在随机位置? 任何帮助将非常感激… 这是代码: public class Ball extends JPanel implements Runnable { private Image ball; private Thread animator; private int x; private int y; private final int DELAY = 50; private int xVelocity = 1; private int yVelocity = 1; private static final int RIGHT_WALL = 400; private static final int LEFT_WALL = 1; […]

Java – 找到表示图像中所有颜色的颜色

我想要对图像进行采样以返回单个颜色,该颜色“看起来”是采样颜色的良好表示。 我试过两种方法: 取所有红色,绿色和蓝色的平均值并从中创建图像。 这很少产生看起来像是来自图像的颜色。 从图像中寻找“主导”颜色。 这需要从图像中找到最常见的颜色。 这是更好的,但例如,蒙娜丽莎产生深紫色。 这似乎捕捉到图像的较暗区域,但它忽略了顶角和皮肤上的所有较亮区域。 我想要一种代表黑暗区域和亮区的颜色。 Photoshop具有“平均模糊”,可为图像生成单一颜色。 对于蒙娜丽莎,这看起来像: 在这种情况下,每个季度代表蒙娜丽莎的四分之一。 这最终是我正在寻找的,但让我们从图像整体开始。 我很想知道Photoshop如何获得这些颜色。 谢谢!

使用JFileChooser上传多个图像

我试图在网上搜索这个问题的帮助,但找不到任何答案。 此时我有一个工作程序,允许您选择一个图像文件并显示它。 我想通过允许用户选择多个文件然后选择要显示的文件来构建此基础。 例如,用户将选择图像并将其显示。 然后,他可以单击一个按钮,允许其他图像排队等待,并且可能会显示一个按钮,点击后,图像将加载到框架中。 任何人都可以指导我如何实施这个方向吗? 非常感谢你的帮助! 这是我当前的代码实现: import java.awt.Image; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; import java.util.ArrayList; public class Images extends JFrame{ JButton button; JButton button2; JButton button3; JLabel label; ArrayList images = new ArrayList(); int selectedImageIndex =0; public Images(){ super(“Java Image Selector”); button = new JButton(“Select”); button.setBounds(300,300,100,40); button2 = […]

如何在Java中Stich to Image对象

我有一个场景,我从我的地图服务器获得了一些瓷砖(例如12)。 现在对于缓冲和离线function,我需要再次将它们连接起来,这样我们就必须处理1个单个图像对象而不是12个。我试过没有JAI,我的代码在下面。 package imagemerge; import java.awt.*; import java.awt.image.*; import java.awt.event.*; public class ImageSticher extends WindowAdapter { Image tile1; Image tile2; Image result; ColorModel colorModel; int width,height,widthr,heightr; //int t1,t2; int t12[]; public ImageSticher() { } public ImageSticher (Image img1,Image img2,int w,int h) { tile1=img1; tile2=img2; width=w; height=h; colorModel=ColorModel.getRGBdefault(); } public Image horizontalStich() throws Exception { widthr=width*2; […]

使用getExternalFilesDir保存Android不一致的图片

在我的应用程序中,我正在尝试拍照,保存它,然后使用Android开发人员教程中提供的代码将其添加到ImageView private static final int REQUEST_IMAGE_CAPTURE = 1; private String lastImagePath; //Create temporary image file using getExternalFilesDir() private File createImageFile() throws IOException{ String timestamp = new SimpleDateFormat(“yyyyMMdd_HHmmss”).format(new Date()); String imageFileName = “JPEG_” + timestamp + “_”; File storageDir = getActivity().getExternalFilesDir(Environment.DIRECTORY_PICTURES); File image = File.createTempFile(imageFileName, “.jpg”, storageDir); lastImagePath = image.getAbsolutePath(); return image; } //Start picture intent […]

从套接字读取图像

可能重复: 通过Java Socket读取映像文件 void readImage() throws IOException { socket = new Socket(“upload.wikimedia.org”, 80); DataOutputStream bw = new DataOutputStream(new DataOutputStream(socket.getOutputStream())); bw.writeBytes(“GET /wikipedia/commons/8/80/Knut_IMG_8095.jpg HTTP/1.1\n”); bw.writeBytes(“Host: wlab.cs.bilkent.edu.tr:80\n\n”); DataInputStream in = new DataInputStream(socket.getInputStream()); File file = new File(“imgg.jpg”); file.createNewFile(); DataOutputStream dos = new DataOutputStream(new FileOutputStream(file)); int count; byte[] buffer = new byte[8192]; while ((count = in.read(buffer)) > 0) { […]

如何阅读简单的xpm图像并使用Java显示它?

我被分配了一个任务来构建一个简单的xpm图像查看器。 我不能使用任何现有的工具包库。 我知道xpm图像是这样的字符串数组(我可以写一个) – /* XPM */ static const char *const hi[] = { “7 5 2 1″, ” c black”, “. c yellow”, “.. ..”, “. . . .”, “. . .”, “. .”, “. .” }; 我想用java来做这件事。 我的问题是 – 1.如何从这个xpm文件中创建一个String变量(hi []),以便我可以在我的主类中使用它? 2.在GUI中显示它的好方法? 3.任何其他口述…… 非常感谢您的帮助

使用BufferedImage创建非常大的图像文件,奇怪的问题取决于编译和计算机

我试图在Java中创建一个非常大的图像,如下所示: BufferedImage bi = new BufferedImage(58240,1664,BufferedImage.TYPE_INT_RGB); 显然,图像非常大。 现在我遇到的问题是,它似乎在某些计算机上运行良好100%但在其他计算机上运行得很慢(而且这与规格没有任何关系)。 我最重大的突破来自Eclipse,IDE拒绝实际显示图像,而是在其中一台计算机上出现错误,这些计算机显示图像的速度非常慢(需要花费大量时间来调整图像大小等): 线程“AWT-EventQueue-0”中的exceptionjava.lang.OutOfMemoryError:Java堆空间 错误的另一个有趣的元素是,即使在计算机上运行缓慢,我也可以调整窗口的大小,直到不再调用绘制函数,然后再将其设置为大,如果我这样做,那么它运行100速度的百分比。 不知道发生了什么,有什么想法吗?

Android – 将图像复制到剪贴板,任何人都有这个工作?

我正在尝试将图像文件从我的apk复制到剪贴板。 以下是我如何接近它(粗略地说,我在本地使用的内容提供商超出了问题的范围。 ClipboardManager mClipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE); ContentValues values = new ContentValues(2); values.put(MediaStore.Images.Media.MIME_TYPE, “Image/jpg”); values.put(MediaStore.Images.Media.DATA, filename.getAbsolutePath()); ContentResolver theContent = getContentResolver(); Uri imageUri = theContent.insert(MediaStore.Images.Media.INTERNAL_CONTENT_URI, values); ClipData theClip = ClipData.newUri(getContentResolver(), “Image”, imageUri); mClipboard.setPrimaryClip(theClip); 使用此代码可能会发生两件事: 1)java.lang.IllegalStateException:无法创建新文件2)粘贴时只粘贴URI本身,而不是图像(即使在兼容的应用程序中) 我没有看到任何人在Android工作中获得图像粘贴的任何例子,我已经广泛搜索了答案,无论是谷歌还是堆栈溢出。 有人能帮忙吗? 我真的很感激有人帮助。 PS:如果这是不可能的话,我也想知道,为了节省浪费时间。 谢谢!