2011-05-13 5 views
2

바이트, 부호없는 short 및 정수 사이의 메모리 사용 차이를 알고 있지만 BufferedImage의 경우에는 '속도'차이가 있습니까?

이미지 저장을 위해 코드에서 이미지 유형을 사용하고 있지만 알파 레이어가 필요합니다. BufferedImage를 사용하면 ARGB가 제공되지만 Image 형식에서 변경 한 후에 코드가/상당히 느리고 느립니다 (일부 개체의 경우에만 변경되었습니다). 그래서 얻을 수있는 모든 성능 향상을 찾고 있습니다.

나는이 질문이 얼마나 어리 석다고 확신하지 못하기 때문에 어떤 답장에 대해서도 감사드립니다.BufferedImage INT/4BYTE/USHORT

+0

프로파일 러는 무엇을 말합니까? – trashgod

+0

'프로파일 러'가 무슨 뜻입니까? – Tanaki

+0

['jvisualvm'] (예 : http://download.oracle.com/javase/6/docs/technotes/tools/share/jvisualvm.html). – trashgod

답변

2

Tanaki는

나는 BufferedImage의에서 알파 채널을 사용하여 필요에 가장 좋은 알파 채널을 전치 승산하는 경우 것으로 나타났습니다. 예를 들어 :

 
// Create an ARGB image 
BufferedImage bi = new BufferedImage(512, 512, BufferedImage.TYPE_INT_ARGB); 
Graphics2D g = bi.createGraphics(); 
// Fill the background (for illustration) 
g.setColor(Color.black); 
g.fill(new Rectangle(0, 0, 512, 512)); 

AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f)); 
// Keep the original composite 
Composite original = g.getComposite(); 
g.setComposite(alpha); 

// Paint with transparency 
Rectangle r = new Rectangle(100, 200, 50, 50); 
g.setColor(Color.magenta); 
g.fillRect(r); 
g.setComposite(original); 
// ... paint further shapes or images as necessary 
// ... 
g.dispose(); 

// Convert to a premultiplied alpha image for fast painting to a Canvas 
BufferedImage biPre = new BufferedImage(512, 512, BufferedImage.TYPE_INT_ARGB_PRE); 
Graphics2D gPre = biPre.createGraphics(); 
gPre.drawImage(bi, 0, 0, null); 
gPre.dispose(); 

// clean up: 
bi.flush(); 


// Now use biPre for painting to a Canvas, or a Component. 
// ... 

// Remember to flush it when done! 
biPre.flush(); 

TYPE_INT_ARGB 먼저 그림에 대한 이유는 예상대로 모든 알파가 그린 도착하도록하는 것입니다 (마다 미리 곱하지!). 그런 다음, 완료되면 전체 이미지를 TYPE_INT_ARGB_PRE에 칠하십시오. 그런 다음 데이터를 빠른 속도로 화면에 가져올 수 있습니다.

+0

고맙습니다. 문제가 해결되었습니다. – Tanaki

관련 문제