/*************以下源码通过测试******************************/

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图像处理相关测试【一些特殊的处理方式】的更多相关文章

  1. DirectShow Filter的开发实践

    一.介绍 摄像头图像采集处理在业界有着多种成熟的方案.从老的DirectShow.Grabber技术,到新的Windows Media Foundation框架,网络上都有着丰富的参考资料.OpenC ...

  2. Unity3D-美术相关

    1.导入动画 (1)使用预分解的动画模型,导入后面板中会含有一个可用的动画片段列表. (2)使用未分解的动画模型,自行添加动画片段. (3)使用多个动画文件,模型与动画分离.对于goober.fbx模 ...

  3. OpenCV学习 7:图像形态学:腐蚀、膨胀

    原创文章,欢迎转载,转载请注明出处 首先什么是图像形态学?额,这个抄下百度到的答案.基本思想:    用具有一定形态的结构元素去度量和提取图像中的对应形状已达到对图像分析和识别的目的,形态学图像处理表 ...

  4. R+NLP︱text2vec包——BOW词袋模型做监督式情感标注案例(二,情感标注)

    要学的东西太多,无笔记不能学~~ 欢迎关注公众号,一起分享学习笔记,记录每一颗"贝壳"~ --------------------------- 在之前的开篇提到了text2vec ...

  5. Swing滚动条重写

    Swing滚动条重写 摘自:https://blog.csdn.net/qq_40064948/article/details/81738191 未验证 Swing滚动条重写 2018年08月16日 ...

  6. 用最简单的方式在C#中使用多线程加速耗时的图像处理算法的执行(多核机器)。

    图像处理中,有很多算法由于其内在的复杂性是天然的耗时大户,加之图像本身蕴涵的数据量比一般的对象就大,因此,针对这类算法,执行速度的提在很大程度上依赖于硬件的性能,现在流行的CPU都是至少2核的,稍微好 ...

  7. Atitit MATLAB 图像处理attilax总结

    Atitit MATLAB 图像处理attilax总结 1.1. 下载 Matlab7.0官方下载_Matlab2012 v7.0 官方简体中文版-办公软件-系统大全.html1 1.2. Matla ...

  8. 图像处理中任意核卷积(matlab中conv2函数)的快速实现。

    卷积其实是图像处理中最基本的操作,我们常见的一些算法比如:均值模糊.高斯模糊.锐化.Sobel.拉普拉斯.prewitt边缘检测等等一些和领域相关的算法,都可以通过卷积算法实现.只不过由于这些算法的卷 ...

  9. 杂项之图像处理pillow

    杂项之图像处理pillow 本节内容 参考文献 生成验证码源码 一些小例子 1. 参考文献 http://pillow-cn.readthedocs.io/zh_CN/latest/ pillow中文 ...

随机推荐

  1. Cogs 97. [NOIP2007] 树网的核 Floyd

    题目: http://cojs.tk/cogs/problem/problem.php?pid=97 97. [NOIP2007] 树网的核 ★☆   输入文件:core.in   输出文件:core ...

  2. 文件同步工具BT Sync介绍和使用说明

    BT Sync介绍 BT 下载,相信大伙儿都知道的.今儿个要介绍的 BT Sync,跟 BT 下载一样,都是 BitTorrent 公司发明滴玩意儿,都是采用 P2P 协议来进行传输. 简而言之,BT ...

  3. Solution for When browse http://xxx/ReportServer Show Error (rsAccessDenied)

    Issue: Reporting Services Error The permissions granted to user 'IDEAAM\William' are insufficient fo ...

  4. obj-c 名词

    类:     Class (description/template for an object)实例: Instance (manifestation of a class)消息: Message ...

  5. puppet_list

  6. 问题-delphi 调试(F8)错行处理

    在delphi 7中(其他版本也可能碰到该问题),编译后,代码左边显示蓝色小点,表示哪句代 码是被编译了的,可今天我的一些代码不能显示那些蓝点了,这样也就不能在上面设断点了,而且用F8跟踪发现执行的顺 ...

  7. JavaScript- The Good Parts Chapter 5 Inheritance

    Divides one thing entire to many objects;Like perspectives, which rightly gazed uponShow nothing but ...

  8. Android ArrayAdpater 填充集合

    在这里我们新创建一个任务来演示 然后再布局文件中定义一个ListView 来当作显示数据的容器,布局文件代码如下: <LinearLayout xmlns:android="http: ...

  9. 百亿级别数据量,又需要秒级响应的案例,需要什么系统支持呢?下面介绍下大数据实时分析工具Yonghong Z-Suite

    Yonghong Z-Suite 除了提供优秀的前端BI工具之外,Yonghong Z-Suite让用户可以选购分布式数据集市来支持实时大数据分析. 对于这种百亿级的大数据案例,Yonghong Z- ...

  10. 哪里有比较全的hadoop视频教程

    robby老师讲了套hadoop视频,讲的比的深入浅出,内容很丰富,把网盘下载地址提供给大家一下: 视频下载啦很大,有图有真相: 1,Hadoop介绍,HDFS和MapReduce工作原理:http: ...