ImageIcon图像处理相关测试【一些特殊的处理方式】
/*************以下源码通过测试******************************/
package cn.jason.ios.images;
import java.awt.FileDialog;
import java.awt.Image;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
/**
*
* ImageIcon图像处理相关测试[一些特殊的处理方式]
*
*/
public class MyImageIcon extends JFrame{
/**
* 打开本地管理器对话框,选择图片文件
* @return 返回图片绝对路径
*/
private static String getLocalImageAbsolutePath(){
JFrame frame=new JFrame();
//创建对话框
FileDialog dialog=new FileDialog(frame);
//设置尺寸
dialog.setBounds(300, 100, 500, 450);
//打开对话框
dialog.setVisible(true);
//获取返回的绝对路径
StringBuilder absolutePath=new StringBuilder();
absolutePath.append(dialog.getDirectory()=="null"?"null":dialog.getDirectory());
absolutePath.append(dialog.getFile()=="null"?"null":dialog.getFile());
//过滤信息
if(absolutePath.toString().contains("null")){
return "NO-Path";
}
return absolutePath.toString();
}
/**
* 终止程序
*/
private static void exitPrograming(){
System.exit(0);
}
/**
* 获取图片二进制数据 :[1024*1024*10]:10M
* @param imagePath 图片绝对地址
* @return 返回二进制数据
*/
private static byte[] getImageBytes(String imagePath){
//二进制对象
byte[] b=new byte[1024*1024*10];
//创建图片文件
File imageFile=new File(imagePath);
//图片流对象
try {
FileInputStream fis=new FileInputStream(imageFile);
//写入
fis.read(b);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return b!=null?b:null;
}
/**
* 通过图片二进制数据 获取ImageIcon对象
* @param b 二进制数据
* @return ImageIcon对象
*/
private static ImageIcon getImageIcon(byte[] b){
return new ImageIcon(b);
}
/**
* 通过图片地址 获取ImageIcon对象
* @param filename 图片地址
* @return ImageIcon对象
*/
private static ImageIcon getImageIcon(String filename){
return new ImageIcon(filename);
}
/**
* 通过图片地址对象 获取ImageIcon对象
* @param location URL地址对象
* @return ImageIcon对象
*/
private static ImageIcon getImageIcon(URL location){
return new ImageIcon(location);
}
/**
* 通过图片对象 获取ImageIcon对象
* @param image Image地址对象
* @return ImageIcon对象
*/
private static ImageIcon getImageIcon(Image image){
return new ImageIcon(image);
}
/**
* 调整ImageIcon的尺寸
* @param icon Icon对象
* @param width 调整后的宽度
* @param height 调整后的高度
* @return
*/
private static ImageIcon imageSizeCorrect(ImageIcon icon,
int width,
int height){
Image images=icon.getImage();
images=images.getScaledInstance(width, height, Image.SCALE_DEFAULT );
return new ImageIcon(images);
}
/**
* 程序入口
* @param params
*/
public static void main(String[] params) {
String path=getLocalImageAbsolutePath();
System.out.println("打开地址:"+path);
MyImageIcon testImages=new MyImageIcon();
testImages.setBounds(200,100, 500, 500);
JLabel jLabel=new JLabel();
jLabel.setBounds(100,100, 300, 300);
jLabel.setIcon(imageSizeCorrect(MyImageIcon.getImageIcon(MyImageIcon.getImageBytes(path)),300,300));
testImages.add(jLabel);
testImages.setVisible(true);
//结束程序
MyImageIcon.exitPrograming();
}
}
ImageIcon图像处理相关测试【一些特殊的处理方式】的更多相关文章
- DirectShow Filter的开发实践
一.介绍 摄像头图像采集处理在业界有着多种成熟的方案.从老的DirectShow.Grabber技术,到新的Windows Media Foundation框架,网络上都有着丰富的参考资料.OpenC ...
- Unity3D-美术相关
1.导入动画 (1)使用预分解的动画模型,导入后面板中会含有一个可用的动画片段列表. (2)使用未分解的动画模型,自行添加动画片段. (3)使用多个动画文件,模型与动画分离.对于goober.fbx模 ...
- OpenCV学习 7:图像形态学:腐蚀、膨胀
原创文章,欢迎转载,转载请注明出处 首先什么是图像形态学?额,这个抄下百度到的答案.基本思想: 用具有一定形态的结构元素去度量和提取图像中的对应形状已达到对图像分析和识别的目的,形态学图像处理表 ...
- R+NLP︱text2vec包——BOW词袋模型做监督式情感标注案例(二,情感标注)
要学的东西太多,无笔记不能学~~ 欢迎关注公众号,一起分享学习笔记,记录每一颗"贝壳"~ --------------------------- 在之前的开篇提到了text2vec ...
- Swing滚动条重写
Swing滚动条重写 摘自:https://blog.csdn.net/qq_40064948/article/details/81738191 未验证 Swing滚动条重写 2018年08月16日 ...
- 用最简单的方式在C#中使用多线程加速耗时的图像处理算法的执行(多核机器)。
图像处理中,有很多算法由于其内在的复杂性是天然的耗时大户,加之图像本身蕴涵的数据量比一般的对象就大,因此,针对这类算法,执行速度的提在很大程度上依赖于硬件的性能,现在流行的CPU都是至少2核的,稍微好 ...
- Atitit MATLAB 图像处理attilax总结
Atitit MATLAB 图像处理attilax总结 1.1. 下载 Matlab7.0官方下载_Matlab2012 v7.0 官方简体中文版-办公软件-系统大全.html1 1.2. Matla ...
- 图像处理中任意核卷积(matlab中conv2函数)的快速实现。
卷积其实是图像处理中最基本的操作,我们常见的一些算法比如:均值模糊.高斯模糊.锐化.Sobel.拉普拉斯.prewitt边缘检测等等一些和领域相关的算法,都可以通过卷积算法实现.只不过由于这些算法的卷 ...
- 杂项之图像处理pillow
杂项之图像处理pillow 本节内容 参考文献 生成验证码源码 一些小例子 1. 参考文献 http://pillow-cn.readthedocs.io/zh_CN/latest/ pillow中文 ...
随机推荐
- sensor的skipping and binning 模式
关于sensor的缩放存在两种模式 binning mode 和skip mode skipping mode 就是把想要的数据采集上来 把其余的数据扔掉 如下所示 column skip 2 row ...
- VellCar(barracuda buggy)
这是我的新目标,不过是外国人设计的,youtube上好多相关视频,只是在中国被墙了,FQ能看到一个不一样的世界,附:FQ教程.国外好多玩车的都是选择这辆车,因为它结构紧凑,制作相对简单,但越野性能强悍 ...
- PHP中的empty()和isset()的比较
- Solution for When browse http://xxx/ReportServer Show Error (rsAccessDenied)
Issue: Reporting Services Error The permissions granted to user 'IDEAAM\William' are insufficient fo ...
- ARM MIPS PowerPC比较
ARM, MIPS, Power PC的比较 “ARM面向的低端消费类市场,拼的是功耗:PowerPC面向的是中高端市场,比的是性能,好像还没看到谁的手机是PowerPC的,也没有看到谁家企业级以 ...
- oc学习之路----application.keyWindow.rootViewController与self.window.rootViewController与[self.window makeKeyAndVisible];小发现
刚才调试的时候除了一些小问题,有一段代码要重用 NSString *key = @"CFBundleVersion"; // 取出沙盒中存储的上次使用软件的版本号 NSUserDe ...
- 知道Form.Show()和Form.ShowDialog()的区别吗
博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:知道Form.Show()和Form.ShowDialog()的区别吗.
- bootstrap-table对前台页面表格的支持
1.bootstrap-table是在bootstrap的基础上面做了一些封装,所以在使用bootstrap-table之前要导入的js和css有 1)基本的还是jQuery <script t ...
- spring getbean 方法分析
spring 缺省: 1.spring用DefaultListableBeanFactory.preInstantiateSingletons()建立bean实例 2.缺省采用单例模式 在最近的项目中 ...
- [React Native] Passing data when changing routes
The way you make HTTP requests in React Native is with the Fetch API. In this video we'll talk about ...