更改linux背景/ycai
在linux中,如果不能直接传输图片进去,那么可以通过使用txt再将文本转成bmp的方式达到传入图片的目的。
将图片转成bmp文件的网址:https://cdkm.com/cn/png-to-bmp
将bmp转成txt的代码,perl语言:
#!/usr/bin/perl
#use strict;
use warnings;
# Open the BMP file
open my $fh, '<', $ARGV[0] or die "Can't open $ARGV[0] file: $!";
# Open the output TXT file
open my $out_fh, '>', $ARGV[1] or die "Can't open output file: $!";
binmode $fh;
# Read the BITMAPFILEHEADER
my $bfh;
read $fh, $bfh, 14 or die "Can't read BITMAPFILEHEADER: $!";
my ($bfType, $bfSize, $bfReserved1, $bfReserved2, $bfOffBits) = unpack('a2VvvV', $bfh);
# Check if it's a BMP file
die "Not a BMP file" unless $bfType eq 'BM';
# Read the BITMAPINFOHEADER
my $bih;
read $fh, $bih, 40 or die "Can't read BITMAPINFOHEADER: $!";
my ($biSize, $biWidth, $biHeight, $biPlanes, $biBitCount, $biCompression, $biSizeImage, $biXPelsPerMeter, $biYPelsPerMeter, $biClrUsed, $biClrImportant) = unpack('VVVvvVVVVVV', $bih);
# Check if it's a 32-bit BMP
die "Not a 32-bit BMP" unless $biBitCount == 32;
print "Image dimensions: $biWidth x $biHeight\n";
# Read and convert the pixel data row by row from bottom to top
for my $y (reverse 0 .. $biHeight - 1) {
# Seek to the start of the current row
seek $fh, $bfOffBits + $y * $biWidth * 4, 0;
for my $x (0 .. $biWidth - 1) {
my $pixel;
read $fh, $pixel, 4 or die "Can't read pixel data: $!";
my ($b, $g, $r, $a) = unpack('CCCC', $pixel);
printf $out_fh "%02x%02x%02x\n", $r, $g, $b;
}
}
close $fh;
close $out_fh;
txt转成bmp代码:(大概率需要修一修)
ifلاا($#ARGVprint "Usage:cov <in.file> <input format> <out.file> <bmp_width> <bmp_height> txtΘ24rgbbmp24yuvد16yuv\n";exit;if ($ARGV[1] != 0 &$ARGV[1] != 1 & $ARGV[1] != 2 & $ARGV[1] != 3)open (INFILE, "< $ARGV[0]") or die;open (OUTFILE, "> $ARGV[2]") or die;print "Usage: over the range(0-2) please retype the command\n";exit;$nextsegment = 0;$IF = $ARGV[1];$w = $ARGV[3];$h = $ARGV[4];print "width= $ARGV[3] height= $ARGV[4]\n";######## BMP FILE HEAD #if (($w*3)%4){ $offset = $w*3 + (4 - ($w*3)%4);}else{ $offset = $w*3;}$data_size@ = $offset*$h;$data_sizel = sprintf ("%08x",$data_size0);@data_size2 = split(//,$data_sizel);$data_size3 = $data_size2[6].$data_size2[7].$data_size2$file sizeo = $data sizeo + 54;$file_sizel = sprintf ("%08x",$file_size0);@file_size2 = split(//,$file_sizel);$file_size3 = $file_size2[6].$file_size2[7].$file_size2[4].$file_size2[5].$file_size2[2].$file_size2[3].$file_size2[0].$file_size2[1]$wo = sprintf ("%08x",$w);@wl = split(//,$wo);$w2 = $w1[6].$w1[7].$w1[4].$w1[5].$w1[2].$w1[3].$w1[0].$w1[1];$h0 = sprintf ("%08x",$h);@hl = split(//,$he);$h2 = $h1[6].$h1[7].$h1[4].$h1[5].$h1[2].$h1[3].$h1[0].$h1[1];$BFTYPE= "424d";$BF FILE SIZE = $file_size3;$RESERVED = "Θ0000000";$BITMAP DATA OFFSET = "36000000";$BITMAP_HEADER_SIZE = "28000000";$WIDTH = $w2; $HEIGHT = $h2;$PLANES = "0100";$BPP = "1800";$COMPRESSION = "Θ0000000";$BF_DATA_SIZE = $data_size3;$HRESOLUTION = "6dΘbΘΘΘΘ";$VRESOLUTION = "6dΘbΘΘ0Θ"$COLORS= "Θ000ΘΘ00";$IMPORTANT|= "ΘΘΘΘΘΘΘΘ"$BMP_HEAD_HEX = $BFTYPE. $BF_FILE_SIZE. $RESERVED. $BITMAP_DATA_OFFSET. $BITMAP_HEADER_SIZE. SWIDTH. $HEIGHT. $PLANES. $BPP. $COMPRESSION. $BF_DATA_SIZE. $HRES OLUTION. $VRESOLUTION.$COLORS.$IMPORTANT;&hex2chr ($BMP_HEAD_HEX);######add zero if image size not matching the input data######### $txt total = Θ;$image_total = $w*$h;while ($line = <INFILE>){ $txt_total = $txt_total + 1;}Snum = $image_total - $txt_total;print "pictures is $image_total, buttxt is $txt_total , and the residual is $num";if ($num != Θ)fprint "Warning:The image size which you just set is not matching input file's data!\n"}for ($x = θ;$x < $num;$x++){if ($txt_total < $image_total) { $zero = "Θ00000";&hex2chr($zero); }close(INFILE);open (INFILE, "< $ARGV[0]") or die; ############### SUB function ######sub hex2chr{my($hex) =@; @onebyte = unpack("A2"x(length($hex)/2),$hex);foreach $chr (@onebyte){$per chr= chr(hex($chr)); print OUTFILE "$per_chr";sub yuv2rgb{my($yin,$uin,$vin) =@;$r_tmp = 1.164*(hex($yin) - 16) + 1.596*(hex($vin) - 128);$g_tmp = 1.164*(hex($yin) - 16) - 0.813*(hex($vin) - 128) - 0.391*(hex($uin) - 128);$b_tmp = 1.164*(hex($yin) - 16) + 2.018*(hex($uin) - 128);$r tmpe = $r tmp + 0.5; $g_tmpθ = $g_tmp + 0.5;$b_tmpe = $b_tmp + 0.5;if ($r tmpθ<0){$r tmpl = 0;}Elsif ($r_TMPO > 255){$r_tmp1 = 255;} else {$r tmpl = $r tmpe;}if ($g tmpo<0){$q tmpl= 0;}Elsif ($q TMPO > 255){$g_tmp1 = 255;} else {$g_tmp1 = $g_tmpθ;}if ($b tmpθ<Θ){sb tmpl = 0:}elsif (Sb tmpo > 255){$b_tmp1 = 255;}else{$b_tmp1 = $b_tmpθ;}$b = sprintf ("%02x",$b tmp1);$q = sprintf ("%02x",$q tmpl);$r = sprintf ("%02x",$r_tmp1);return($b, $g,$r);ADD DATA INFORMATION ####$i=0.$j = 0;if ($IF == 0)امwhile ($line = <INFILE>){chomp ($line);@split_line = split(//,$line);@image[$i] = $split line[4].$split line].$split_line[.$split_line$split_line[0].$split_line[1]8$i = $i + 1;}print "input format:24bit rgb\n";elif ($IF == 1)while ($line= <INFILE>){chomp($line):@split_line = split(//,$line);$y = $split_line[0].$split_line[1];$u = $split_line[2].$split_line[3];$v = $split_line[4].$split_line[5];@rgb = &yuv2rgb($y,$u,$v);@image[$i] = $rgb[0].$rgb[1].$rgb[2];سا$i = $i + 1; }print "input format:24bit yuv\n";String elsif (IF = = 2) chomp dollar (currenline dollar);$con = $I % 2;if ($i%2 == 0)ماwhile ($currenline = <INFILE>){$pixel@ = $currenline;else $pixel 1 = $currenline; $line = $pixelo.$pixel 1; @split_line = split(//,$line); $ye = $split_line[0].$split_line[1]; $u θ = $split_line[2].$split_line[3]; $ve = $split_line[6].$split_line[7]; $yl = $split_line[4].$split_line[5]; $ul = $split_line[2].$split_line[3]; $v 1 = $split_line[6].$split_line[7]; @rgbe = &yuv2rgb($yo, $uo,$vo);@rgbl = &yuv2rgb($y1,$ul,$v1);@image[$j] = $rgbe[0].$rgbe[1]. $rgbe[2]ب@image[$j+1] = $rgb1[0].$rgb1[1].$rgb1[2]$j = $j + 2;}$i = $i + 1;}print "input format:16bit yuv\n";elif ($IF == 3)}while ($currenline = <INFILE>){chomp($currenline);$con = $I % 2;if ($i%2 == 0) {$pixelo = $currenline;} else{$pixel1 = $currenline;}$line = $pixelo.$pixel 1; @split_line = split(//,$line); $ye = $split_line[0].ssplit_line[1]; $u θ = $split_line[2]. Ssplit_line [3]; $vo = $split_line[6]. Ssplit_line [7]; $y 1 = $split_line[4].$split_line[5]; $ul = $split_line[2].ssplit_line[3]; $v 1 = $split_line[6]. Ssplit_line [7];@rgb1 = &yuv2rgb($y1,Sul,$v1);@rgbe = &yuv2rgb($yo,$uo,$vo);@image[$j] =$rgbe[0].$rgbe[1].$rgbe[2];@image[$j+1] = $rgb1[0].$rgb1[1].$rgb1[2];$j = $j + 2;}$i = $i + 1;$zero_chr = chr(hex($zero));if ($n == $w - 1){}}}print "input format:16bit yuv\n";for($m = $h -1;$m >= 0;$m--){for($n = α;$n < $w;$n++){$addr = $n + $m*$w - $num;&hex2chr($image[$addr]);$zero = "00";if (($w*3)%4 == 3){print OUTFILE "$zero chr";}elsif ($w*3)%4 == 2){print OUTFILE "$zero chr$zero_chr";}elsif ($w*3)%4 ==1{print OUTFILE "$zero chr$zero_chr$zero_chr";}close(INFILE);close(OUTFILE);END
补充:perl环境需要下载相关解释器
https://www.activestate.com/activeperl/downloads
注册下载,并按照提示进行即可;其中的第一个是在cmd窗口中执行,而第二个命令是直接用在win+R输入的窗口

浙公网安备 33010602011771号