任何人可以建议我在java中的任何方法或任何其他方式,我可以在某些事件发生时取消选择我的jlist项目?我试过这个,但这似乎不起作用
myJList.setSelectedIndex(-1);
myJList.ensureIndexIsVisible(-1);
Run Code Online (Sandbox Code Playgroud) 我在JList中添加了一些图像,水平显示它们.
现在我想增加JList中图像之间的空间.
谁能建议怎么做?
获取每个像素的RGB值的最快方法是BufferedImage
什么?
现在我使用两个for
循环获取RGB值,如下面的代码所示,但是由于嵌套循环运行总共479999次,因此获取这些值花费的时间太长.如果我使用16位图像,这个数字会更高!
我需要一种更快的方法来获取像素值.
这是我目前正在尝试使用的代码:
BufferedImage bi=ImageIO.read(new File("C:\\images\\Sunset.jpg"));
int countloop=0;
for (int x = 0; x <bi.getWidth(); x++) {
for (int y = 0; y < bi.getHeight(); y++) {
Color c = new Color(bi.getRGB(x, y));
System.out.println("red=="+c.getRed()+" green=="+c.getGreen()+" blue=="+c.getBlue()+" countloop="+countloop++);
}
}
Run Code Online (Sandbox Code Playgroud) 我已经加载了我的JTree来查看我的目录结构,如我的代码和输出图像所示.这里,Tree节点默认按字母顺序排序,但我的另一个要求是我想根据目录名的第二个名称对所有节点进行排序,而不实际重命名目录.我已经在下面列出了我需要对JTree节点进行排序的名称.请给我一些建议.
import java.io.File;
import javax.swing.JFrame;
import javax.swing.JTree;
import javax.swing.event.TreeModelListener;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
public class FILE_NAME {
public static void main(String[] args) {
JFrame frame = new JFrame("My Jtree");
File root = new File("C:/java");
JTree tree = new JTree(new FileTreeModel(root));
frame.setSize(300, 300);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(tree);
frame.setVisible(true);
}
}
class FileTreeModel implements TreeModel {
protected File root;
public FileTreeModel(File root) {
this.root = root;
}
@Override
public Object getRoot() {
return root;
}
@Override
public boolean isLeaf(Object node) {
return ((File) …
Run Code Online (Sandbox Code Playgroud) 我在 CUDA 中实现了一个 2D 中值滤波器,整个程序如下所示。
#include "cuda_runtime.h"
#include "cuda_runtime_api.h"
#include "device_launch_parameters.h"
#include <iostream>
#include <fstream>
#include <iomanip>
#include <windows.h>
#include <io.h>
#include <stdio.h>
#include<conio.h>
#include <cstdlib>
#include "cstdlib"
#include <process.h>
#include <stdlib.h>
#include <malloc.h>
#include <ctime>
using namespace std;
#define MEDIAN_DIMENSION 3 // For matrix of 3 x 3. We can Use 5 x 5 , 7 x 7 , 9 x 9......
#define MEDIAN_LENGTH 9 // Shoul be MEDIAN_DIMENSION x MEDIAN_DIMENSION = 3 x 3
#define BLOCK_WIDTH 16 // …
Run Code Online (Sandbox Code Playgroud) 我正在使用JNA.我从我的c ++方法获取原始数据的字节数组.现在我被困在如何使用这个原始数据字节数组在java中获取缓冲图像.我曾尝试过很少的东西来把它作为tiff图像,但我得到了成功.这是我到目前为止尝试的代码.这里我的字节数组包含16位灰度图像的数据.我从x传感器设备获得这些数据.现在我需要从这个字节数组中获取图像.
第一次尝试
byte[] byteArray = myVar1.getByteArray(0, 3318000);//array of raw data
ImageInputStream stream1=ImageIO.createImageInputStream(newByteArrayInputStream(byteArray));
ByteArraySeekableStream stream=new ByteArraySeekableStream(byteArray,0,3318000);
BufferedImage bi = ImageIO.read(stream);
Run Code Online (Sandbox Code Playgroud)
第二个尝试
SeekableStream stream = new ByteArraySeekableStream(byteArray);
String[] names = ImageCodec.getDecoderNames(stream);
ImageDecoder dec = ImageCodec.createImageDecoder(names[0], stream, null);
//at this line get the error ArrayIndexOutOfBoundsException: 0
RenderedImage im = dec.decodeAsRenderedImage();
Run Code Online (Sandbox Code Playgroud)
我想我在这里失踪了.由于我的数组包含原始数据,因此它不包含tiff图像的标题.对吗?如果是,则如何在字节数组中提供此标头.最终如何从这个字节数组中获取图像?
测试我从我的本机方法得到正确的字节数组我将这个字节数组存储为.raw文件,在ImageJ软件中打开这个原始文件后,它播放了正确的图像,所以我的原始数据是正确的.我唯一需要的是如何在图像字节数组中转换我的原始字节数组?
这是我的代码.它不会在框架中显示图像,而是显示一些文本.任何人都可以建议我,我应该在代码中做出什么改变,以便它允许我在一个框架中显示图像?
import java.awt.Component;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.DefaultListModel;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollPane;
public class ListView {
public static void main(String[] args) throws IOException {
JFrame frame=new JFrame();
frame.setSize(500,500);
JLabel lbl[] = new JLabel[10];
DefaultListModel listModel;
ImageIcon[] b = new ImageIcon[10];
//JList lsm=new JList();
listModel = new DefaultListModel();
File folder = new File("C:/Documents and Settings/All Users/Documents/My Pictures/Sample Pictures");
File[] listOfFiles = folder.listFiles();
JLabel[] lb=new …
Run Code Online (Sandbox Code Playgroud) 任何人都可以建议我如何存储.TIF格式的图像ImageIcon
并将此图像添加到列表模型?我尝试了这个,但给了我java.lang.NullPointerException
.
public static void main(String[] args) throws Exception {
String path = "C:\\project\\aimages";
JFrame frame = new JFrame();
frame.setSize(500, 500);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
File folder = new File(path);
File[] listOfFiles = folder.listFiles();
DefaultListModel listModel = new DefaultListModel();
System.out.println("listOfFiles.length="+listOfFiles.length);
int count = 0;
for (int i = 0; i < listOfFiles.length; i++) {
//System.out.println("check path"+listOfFiles[i]);
String name = listOfFiles[i].toString();
System.out.println("name"+name);
// load only JPEGs
if (name.endsWith("jpg") || name.endsWith("JPG")|| name.endsWith("tif") || name.endsWith("TIF")) {
if(name.endsWith("tif") || name.endsWith("TIF"))
{
BufferedImage image = …
Run Code Online (Sandbox Code Playgroud) 如何在java中JTabbedPane的选项卡中生成或显示图像的缩略图视图,并允许用户单击该图像以显示在JTabbedpane的其他选项卡中?
import javax.swing.*;
import java.awt.*;
import java.awt.Event.*;
import java.io.File;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.IOException;
public class SwindDesign {
public static void main(String[] args) throws IOException {
JFrame frame = new JFrame("Split Pain");
frame.setSize(700, 500);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new GridLayout());
//panel
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.add(new PicturePanel());
JTabbedPane jtp = new JTabbedPane();
jtp.addTab("Set Image", panel);
jtp.addTab("Compare Image", new JButton());
frame.add(jtp);
}
}
class PicturePanel extends JPanel {
File folder = new File("C:/Documents and Settings/All Users/Documents/My Pictures/Sample Pictures"); …
Run Code Online (Sandbox Code Playgroud)