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中文 ...
随机推荐
- HDU 2509
与HDU 1907一样... #include<cstdio> #include<cstring> #include<cstdlib> #include<io ...
- eclipse安装插件checkstyle
最近听说了一个eclipse神器:checkstyle,可以帮助java开发人员规范代码,对我这种有代码洁癖的人来说,这有着不小的魔力啊,必然要安装试一试啊. 我最喜欢的安装方式是 输入一个安装网址, ...
- Spring源码入门——XmlBeanDefinitionReader解析
接上篇[] ,我们看到BeanDefinitionReader解决的是从资源文件(xml,propert)到BeanDefinition集合的过程.所以BeanDefinitionReader接口有两 ...
- GifView项目学习
http://code.google.com/p/gifview/downloads/detail?name=GifViewDemo.rar&can=2&q= 加入jar包
- ONIX 实例
<?xml version="1.0"?><!DOCTYPE ONIXMessage SYSTEM"http://www.editeur.org/oni ...
- 百亿级别数据量,又需要秒级响应的案例,需要什么系统支持呢?下面介绍下大数据实时分析工具Yonghong Z-Suite
Yonghong Z-Suite 除了提供优秀的前端BI工具之外,Yonghong Z-Suite让用户可以选购分布式数据集市来支持实时大数据分析. 对于这种百亿级的大数据案例,Yonghong Z- ...
- Play!framework 项目部署到Tomcat
Play Framework有自带的服务器,也可部署到其他服务器上.这里讲解下如何将Play的项目部署到Tomcat. 1.准备war包 首先进入play目录: 比如我的: cd C:\play-1. ...
- Ubuntu下开启root登陆
亲手安装过Ubuntu的童鞋都知道,默认安装只会添加一个普通用户名和密码,而超级用户权限则是利用sudo命令来执行.在Ubuntu下使用root登陆或者在shell中用su命令切换到root时会提示错 ...
- ThinkPHP3.1新特性:Action参数绑定
Action参数绑定功能提供了URL变量和操作方法的参数绑定支持,这一功能可以使得你的操作方法定义和参数获取更加清晰,也便于跨模块调用操作方法了.这一新特性对以往的操作方法使用没有任何影响,你也可以用 ...
- C# WPF 解压缩7zip文件 带进度条 sevenzipsharp
vs2013附件 :http://download.csdn.net/detail/u012663700/7427461 C# WPF 解压缩7zip文件 带进度条 sevenzipsharp W ...