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中文 ...
随机推荐
- 支持度(support)和置信度(confidence)
支持度(Support)的公式是:Support(A->B)=P(A U B).支持度揭示了A与B同时出现的概率.如果A与B同时出现的概率小,说明A与B的关系不大:如果A与B同时出现的非常频 ...
- HDU FatMouse's Speed 基本DP
题意:要求找到的体重递增,速度递减的老鼠,并且输出最长的长度数,而且输出各自的序列数.Special Judge 思路:先按体重由小到大排序,再找最长速度递减序列. 转移方程:mou[i].w> ...
- lua 中pairs 和 ipairs区别
lua 中pairs 和 ipairs区别 标准库提供了集中迭代器,包括迭代文件每行的(io.lines),迭代table元素的(pairs),迭代数组元素的(ipairs),迭代字符串中单词的 (s ...
- 【Java基础】Integer包装类的缓冲池问题
首先看下面这个例子: public class TestNew { public static void main(String args[]){ Integer i1 = 10; //Integer ...
- HW2.19
public class Solution { public static void main(String[] args) { char outcome; long randomNumber; wh ...
- LeetCode:Restore IP Address
93. Restore IP Addresses Given a string containing only digits, restore it by returning all possible ...
- POJ1155 - TELE(树形DP)
题目大意 电视台要直播一场比赛,电视网络刚好形成了一棵树,其中有M个为客户端,其他的为中转站,其中中转站与中转站以及中转站与客户端之间连接都需要一定费用,每个客户i愿意支付pay[i]元钱,问电视台在 ...
- javascript如何判断一个对象是否是窗口
<!DOCTYPE html> <html> <head> </head> <body> <script type="tex ...
- java_method_获取数据库中列表的第一行第一列的int值
List<String[]> counts=DataBaseManage.getInstance().executeQuery(sql, 1, list); int count=0; if ...
- html的框架