当前位置: 首页>>代码示例>>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;未经允许,请勿转载。