當前位置: 首頁>>代碼示例>>Java>>正文


Java DataBufferByte類代碼示例

本文整理匯總了Java中java.awt.image.DataBufferByte的典型用法代碼示例。如果您正苦於以下問題:Java DataBufferByte類的具體用法?Java DataBufferByte怎麽用?Java DataBufferByte使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DataBufferByte類屬於java.awt.image包,在下文中一共展示了DataBufferByte類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: conv_Mat

import java.awt.image.DataBufferByte; //導入依賴的package包/類
private Mat conv_Mat(BufferedImage img) {
    byte[] data = ((DataBufferByte) img.getRaster().getDataBuffer()).getData();
    Mat mat = new Mat(img.getHeight(), img.getWidth(), CvType.CV_8UC3);
    mat.put(0, 0, data);
    Mat mat1 = new Mat(img.getHeight(), img.getWidth(), CvType.CV_8UC3);
    Imgproc.cvtColor(mat, mat1, Imgproc.COLOR_RGB2HSV);

    return mat1;
}
 
開發者ID:javaspecial,項目名稱:Face-detection-and-recognition-desktop-application,代碼行數:10,代碼來源:FaceRecognizeFrame.java

示例2: matrixToBuffer

import java.awt.image.DataBufferByte; //導入依賴的package包/類
/**
 * Converts/writes a Mat into a BufferedImage.
 *
 * @param matBGR Mat of type CV_8UC3 or CV_8UC1
 * @return BufferedImage of type TYPE_3BYTE_BGR or TYPE_BYTE_GRAY
 */
public static BufferedImage matrixToBuffer(Mat matBGR) {
   int type = BufferedImage.TYPE_BYTE_GRAY;
   if (matBGR.channels() > 1) {
      type = BufferedImage.TYPE_3BYTE_BGR;
   }
   int width = matBGR.width(), height = matBGR.height(), channels = matBGR.channels();
   byte[] sourcePixels = new byte[width * height * channels];
   matBGR.get(0, 0, sourcePixels);

   // Create new image and get reference to backing data
   image = new BufferedImage(width, height, type);
   final byte[] targetPixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
   System.arraycopy(sourcePixels, 0, targetPixels, 0, sourcePixels.length);
   return image;
}
 
開發者ID:grantslatton,項目名稱:GarfieldLanguage,代碼行數:22,代碼來源:Webcam.java

示例3: convertPowerOf2

import java.awt.image.DataBufferByte; //導入依賴的package包/類
/**
 * Converts the given image to a gl compatible format if necessary and returns the data in the format GL_RGBA as GL_UNSIGNED_BYTE
 * such that the width and height are a power of 2. The image is place in the upper left corner.
 * @param awtImage the image to be converted to an byte buffer
 * @return nio buffer
 */
public static ByteBuffer convertPowerOf2(BufferedImage awtImage)
{
	if(!isGlCompatibleAwtImage(awtImage) || !isPowerOf2(awtImage.getWidth()) || !isPowerOf2(awtImage.getHeight()))
	{
		int width = powerOf2(awtImage.getWidth());
		int height = powerOf2(awtImage.getHeight());
		BufferedImage convertImage = createGlCompatibleAwtImage(width, height);
        // copy the source image into the produced image
        Graphics g = convertImage.getGraphics();
        g.setColor(new Color(0f, 0f, 0f, 0f));
        g.fillRect(0, 0, width, height);
        g.drawImage(awtImage, 0, 0, null);
        awtImage = convertImage;
	}
	
       // build a byte buffer from the temporary image 
       // that be used by OpenGL to produce a texture.
       byte[] data = ((DataBufferByte) awtImage.getRaster().getDataBuffer()).getData(); 
       ByteBuffer imageBuffer = ByteBuffer.allocateDirect(data.length); 
       imageBuffer.order(ByteOrder.nativeOrder()); 
       imageBuffer.put(data, 0, data.length); 
       imageBuffer.flip();
       
       return imageBuffer; 
}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:32,代碼來源:ImageConverter.java

示例4: makeImage

import java.awt.image.DataBufferByte; //導入依賴的package包/類
BufferedImage makeImage() {
// Generate 8-bit image

    //Image img8;
    byte[] pixels8;
    int color16;

    pixels8 = new byte[width*height];
    for (int i=0; i<width*height; i++) {
        color16 = rgb(pixels32[i]);
        pixels8[i] = (byte)hist[color16];
    }

    SampleModel sampleModel = new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE, width, height, 1, width, new int[] {0});
    DataBufferByte Buffer = new DataBufferByte(pixels8, pixels8.length);
    WritableRaster raster = Raster.createWritableRaster(sampleModel, Buffer, null);

    return new BufferedImage(cm, raster, false, null);
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:20,代碼來源:MedianCut.java

示例5: getImage

import java.awt.image.DataBufferByte; //導入依賴的package包/類
@Override
public BufferedImage getImage()
{

	ByteBuffer buffer = this.getImageBytes();

	if (buffer == null)
	{
		LOG.error("Images bytes buffer is null!");
		return null;
	}

	byte[] bytes = new byte[this.size.width * this.size.height * 3];
	byte[][] data = new byte[][] { bytes };

	buffer.get(bytes);

	DataBufferByte dbuf = new DataBufferByte(data, bytes.length, OFFSET);
	WritableRaster raster = Raster.createWritableRaster(this.smodel, dbuf, null);

	BufferedImage bi = new BufferedImage(this.cmodel, raster, false, null);
	bi.flush();

	return bi;
}
 
開發者ID:PolyphasicDevTeam,項目名稱:NoMoreOversleeps,代碼行數:26,代碼來源:WebcamDefaultDevice.java

示例6: read24BitBitmap

import java.awt.image.DataBufferByte; //導入依賴的package包/類
private static BufferedImage read24BitBitmap(int nSizeImage, int nHeight, int nWidth, InputStream input) throws IOException {
    int npad = (nSizeImage / nHeight) - nWidth * 3;
    if (npad == 4 || npad < 0)
        npad = 0;
    int nindex = 0;
    BufferedImage bufferedImage = new BufferedImage(nWidth, nHeight, BufferedImage.TYPE_4BYTE_ABGR);
    DataBufferByte dataBufferByte = ((DataBufferByte) bufferedImage.getRaster().getDataBuffer());
    byte[][] bankData = dataBufferByte.getBankData();
    byte brgb[] = new byte[(nWidth + npad) * 3 * nHeight];

    readBuffer(input, brgb);

    for (int j = nHeight - 1; j >= 0; j--) {
        for (int i = 0; i < nWidth; i++) {
            int base = (j * nWidth + i) * 4;
            bankData[0][base] = (byte) 255;
            bankData[0][base + 1] = brgb[nindex];
            bankData[0][base + 2] = brgb[nindex + 1];
            bankData[0][base + 3] = brgb[nindex + 2];
            nindex += 3;
        }
        nindex += npad;
    }

    return bufferedImage;
}
 
開發者ID:claudiu-ancau-rm,項目名稱:GUI,代碼行數:27,代碼來源:BitmapLoader.java

示例7: prepare

import java.awt.image.DataBufferByte; //導入依賴的package包/類
@Before
public void prepare() {
	try {

		File _file = new File(imgFilePath);
		BufferedImage inputImage = ImageIO.read(_file);
		inputImage = resizeImageWithHint(inputImage, inputImage.getType(), size, size);
		height = inputImage.getHeight();
		width = inputImage.getWidth();

		outputImageCPU = new BufferedImage(width, height, inputImage.getType());
		outputImageGPU = new BufferedImage(width, height, inputImage.getType());
		outputImageApar = new BufferedImage(width, height, inputImage.getType());

		imageIn = ((DataBufferByte) inputImage.getRaster().getDataBuffer()).getData();
		imageOutCPU = ((DataBufferByte) outputImageCPU.getRaster().getDataBuffer()).getData();
		imageOutGPU = ((DataBufferByte) outputImageGPU.getRaster().getDataBuffer()).getData();
		imageOutApar = ((DataBufferByte) outputImageApar.getRaster().getDataBuffer()).getData();

	} catch (IOException e) {
		e.printStackTrace();
	}

}
 
開發者ID:adnanmitf09,項目名稱:Rubus,代碼行數:25,代碼來源:Convolution.java

示例8: loadFromFile

import java.awt.image.DataBufferByte; //導入依賴的package包/類
private int[][] loadFromFile(BufferedImage image) {
	final byte[] pixels = ((DataBufferByte) image.getData().getDataBuffer())
			.getData();
	final int width = image.getWidth();

	if (rgbData == null)
		rgbData = new int[image.getHeight()][width];

	for (int pixel = 0, row = 0; pixel < pixels.length; row++)
		for (int col = 0; col < width; col++, pixel += 3)
			rgbData[row][col] = -16777216 + ((int) pixels[pixel] & 0xFF)
					+ (((int) pixels[pixel + 1] & 0xFF) << 8)
					+ (((int) pixels[pixel + 2] & 0xFF) << 16); // 255
																// alpha, r
																// g b;

	return rgbData;
}
 
開發者ID:1Ridav,項目名稱:PengueeBot,代碼行數:19,代碼來源:Frag.java

示例9: matToBufferedImage

import java.awt.image.DataBufferByte; //導入依賴的package包/類
public static Image matToBufferedImage(Mat m)
{
    // just a simple convertor from web, this code is the fastest one
    int type = BufferedImage.TYPE_BYTE_GRAY;
    if ( m.channels() > 1 ) {
        type = BufferedImage.TYPE_3BYTE_BGR;
    }
    int bufferSize = m.channels()*m.cols()*m.rows();
    byte [] b = new byte[bufferSize];
    m.get(0,0,b);
    BufferedImage image = new BufferedImage(m.cols(),m.rows(), type);
    final byte[] targetPixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
    System.arraycopy(b, 0, targetPixels, 0, b.length);
    return image;
    
}
 
開發者ID:Plasmoxy,項目名稱:AquamarineLake,代碼行數:17,代碼來源:CVUtility.java

示例10: matToBufferedImage

import java.awt.image.DataBufferByte; //導入依賴的package包/類
public static Image matToBufferedImage(Mat m)
{
    // just a simple convertor from web, this code is the fastest one
    int type = BufferedImage.TYPE_BYTE_GRAY;
    if ( m.channels() > 1 ) {
        type = BufferedImage.TYPE_3BYTE_BGR;
    }
    int bufferSize = m.channels()*m.cols()*m.rows();
    byte [] b = new byte[bufferSize];
    m.get(0,0,b);
    BufferedImage image = new BufferedImage(m.cols(),m.rows(), type);
    final byte[] targetPixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
    System.arraycopy(b, 0, targetPixels, 0, b.length);
    return image;

}
 
開發者ID:Plasmoxy,項目名稱:AquamarineLake,代碼行數:17,代碼來源:CVUtility.java

示例11: makeImage

import java.awt.image.DataBufferByte; //導入依賴的package包/類
public Image makeImage(TestEnvironment env, int w, int h) {
    BufferedImage img = new BufferedImage(w, h, type);
    if (unmanaged) {
        DataBuffer db = img.getRaster().getDataBuffer();
        if (db instanceof DataBufferInt) {
            ((DataBufferInt)db).getData();
        } else if (db instanceof DataBufferShort) {
            ((DataBufferShort)db).getData();
        } else if (db instanceof DataBufferByte) {
            ((DataBufferByte)db).getData();
        } else {
            try {
                img.setAccelerationPriority(0.0f);
            } catch (Throwable e) {}
        }
    }
    return img;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:19,代碼來源:ImageTests.java

示例12: createBuffer

import java.awt.image.DataBufferByte; //導入依賴的package包/類
/**
  * Create a data buffer of a particular type.
  *
  * @param dataType the desired data type of the buffer.
  * @param size the size of the data buffer bank
  * @param numBanks the number of banks the buffer should have
  */
 public static DataBuffer createBuffer(int dataType, int size, int numBanks)
 {
   switch (dataType)
     {
     case DataBuffer.TYPE_BYTE:
return new DataBufferByte(size, numBanks);
     case DataBuffer.TYPE_SHORT:
return new DataBufferShort(size, numBanks);
     case DataBuffer.TYPE_USHORT:
return new DataBufferUShort(size, numBanks);
     case DataBuffer.TYPE_INT:
return new DataBufferInt(size, numBanks);
     case DataBuffer.TYPE_FLOAT:
return new DataBufferFloat(size, numBanks);
     case DataBuffer.TYPE_DOUBLE:
return new DataBufferDouble(size, numBanks);
     default:
throw new UnsupportedOperationException();
     }
 }
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:28,代碼來源:Buffers.java

示例13: createBufferFromData

import java.awt.image.DataBufferByte; //導入依賴的package包/類
/**
  * Create a data buffer of a particular type.
  *
  * @param dataType the desired data type of the buffer
  * @param data an array containing the data
  * @param size the size of the data buffer bank
  */
 public static DataBuffer createBufferFromData(int dataType, Object data,
					int size)
 {
   switch (dataType)
     {
     case DataBuffer.TYPE_BYTE:
return new DataBufferByte((byte[]) data, size);
     case DataBuffer.TYPE_SHORT:
return new DataBufferShort((short[]) data, size);
     case DataBuffer.TYPE_USHORT:
return new DataBufferUShort((short[]) data, size);
     case DataBuffer.TYPE_INT:
return new DataBufferInt((int[]) data, size);
     case DataBuffer.TYPE_FLOAT:
return new DataBufferFloat((float[]) data, size);
     case DataBuffer.TYPE_DOUBLE:
return new DataBufferDouble((double[]) data, size);
     default:
throw new UnsupportedOperationException();
     }
 }
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:29,代碼來源:Buffers.java

示例14: bufferedImage2Mat

import java.awt.image.DataBufferByte; //導入依賴的package包/類
/**
 * Converts a buffered image object in to an openCV mat.
 * @param image buffered image
 * @return mat
 */
public static Mat bufferedImage2Mat(BufferedImage image){
	byte[] data = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();  		  
	Mat mat = new Mat(image.getHeight(), image.getWidth(), CvType.CV_8UC3);  		  
	mat.put(0, 0, data);  		  		  
	return mat;  
}
 
開發者ID:Flash3388,項目名稱:FlashLib,代碼行數:12,代碼來源:CvProcessing.java

示例15: makeUnmanagedBI

import java.awt.image.DataBufferByte; //導入依賴的package包/類
private static BufferedImage makeUnmanagedBI(GraphicsConfiguration gc,
                                             int type) {
    BufferedImage img = gc.createCompatibleImage(SIZE, SIZE, type);
    Graphics2D g2d = img.createGraphics();
    g2d.setColor(RGB);
    g2d.fillRect(0, 0, SIZE, SIZE);
    g2d.dispose();
    final DataBuffer db = img.getRaster().getDataBuffer();
    if (db instanceof DataBufferInt) {
        ((DataBufferInt) db).getData();
    } else if (db instanceof DataBufferShort) {
        ((DataBufferShort) db).getData();
    } else if (db instanceof DataBufferByte) {
        ((DataBufferByte) db).getData();
    } else {
        try {
            img.setAccelerationPriority(0.0f);
        } catch (final Throwable ignored) {
        }
    }
    return img;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:23,代碼來源:IncorrectAlphaConversionBicubic.java


注:本文中的java.awt.image.DataBufferByte類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。