重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

php接收byte数据 php byte数组

php 如何将图片转换成java中Byte[]的

按照你的要求编写的Java程序如下:( 要注意的地方见语句后面的注释)

成都创新互联主要从事网站设计、做网站、网页设计、企业做网站、公司建网站等业务。立足成都服务建昌,十多年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:13518219792

import java.awt.image.BufferedImage;import java.awt.image.RenderedImage;import java.io.File;import java.io.IOException;import javax.imageio.ImageIO;public class ImageWithArray { public static void main(String[] args) {  // 读取图片到BufferedImage  BufferedImage bf = readImage("c:\\tmp\\6\\female.png");//这里写你要读取的绝对路径+文件名  // 将图片转换为二维数组  int[][] rgbArray1 = convertImageToArray(bf);  // 输出图片到指定文件  writeImageFromArray("c:\\tmp\\2.png", "png", rgbArray1);//这里写你要输出的绝对路径+文件名  System.out.println("图片输出完毕!"); } public static BufferedImage readImage(String imageFile){  File file = new File(imageFile);  BufferedImage bf = null;  try {   bf = ImageIO.read(file);  } catch (IOException e) {   e.printStackTrace();  }  return bf; } public static int[][] convertImageToArray(BufferedImage bf) {  // 获取图片宽度和高度  int width = bf.getWidth();  int height = bf.getHeight();  // 将图片sRGB数据写入一维数组  int[] data = new int[width*height];  bf.getRGB(0, 0, width, height, data, 0, width);  // 将一维数组转换为为二维数组  int[][] rgbArray = new int[height][width];  for(int i = 0; i  height; i++)   for(int j = 0; j  width; j++)    rgbArray[i][j] = data[i*width + j];  return rgbArray; } public static void writeImageFromArray(String imageFile, String type, int[][] rgbArray){  // 获取数组宽度和高度  int width = rgbArray[0].length;  int height = rgbArray.length;  // 将二维数组转换为一维数组  int[] data = new int[width*height];  for(int i = 0; i  height; i++)   for(int j = 0; j  width; j++)    data[i*width + j] = rgbArray[i][j];  // 将数据写入BufferedImage  BufferedImage bf = new BufferedImage(width, height, BufferedImage.TYPE_INT_BGR);  bf.setRGB(0, 0, width, height, data, 0, width);  // 输出图片  try {   File file= new File(imageFile);   ImageIO.write((RenderedImage)bf, type, file);  } catch (IOException e) {   e.printStackTrace();  } }}

运行结果:

图片输出完毕!

原图:

输出图:

PHP中如何把图片转成java里 byte[]的 数据类型?

java中数组本身可以划分为一个类型.这个类型就是存放各种类型的对象或者值.

至于你的问题,则可以回答为存放byte的数组应该是数组类型.或者说数组的泛型是byte.

具体作用,泛泛的说,应该是存储数据.至于存储后干什么.那就看具体需求了.比如用于显示,用于逻辑判断......等等.

PHP如何给图片里加 byte

就是通过二进制打开图片。。给里面加个数字,但先要把这个数字弄成二进制再加进去加了油问题

php提取指定字节的内容问题,求助!!

$str=file_get_contents("a.txt");

$str_arr = explode("//",$str);

for($i=1;$i(count($str_arr)-1);$i++){ //楼主是要//与//之间的,第一个“你好”和最后的“你好吧/哈哈”不算是吧?

if(strlen($str_arr[$i]) 6){

$str1 = $str_arr[$i];

break;

}

}

if(isset($str1)){

echo $str1 . "是//与//之间第一个 6个字节以上的内容";

}else{

echo "没有6个字节以上的内容";

}

php里字节数组 怎么理解

PHP的字符串都是字节数组(或者叫字节串)。传言到PHP6 会改成真正的unicode字符串,但目前PHP4、5的字符串都只是字节串。

$a='你好';

echo $a[0];//这时显示的是一个字节,而不是字符‘你’

PHP中所有的字符串函数,比如substr、strpos、strcmp等等都注明了“binary-safe二进制安全”,表明这些函数只是处理字节,而非处理字符。

形成的原因:PHP早期和C一样,仅仅兼容ASCII码,而ASCII码的一个字符等同一个字节。

所以目前PHP的字符和字节是基本同义的,处理中文需要multibyte char多字节字符的MB模块。

到PHP6才会改变


本文名称:php接收byte数据 php byte数组
URL地址:http://cqcxhl.com/article/docpois.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP