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 1754 I Hate It 线段树 单点更新 区间最大值
#include<iostream> #include<string> #include<algorithm> #include<cstdlib> #i ...
- Esper系列(二)时间窗口、长度窗口、cast、注解、自定义函数、静态方法
长度窗口实现原理图 说明: 上图长度窗口为5,事件W1至W5进入引擎后属于NewEvents队列,事件W6进入引擎后,W2至W6就属于NewEvents队列,而事件W1就属于OldEvents队列了. ...
- HW5.20
public class Solution { public static void main(String[] args) { System.out.printf("%s\t%s\t%s\ ...
- 在浏览器中使用jquery取得iframe中页面中指定元素的值的不同
自己使用aspx页面中嵌套了ascx的页面其中使用了iframe的一些内容,出现了同一个页面的两种取值的方式 1. 在iframe的包含页面,需要使用iframe的页面中的元素,是需要使用$(wind ...
- json.net json转换神器
json.nethttps://json.codeplex.com/ api documenthttp://james.newtonking.com/json/help/index.html#
- 问题-Delphi记忆工程打开的单元(XE2设置项)
问题情况:每次在delphi中打开了N个单元的窗口,关闭delphi后,第二天还得一个一个打开单元窗口.问题原因:这是因为delphi的记忆功能未打开.问题处理:Tools->Options.. ...
- Code Smell那么多,应该先改哪一个?
博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:Code Smell那么多,应该先改哪一个?.
- 文件正在上传的转圈圈gif图片引出的fixed定位和absolute定位
文件正在上传的转圈圈gif图片 一.文件上传时,未上传返回成功状态之前给个gif动态图片显示在页面,改善用户体验. <!--S 遮罩层 --> <div id="mas ...
- Mac安装Mysql无法登录
Mac安装的Mysql5.7.10 执行mysql -u root -p 就要求输入密码,但是新安装是没密码的.然后就会报错. ERROR 1045 (28000): Access denied fo ...
- css字体转换程序(Node.js)
我下载的是ttf文件,css导入的文件有多种格式:eot,woff,svg 在windows下,需要寻找相应的exe文件来处理或者node.js来处理: ttf2eot: https://github ...