创建图片的缩略图 2022-06-05 00:20 204阅读 0赞 private void createThumbnail(String filename, int thumbWidth, int thumbHeight, int quality, String outFilename) throws InterruptedException, FileNotFoundException, IOException { // load image from filename Image image = Toolkit.getDefaultToolkit().getImage(filename); MediaTracker mediaTracker = new MediaTracker(new Container()); mediaTracker.addImage(image, 0); mediaTracker.waitForID(0); // use this to test for errors at this point: System.out.println(mediaTracker.isErrorAny()); // determine thumbnail size from WIDTH and HEIGHT double thumbRatio = (double)thumbWidth / (double)thumbHeight; int imageWidth = image.getWidth(null); int imageHeight = image.getHeight(null); double imageRatio = (double)imageWidth / (double)imageHeight; if (thumbRatio < imageRatio) { thumbHeight = (int)(thumbWidth / imageRatio); } else { thumbWidth = (int)(thumbHeight * imageRatio); } // draw original image to thumbnail image object and // scale it to the new size on-the-fly BufferedImage thumbImage = new BufferedImage(thumbWidth, thumbHeight, BufferedImage.TYPE_INT_RGB); Graphics2D graphics2D = thumbImage.createGraphics(); graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); graphics2D.drawImage(image, 0, 0, thumbWidth, thumbHeight, null); // save thumbnail image to outFilename BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(outFilename)); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out); JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(thumbImage); quality = Math.max(0, Math.min(quality, 100)); param.setQuality((float)quality / 100.0f, false); encoder.setJPEGEncodeParam(param); encoder.encode(thumbImage); out.close(); }
相关 vue图片缩略图及图片预览功能 前言 上次有个需求,是要给图片做个缩略图以及预览功能。其实用vue来实现是很简单的, 几句代码可以搞定,也不需要什么额外的插件。 效果如下: vue显示图片缩略 ゞ 浴缸里的玫瑰/ 2022年12月31日 03:22/ 0 赞/ 542 阅读
相关 php 图片生成缩略图方法,php批量生成图片缩略图的方法 //用PHP批量生成图片缩略图 function mkdirs($dirname,$mode=0777) //创建目录(目录, [模式]) \{ if(!is\_dir 分手后的思念是犯贱/ 2022年11月12日 09:55/ 0 赞/ 146 阅读
相关 php图片生成缩略图_PHP图片上传,并生成缩略图保存 HTML表单 上传: PHP接收处理upload.php // 文件及缩放尺寸 $imgfile = 'a.jpg';//这可以读取刚上传的文件 $percent = 绝地灬酷狼/ 2022年11月12日 04:27/ 0 赞/ 155 阅读
相关 读取系统所有 图片 和缩略图 / 读取系统的 多媒体索引 获取 sd卡中的所有图片信息 / public void initImag 超、凢脫俗/ 2022年08月18日 10:54/ 0 赞/ 64 阅读
相关 android 获取视频,图片缩略图 1、获取视频缩略图有两个方法 (1)通过内容提供器来获取 (2)人为创建缩略图 (1)缺点就是必须更新媒体库才能看到最新的视频的缩略图 获取的方法 /\\ 矫情吗;*/ 2022年08月14日 01:45/ 0 赞/ 167 阅读
相关 java 后台创建缩略图 通过Thumbnailator来解决问题:[https://github.com/coobird/thumbnailator][https_github.com_coobird 忘是亡心i/ 2022年06月18日 07:22/ 0 赞/ 117 阅读
相关 Android 开发图片压缩/缩略图的方法 在开发图片浏览器等软件是,很多时候要显示图片的缩略图,而一般情况下,我们要将图片按照固定大小取缩略图,一般取缩略图的方法是使用 BitmapFactory的decodeFile 港控/mmm°/ 2022年06月13日 03:26/ 0 赞/ 248 阅读
相关 创建图片的缩略图 private void createThumbnail(String filename, int thumbWidth, int thumbHeight, int q 浅浅的花香味﹌/ 2022年06月05日 00:20/ 0 赞/ 205 阅读
相关 生成 图片的 缩略图 public static void main(String[] args) throws IOException { File input 阳光穿透心脏的1/2处/ 2022年04月22日 00:28/ 0 赞/ 198 阅读
相关 Bootstrap 图片及缩略图 一、图片形状 1、通过为 <img> 元素添加以下相应的类,可以让图片呈现不同的形状。 .img-rounded:添加 border-radius:6px 墨蓝/ 2022年03月21日 07:26/ 0 赞/ 409 阅读
还没有评论,来说两句吧...