के लिए तेज़ विकल्प मेरे पास BufferedImages को परिवर्तित करने का एक तरीका है जिसका प्रकार TYPE_CUSTOM TYPE_INT_RGB है। मैं निम्नलिखित कोड का उपयोग कर रहा हूं, हालांकि मैं वास्तव में ऐसा करने का एक तेज़ तरीका ढूंढना चाहता हूं।ColorConvertOp
BufferedImage newImg = new BufferedImage(
src.getWidth(),
src.getHeight(),
BufferedImage.TYPE_INT_RGB);
ColorConvertOp op = new ColorConvertOp(null);
op.filter(src, newImg);
यह ठीक काम करता है, हालांकि यह काफी धीमा है और मैं सोच रहा हूं कि इस रूपांतरण को करने का एक तेज़ तरीका है या नहीं। रूपांतरण से पहले
ColorModel:
ColorModel: #pixelBits = 24 numComponents = 3 color space = [email protected] transparency = 1 has alpha = false isAlphaPre = false
ColorModel रूपांतरण के बाद:
DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=0
धन्यवाद!
अद्यतन:
कच्चे पिक्सेल डेटा के साथ काम कर बाहर कर देता है सबसे अच्छा तरीका था। चूंकि TYPE_CUSTOM वास्तव में आरजीबी को परिवर्तित कर रहा था, यह मैन्युअल रूप से सरल है और ColorConvertOp से लगभग 95% तेज है।
public static BufferedImage makeCompatible(BufferedImage img) throws IOException {
// Allocate the new image
BufferedImage dstImage = new BufferedImage(img.getWidth(), img.getHeight(), BufferedImage.TYPE_INT_RGB);
// Check if the ColorSpace is RGB and the TransferType is BYTE.
// Otherwise this fast method does not work as expected
ColorModel cm = img.getColorModel();
if (cm.getColorSpace().getType() == ColorSpace.TYPE_RGB && img.getRaster().getTransferType() == DataBuffer.TYPE_BYTE) {
//Allocate arrays
int len = img.getWidth()*img.getHeight();
byte[] src = new byte[len*3];
int[] dst = new int[len];
// Read the src image data into the array
img.getRaster().getDataElements(0, 0, img.getWidth(), img.getHeight(), src);
// Convert to INT_RGB
int j = 0;
for (int i=0; i<len; i++) {
dst[i] = (((int)src[j++] & 0xFF) << 16) |
(((int)src[j++] & 0xFF) << 8) |
(((int)src[j++] & 0xFF));
}
// Set the dst image data
dstImage.getRaster().setDataElements(0, 0, img.getWidth(), img.getHeight(), dst);
return dstImage;
}
ColorConvertOp op = new ColorConvertOp(null);
op.filter(img, dstImage);
return dstImage;
}
सुंदर! कच्चे डेटा के साथ काम करना प्रसंस्करण समय में 95% कटौती !! इस पोस्ट को समाप्त करने के तरीके के लिए संपादित पोस्ट देखें। –
मैंने बाइटइंटरलेवडररस्टर और इंटीजरइंटरलेवडर रास्टर कक्षाओं का उपयोग नहीं किया क्योंकि किसी कारण से मेरे पास सूर्य पैकेज नहीं हैं। –
पवित्र बकवास मैं बस 100 मिनट + psd फ़ाइल को 10 मिनट से 8 सेकंड तक संसाधित करने से चला गया। धन्यवाद! – EdgeCaseBerg