Swing/PixelGrabber のバックアップ差分(No.1)
- バックアップ一覧
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/PixelGrabber へ行く。
- 1 (2009-12-28 (月) 11:50:47)
- 2 (2011-01-11 (火) 16:54:22)
- 3 (2011-01-11 (火) 18:19:32)
- 4 (2013-01-03 (木) 14:09:17)
- 5 (2013-02-26 (火) 19:51:38)
- 6 (2014-09-30 (火) 01:08:26)
- 7 (2015-01-03 (土) 06:17:02)
- 8 (2015-03-07 (土) 15:36:25)
- 9 (2015-04-04 (土) 22:09:32)
- 10 (2017-03-02 (木) 17:49:38)
- 11 (2018-01-06 (土) 18:57:24)
- 12 (2019-12-31 (火) 19:15:02)
- 13 (2021-07-03 (土) 03:39:49)
- 追加された行はこの色です。
- 削除された行はこの色です。
TITLE:PixelGrabberで画像を配列として取得し編集、書出し #navi(../) RIGHT:Posted by [[terai]] at 2009-12-28 *PixelGrabberで画像を配列として取得し編集、書出し [#cc3d247f] 画像の配列を取り出すPixelGrabberを生成して、角を透過色で塗りつぶします。 -&jnlp; -&jar; -&zip; #screenshot **サンプルコード [#v6f90a8c] #code{{ BufferedImage image; try { image = javax.imageio.ImageIO.read(getClass().getResource("screenshot.png")); }catch(java.io.IOException ioe) { ioe.printStackTrace(); return; } int width = image.getWidth(p); int height = image.getHeight(p); int[] pix = new int[height * width]; PixelGrabber pg = new PixelGrabber(image, 0, 0, width, height, pix, 0, width); try { pg.grabPixels(); } catch (Exception e) { e.printStackTrace(); } //NW for(int y=0;y<5;y++) { for(int x=0;x<5;x++) { if((y==0 && x<5) || (y==1 && x<3) || (y==2 && x<2) || (y==3 && x<1) || (y==4 && x<1) ) pix[y*width+x] = 0x0; } } //NE for(int y=0;y<5;y++) { for(int x=width-5;x<width;x++) { if((y==0 && x>=width-5) || (y==1 && x>=width-3) || (y==2 && x>=width-2) || (y==3 && x>=width-1) || (y==4 && x>=width-1) ) pix[y*width+x] = 0x0; } } }} **解説 [#m27cc900] 上記のサンプルでは、ウインドウのスクリーンショット画像から、PixelGrabberで配列を生成し、左上、右上の角((Windows XP風))を透過色で上書きしています。 角を置き換えた配列は、以下のようにMemoryImageSourceなどを使用して画像に変換しています。 #code{{ MemoryImageSource producer = new MemoryImageSource(width, height, pix, 0, width); Image img = p.createImage(producer); BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR); Graphics g = bi.createGraphics(); g.drawImage(img, 0, 0, null); g.dispose(); //try { // javax.imageio.ImageIO.write( // bi, "png", java.io.File.createTempFile("screenshot", ".png")); //}catch(java.io.IOException ioe) { // ioe.printStackTrace(); //} }} //**参考リンク **コメント [#y80493ae] #comment