【GIFDecoder】GIFDecoder的排错以及修改另附完整代码和demo

前言

好久没有写技术类的博客了,今天有些小的收获,记录下来,留作备份

Gif图片的处理

由于业务需求,需要对gif动图的第一帧进行截取,然后我就搜索,发现了GIFDecoder这样的一个类,是做gif图片的处理的,怎奈国内人博客环境还是那么差,各种网站博客到处抄抄抄,没有一个完整的内容,经过多个站的资料整理,终于能用了。

出现了异常

在运行demo的时候,遇到了显示错误的问题

Notice: Undefined offset: 4 in /Applications/XAMPP/xamppfiles/htdocs/giftest/gifdecoder.class.php on line 83

查看源码发现83行是这样的

            function GIFReadExtensions() {
            GIFDecoder::GIFGetByte(1);
            if ($this->GIF_buffer [0] == 0xff) {
                for (;;) {
                    GIFDecoder::GIFGetByte(1);
                    if (( $u = $this->GIF_buffer [0] ) == 0x00) {
                        break;
                    }
                    GIFDecoder::GIFGetByte($u);
                    if ($u == 0x03) {
                        $this->GIF_anloop = ( $this->GIF_buffer [1] | $this->GIF_buffer [2] << 8 );
                    }
                }
            } else {
                for (;;) {
                    GIFDecoder::GIFGetByte(1);
                    if (( $u = $this->GIF_buffer [0] ) == 0x00) {
                        break;
                    }
                    GIFDecoder::GIFGetByte($u);
                    if ($u == 0x04) {
                        if ($this->GIF_buffer [4] & 0x80) {   //这里是第83行
                            $this->GIF_dispos [] = ( $this->GIF_buffer [0] >> 2 ) - 1;
                        } else {
                            $this->GIF_dispos [] = ( $this->GIF_buffer [0] >> 2 ) - 0;
                        }
                        $this->GIF_delays [] = ( $this->GIF_buffer [1] | $this->GIF_buffer [2] << 8 );
                        if ($this->GIF_buffer [3]) {
                            $this->GIF_TransparentI = $this->GIF_buffer [3];
                        }
                    }
                }
            }
        }

原因

经过搜索引擎的努力,我得到的比较正规的解释是

offset:接下去的数字是出错的数组下标,一般是超出了数组的取值范围,如定义了数组A[]有10个元数,如果出现了A[10]就会出现错误(Notice: Undefined offset: 10 ….),因为数组的下标是从0开始的,所以这个数组的下标就只能是0~9.

所以,原因就是

数组找不到下标为4的元素

解决方案

我们需要判断下标是不是存在

 if (isset($this->GIF_buffer [4]) & 0x80) { 

酱紫就搞定啦,啦啦啦~

源码

<?php

/**
 * GIFDecoder  <br/>
 *
 * 日期: 2015年05月21日   <br/>
 * 原作者: 不详           <br/>
 * 修改: CalvinLee       <br/>
 *
 *
 * <code>
 * require_once("gifdecoder.class.php");
 *
 * $FIC = "test.gif";
 * //获取gif的第一帧进行保存
 * if (file_exists($FIC)) {
 *      $GIF_frame = fread(fopen($FIC, 'rb'), filesize($FIC));
 *      $decoder = new GIFDecoder($GIF_frame);
 *      $frames = $decoder->GIFGetFrames();
 *      $i = 0;
 *      $fname =  rand(1000, 9999). $FIC . "_0$i.png";
 *      $hfic = fopen("" . $fname, "wb");
 *      fwrite($hfic, $frames [$i]);
 *      fclose($hfic);
 * }
 *  </code>
 *
 *
 * @copyright (c) 2015, Calvin Lee
 * @author Calvin Lee <diandianxiyu_@live.cn>

 */
Class GIFDecoder {

    public $GIF_TransparentR = -1;
    public $GIF_TransparentG = -1;
    public $GIF_TransparentB = -1;
    public $GIF_TransparentI = 0;
    public $GIF_buffer = array();
    public $GIF_arrays = array();
    public $GIF_delays = array();
    public $GIF_dispos = array();
    public $GIF_stream = "";
    public $GIF_string = "";
    public $GIF_bfseek = 0;
    public $GIF_anloop = 0;
    public $GIF_screen = array();
    public $GIF_global = array();
    public $GIF_sorted;
    public $GIF_colorS;
    public $GIF_colorC;
    public $GIF_colorF;

    function GIFDecoder($GIF_pointer) {
        $this->GIF_stream = $GIF_pointer;

        GIFDecoder::GIFGetByte(6);
        GIFDecoder::GIFGetByte(7);

        $this->GIF_screen = $this->GIF_buffer;
        $this->GIF_colorF = $this->GIF_buffer [4] & 0x80 ? 1 : 0;
        $this->GIF_sorted = $this->GIF_buffer [4] & 0x08 ? 1 : 0;
        $this->GIF_colorC = $this->GIF_buffer [4] & 0x07;
        $this->GIF_colorS = 2 << $this->GIF_colorC;

        if ($this->GIF_colorF == 1) {
            GIFDecoder::GIFGetByte(3 * $this->GIF_colorS);
            $this->GIF_global = $this->GIF_buffer;
        }
        for ($cycle = 1; $cycle;) {
            if (GIFDecoder::GIFGetByte(1)) {
                switch ($this->GIF_buffer [0]) {
                    case 0x21:
                        GIFDecoder::GIFReadExtensions();
                        break;
                    case 0x2C:
                        GIFDecoder::GIFReadDescriptor();
                        break;
                    case 0x3B:
                        $cycle = 0;
                        break;
                }
            } else {
                $cycle = 0;
            }
        }
    }

    function GIFReadExtensions() {
        GIFDecoder::GIFGetByte(1);
        if ($this->GIF_buffer [0] == 0xff) {
            for (;;) {
                GIFDecoder::GIFGetByte(1);
                if (( $u = $this->GIF_buffer [0] ) == 0x00) {
                    break;
                }
                GIFDecoder::GIFGetByte($u);
                if ($u == 0x03) {
                    $this->GIF_anloop = ( $this->GIF_buffer [1] | $this->GIF_buffer [2] << 8 );
                }
            }
        } else {
            for (;;) {
                GIFDecoder::GIFGetByte(1);
                if (( $u = $this->GIF_buffer [0] ) == 0x00) {
                    break;
                }
                GIFDecoder::GIFGetByte($u);
                if ($u == 0x04) {
                    if (isset($this->GIF_buffer [4]) & 0x80) {
                        $this->GIF_dispos [] = ( $this->GIF_buffer [0] >> 2 ) - 1;
                    } else {
                        $this->GIF_dispos [] = ( $this->GIF_buffer [0] >> 2 ) - 0;
                    }
                    $this->GIF_delays [] = ( $this->GIF_buffer [1] | $this->GIF_buffer [2] << 8 );
                    if ($this->GIF_buffer [3]) {
                        $this->GIF_TransparentI = $this->GIF_buffer [3];
                    }
                }
            }
        }
    }

    function GIFReadDescriptor() {
        $GIF_screen = Array();

        GIFDecoder::GIFGetByte(9);
        $GIF_screen = $this->GIF_buffer;
        $GIF_colorF = $this->GIF_buffer [8] & 0x80 ? 1 : 0;
        if ($GIF_colorF) {
            $GIF_code = $this->GIF_buffer [8] & 0x07;
            $GIF_sort = $this->GIF_buffer [8] & 0x20 ? 1 : 0;
        } else {
            $GIF_code = $this->GIF_colorC;
            $GIF_sort = $this->GIF_sorted;
        }
        $GIF_size = 2 << $GIF_code;
        $this->GIF_screen [4] &= 0x70;
        $this->GIF_screen [4] |= 0x80;
        $this->GIF_screen [4] |= $GIF_code;
        if ($GIF_sort) {
            $this->GIF_screen [4] |= 0x08;
        }

        //GIF Data Begin
        if ($this->GIF_TransparentI) {
            $this->GIF_string = "GIF89a";
        } else {
            $this->GIF_string = "GIF87a";
        }
        GIFDecoder::GIFPutByte($this->GIF_screen);
        if ($GIF_colorF == 1) {
            GIFDecoder::GIFGetByte(3 * $GIF_size);
            if ($this->GIF_TransparentI) {
                $this->GIF_TransparentR = $this->GIF_buffer [3 * $this->GIF_TransparentI + 0];
                $this->GIF_TransparentG = $this->GIF_buffer [3 * $this->GIF_TransparentI + 1];
                $this->GIF_TransparentB = $this->GIF_buffer [3 * $this->GIF_TransparentI + 2];
            }
            GIFDecoder::GIFPutByte($this->GIF_buffer);
        } else {
            if ($this->GIF_TransparentI) {
                $this->GIF_TransparentR = $this->GIF_global [3 * $this->GIF_TransparentI + 0];
                $this->GIF_TransparentG = $this->GIF_global [3 * $this->GIF_TransparentI + 1];
                $this->GIF_TransparentB = $this->GIF_global [3 * $this->GIF_TransparentI + 2];
            }
            GIFDecoder::GIFPutByte($this->GIF_global);
        }
        if ($this->GIF_TransparentI) {
            $this->GIF_string .= "!\xF9\x04\x1\x0\x0" . chr($this->GIF_TransparentI) . "\x0";
        }
        $this->GIF_string .= chr(0x2C);
        $GIF_screen [8] &= 0x40;
        GIFDecoder::GIFPutByte($GIF_screen);
        GIFDecoder::GIFGetByte(1);
        GIFDecoder::GIFPutByte($this->GIF_buffer);
        for (;;) {
            GIFDecoder::GIFGetByte(1);
            GIFDecoder::GIFPutByte($this->GIF_buffer);
            if (( $u = $this->GIF_buffer [0] ) == 0x00) {
                break;
            }
            GIFDecoder::GIFGetByte($u);
            GIFDecoder::GIFPutByte($this->GIF_buffer);
        }
        $this->GIF_string .= chr(0x3B);
        //GIF Data End

        $gif_array = &$this->GIF_arrays;
        $gif_array[] = $this->GIF_string;
    }

    function GIFGetByte($len) {
        $this->GIF_buffer = Array();
        for ($i = 0; $i < $len; $i++) {
            if ($this->GIF_bfseek > strlen($this->GIF_stream)) {
                return 0;
            }
            $this->GIF_buffer[] = ord($this->GIF_stream { $this->GIF_bfseek++});
        }
        return 1;
    }

    function GIFPutByte($bytes) {
        foreach ($bytes as $byte) {
            $this->GIF_string .= chr($byte);
        }
    }

    function GIFGetFrames() {
        return ( $this->GIF_arrays );
    }

    function GIFGetDelays() {
        return ( $this->GIF_delays );
    }

    function GIFGetLoop() {
        return ( $this->GIF_anloop );
    }

    function GIFGetDisposal() {
        return ( $this->GIF_dispos );
    }

    function GIFGetTransparentR() {
        return ( $this->GIF_TransparentR );
    }

    function GIFGetTransparentG() {
        return ( $this->GIF_TransparentG );
    }

    function GIFGetTransparentB() {
        return ( $this->GIF_TransparentB );
    }

}

?>

后记

  • 小的知识积累最后会有质变
  • 善于总结永远没有坏处
  • 一个功能写三遍就会变得不一样,如果还一样的话那就是自己的问题了

后后记

后来发现这个类在Yii2中还是不能使用,识别不出gif里面的图片,所以,我又去github上找到了这个类的2.0版

https://github.com/xurei/GIFDecoder_optimized

下面是用的源码,已经加上了namespace和注释

<?php
namespace common\components\helper;
/*
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::
::  GIFDecoder Version 2.0 by László Zsidi
::  Optimized version by xurei
::
::  Created at 2007. 02. 01. '07.47.AM'
::
::  Updated at 2009. 06. 23. '06.00.AM'
::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *
 *
 * <code>
 * require_once("gifdecoder.class.php");
 *
 * $FIC = "test.gif";
 * //获取gif的第一帧进行保存
 * if (file_exists($FIC)) {
 *      $GIF_frame = fread(fopen($FIC, 'rb'), filesize($FIC));
 *      $decoder = new GIFDecoder($GIF_frame);
 *      $frames = $decoder->GIFGetFrames();
 *      $i = 0;
 *      $fname =  rand(1000, 9999). $FIC . "_0$i.png";
 *      $hfic = fopen("" . $fname, "wb");
 *      fwrite($hfic, $frames [$i]);
 *      fclose($hfic);
 * }
 *  </code>
 *
 *
 *
 *
*/
use SplFixedArray;
class GIFDecoder {
    var $GIF_TransparentR =  -1;
    var $GIF_TransparentG =  -1;
    var $GIF_TransparentB =  -1;
    var $GIF_TransparentI =   0;

    var $GIF_buffer = null;
    var $GIF_arrays = Array ( );
    var $GIF_delays = Array ( );
    var $GIF_dispos = Array ( );
    var $GIF_stream = "";
    var $GIF_string = "";
    var $GIF_bfseek =  0;
    var $GIF_anloop =  0;

    //xurei - frames metadata
    var $GIF_frames_meta =  Array();

    var $GIF_screen = Array ( );
    var $GIF_global = Array ( ); //global color map
    var $GIF_sorted;
    var $GIF_colorS; //
    var $GIF_colorC; //Size of global color table
    var $GIF_colorF; //if 1, global color table follows image descriptor
    /*
    :::::::::::::::::::::::::::::::::::::::::::::::::::
    ::
    ::  GIFDecoder ( $GIF_pointer )
    ::
    */
    function __construct ( $GIF_pointer ) {
        $this->GIF_stream = $GIF_pointer;

        GIFDecoder::GIFGetByte ( 6 );
        GIFDecoder::GIFGetByte ( 7 );

        $this->GIF_screen = $this->GIF_buffer;
        $this->GIF_colorF = $this->GIF_buffer [ 4 ] & 0x80 ? 1 : 0;
        $this->GIF_sorted = $this->GIF_buffer [ 4 ] & 0x08 ? 1 : 0;
        $this->GIF_colorC = $this->GIF_buffer [ 4 ] & 0x07;
        $this->GIF_colorS = 2 << $this->GIF_colorC;

        if ( $this->GIF_colorF == 1 ) {
            GIFDecoder::GIFGetByte ( 3 * $this->GIF_colorS );
            $this->GIF_global = $this->GIF_buffer;
        }
        for ( $cycle = 1; $cycle; ) {
            if ( GIFDecoder::GIFGetByte ( 1 ) ) {
                switch ( $this->GIF_buffer [ 0 ] ) {
                    case 0x21:
                        GIFDecoder::GIFReadExtensions ( );
                        break;
                    case 0x2C:
                        GIFDecoder::GIFReadDescriptor ( );
                        break;
                    case 0x3B:
                        $cycle = 0;
                        break;
                }
            }
            else {
                $cycle = 0;
            }
        }
    }
    /*
    :::::::::::::::::::::::::::::::::::::::::::::::::::
    ::
    ::  GIFReadExtension ( )
    ::
    */
    function GIFReadExtensions ( ) {
        GIFDecoder::GIFGetByte ( 1 );
        if ( $this->GIF_buffer [ 0 ] == 0xff ) {
            for ( ; ; ) {
                GIFDecoder::GIFGetByte ( 1 );
                if ( ( $u = $this->GIF_buffer [ 0 ] ) == 0x00 ) {
                    break;
                }
                GIFDecoder::GIFGetByte ( $u );
                if ( $u == 0x03 ) {
                    $this->GIF_anloop = ( $this->GIF_buffer [ 1 ] | $this->GIF_buffer [ 2 ] << 8 );
                }
            }
        }
        else {
            for ( ; ; ) {
                GIFDecoder::GIFGetByte ( 1 );
                if ( ( $u = $this->GIF_buffer [ 0 ] ) == 0x00 ) {
                    break;
                }
                GIFDecoder::GIFGetByte ( $u );
                if ( $u == 0x04 ) {
                    $buf4 = count($this->GIF_buffer) >= 5 ? $this->GIF_buffer [ 4 ] : 0;
                    if ( $buf4 & 0x80 ) {
                        $this->GIF_dispos [ ] = ( $this->GIF_buffer [ 0 ] >> 2 ) - 1;
                    }
                    else {
                        $this->GIF_dispos [ ] = ( $this->GIF_buffer [ 0 ] >> 2 ) - 0;
                    }
                    $this->GIF_delays [ ] = ( $this->GIF_buffer [ 1 ] | $this->GIF_buffer [ 2 ] << 8 );
                    if ( $this->GIF_buffer [ 3 ] ) {
                        $this->GIF_TransparentI = $this->GIF_buffer [ 3 ];
                    }
                }
            }
        }
    }
    /*
    :::::::::::::::::::::::::::::::::::::::::::::::::::
    ::
    ::  GIFReadDescriptor ( )
    ::
    */
    function GIFReadDescriptor ( ) {
        $GIF_screen    = Array ( );

        GIFDecoder::GIFGetByte ( 9 );

        //xurei - metadata saving
        $this->GIF_frames_meta[] = array(
            'left'=>$this->GIF_buffer[0] + ($this->GIF_buffer[1] << 8),
            'top'=>$this->GIF_buffer[2] + ($this->GIF_buffer[3] << 8),
            'width'=>$this->GIF_buffer[4] + ($this->GIF_buffer[5] << 8),
            'height'=>$this->GIF_buffer[6] + ($this->GIF_buffer[7] << 8),
        ); 

        $GIF_screen = $this->GIF_buffer;
        $GIF_colorF = $this->GIF_buffer [ 8 ] & 0x80 ? 1 : 0;
        if ( $GIF_colorF ) {
            $GIF_code = $this->GIF_buffer [ 8 ] & 0x07;
            $GIF_sort = $this->GIF_buffer [ 8 ] & 0x20 ? 1 : 0;
        }
        else {
            $GIF_code = $this->GIF_colorC;
            $GIF_sort = $this->GIF_sorted;
        }
        $GIF_size = 2 << $GIF_code;
        $this->GIF_screen [ 4 ] &= 0x70;
        $this->GIF_screen [ 4 ] |= 0x80;
        $this->GIF_screen [ 4 ] |= $GIF_code;
        if ( $GIF_sort ) {
            $this->GIF_screen [ 4 ] |= 0x08;
        }

        /*
         *
         * GIF Data Begin
         *
         */
        if ( $this->GIF_TransparentI ) {
            $this->GIF_string = "GIF89a";
        }
        else {
            $this->GIF_string = "GIF87a";
        }
        GIFDecoder::GIFPutByte ( $this->GIF_screen );
        if ( $GIF_colorF == 1 ) {
            GIFDecoder::GIFGetByte ( 3 * $GIF_size );
            if ( $this->GIF_TransparentI ) {
                $this->GIF_TransparentR = $this->GIF_buffer [ 3 * $this->GIF_TransparentI + 0 ];
                $this->GIF_TransparentG = $this->GIF_buffer [ 3 * $this->GIF_TransparentI + 1 ];
                $this->GIF_TransparentB = $this->GIF_buffer [ 3 * $this->GIF_TransparentI + 2 ];
            }
            GIFDecoder::GIFPutByte ( $this->GIF_buffer );
        }
        else {
            if ( $this->GIF_TransparentI ) {
                $this->GIF_TransparentR = $this->GIF_global [ 3 * $this->GIF_TransparentI + 0 ];
                $this->GIF_TransparentG = $this->GIF_global [ 3 * $this->GIF_TransparentI + 1 ];
                $this->GIF_TransparentB = $this->GIF_global [ 3 * $this->GIF_TransparentI + 2 ];
            }
            GIFDecoder::GIFPutByte ( $this->GIF_global );
        }
        if ( $this->GIF_TransparentI ) {
            $this->GIF_string .= "!\xF9\x04\x1\x0\x0". chr ( $this->GIF_TransparentI ) . "\x0";
        }
        $this->GIF_string .= chr ( 0x2C );
        $GIF_screen [ 8 ] &= 0x40;
        GIFDecoder::GIFPutByte ( $GIF_screen );
        GIFDecoder::GIFGetByte ( 1 );
        GIFDecoder::GIFPutByte ( $this->GIF_buffer );
        for ( ; ; ) {
            GIFDecoder::GIFGetByte ( 1 );
            GIFDecoder::GIFPutByte ( $this->GIF_buffer );
            if ( ( $u = $this->GIF_buffer [ 0 ] ) == 0x00 ) {
                break;
            }

            /*for ($i=0; $i!=$u; ++$i)
            {
                $this->GIF_string .= $this->GIF_stream { $this->GIF_bfseek++ };
            }*/
            $this->GIF_string .= substr($this->GIF_stream, $this->GIF_bfseek, $u);
            $this->GIF_bfseek += $u;

            //GIFDecoder::GIFGetByte ( $u );
            //GIFDecoder::GIFPutByte ( $this->GIF_buffer );
        }
        $this->GIF_string .= chr ( 0x3B );
        /*
         *
         * GIF Data End
         *
         */
        $this->GIF_arrays [ ] = $this->GIF_string;
    }
    /*
    :::::::::::::::::::::::::::::::::::::::::::::::::::
    ::
    ::  GIFGetByte ( $len )
    ::
    */
    function GIFGetByte ( $len ) {
        $this->GIF_buffer = new SplFixedArray($len);

        $l = strlen ( $this->GIF_stream );
        for ( $i = 0; $i < $len; $i++ ) {
            if ( $this->GIF_bfseek > $l ) {
                $this->GIF_buffer->setSize($i);
                return 0;
            }
            $this->GIF_buffer [$i] = ord ( $this->GIF_stream { $this->GIF_bfseek++ } );
        }
        return 1;
    }
    /*
    :::::::::::::::::::::::::::::::::::::::::::::::::::
    ::
    ::  GIFPutByte ( $bytes )
    ::
    */
    function GIFPutByte ( $bytes ) {
        $out = '';
        foreach ( $bytes as $byte ) {
            $out .= chr($byte);
        }
        $this->GIF_string .= $out;
    }
    /*
    :::::::::::::::::::::::::::::::::::::::::::::::::::
    ::
    ::  PUBLIC FUNCTIONS
    ::
    ::
    ::  GIFGetFrames ( )
    ::
    */
    function GIFGetFrames ( ) {
        return ( $this->GIF_arrays );
    }
    /*
    :::::::::::::::::::::::::::::::::::::::::::::::::::
    ::
    ::  GIFGetFramesMeta ( )
    ::
    ::  xurei - returns metadata as an array of arrays
    */
    function GIFGetFramesMeta ( ) {
        return ( $this->GIF_frames_meta );
    }
    /*
    :::::::::::::::::::::::::::::::::::::::::::::::::::
    ::
    ::  GIFGetDelays ( )
    ::
    */
    function GIFGetDelays ( ) {
        return ( $this->GIF_delays );
    }
    /*
    :::::::::::::::::::::::::::::::::::::::::::::::::::
    ::
    ::  GIFGetLoop ( )
    ::
    */
    function GIFGetLoop ( ) {
        return ( $this->GIF_anloop );
    }
    /*
    :::::::::::::::::::::::::::::::::::::::::::::::::::
    ::
    ::  GIFGetDisposal ( )
    ::
    */
    function GIFGetDisposal ( ) {
        return ( $this->GIF_dispos );
    }
    /*
    :::::::::::::::::::::::::::::::::::::::::::::::::::
    ::
    ::  GIFGetTransparentR ( )
    ::
    */
    function GIFGetTransparentR ( ) {
        return ( $this->GIF_TransparentR );
    }
    /*
    :::::::::::::::::::::::::::::::::::::::::::::::::::
    ::
    ::  GIFGetTransparentG ( )
    ::
    */
    function GIFGetTransparentG ( ) {
        return ( $this->GIF_TransparentG );
    }
    /*
    :::::::::::::::::::::::::::::::::::::::::::::::::::
    ::
    ::  GIFGetTransparentB ( )
    ::
    */
    function GIFGetTransparentB ( ) {
        return ( $this->GIF_TransparentB );
    }
}
时间: 2024-10-03 05:30:37

【GIFDecoder】GIFDecoder的排错以及修改另附完整代码和demo的相关文章

全排列的编码与解码:康托展开 (附完整代码)

一.康托展开:全排列到一个自然数的双射 X=an*(n-1)!+an-1*(n-2)!+...+ai*(i-1)!+...+a2*1!+a1*0! ai为整数,并且0<=ai<i(1<=i<=n) 适用范围:没有重复元素的全排列 二.全排列的编码: {1,2,3,4,...,n}的排列总共有n!种,将它们从小到大排序,怎样知道其中一种排列是有序序列中的第几个? 如 {1,2,3} 按从小到大排列一共6个:123 132 213 231 312 321.想知道321是{1,2,3}中

Android编程开发之TextView文字显示和修改方法(附TextView属性介绍)_Android

本文实例讲述了Android编程开发之TextView文字显示和修改方法.分享给大家供大家参考,具体如下: 一. 新建一个Activity 和 Layout 首先在layout文件夹中新建一个activity_main.xml,在新建工程的时候一般默认会新建此xml文件,修改其代码如下: activity_main.xml 代码 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" x

Android编程开发之TextView文字显示和修改方法(附TextView属性介绍)

本文实例讲述了Android编程开发之TextView文字显示和修改方法.分享给大家供大家参考,具体如下: 一. 新建一个Activity 和 Layout 首先在layout文件夹中新建一个activity_main.xml,在新建工程的时候一般默认会新建此xml文件,修改其代码如下: activity_main.xml 代码 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" x

Linux下使用python自动修改本机网关代码分享

  这篇文章主要介绍了Linux下使用python自动修改本机网关代码分享,本文直接给出实现代码,需要的朋友可以参考下 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 #!/usr/bin/python #auto change gateway Created By mickelfeng import os import random,re g='gateway 192.168.1.' rand=random.randint(1,3

ajax和ssh框架实现对遍历项的修改(求完整代码)

问题描述 ajax和ssh框架实现对遍历项的修改(求完整代码) 这是我的jsp代码,这里的数据是遍历的,求一个完整的代码,从ajax的传输,到action回应的 解决方案 解决方案二: 从后台返回来的应该是ArrayList<对象实体>,这样的结果应该是查询数据库中多行记录, 你只需要action中定义一个 private List listUser = null; private List getListUser() { if(reuslt == null){ return Collecti

攻击场景还原:本地ROOT Moto G4 &amp; G5设备(附利用代码)

本文讲的是攻击场景还原:本地ROOT Moto G4 & G5设备(附利用代码),在之前的文章中,我们曾提到CVE-2016-10277可能会影响其他摩托罗拉设备.而在Twitter上收到一些相关的报告之后,我们购买了摩托罗拉的几台设备,并且更新到最新的可用版本以进行此次的测试. Moto G4 athene XT1622,运行的系统:NPJS25.93-14.4,bootloader moto-msm8952-B1.05. Moto G5 cedric XT1676,运行的系统:NPP25.1

认证系统-进行单点登录,用不用修改原有系统的代码?

问题描述 进行单点登录,用不用修改原有系统的代码? 如果进行多系统整合,开发一个统一的认证系统,进行单点登录,用不用修改原有系统的代码?假如没有原有系统的代码怎么办? 解决方案 修改原有代码是必须的啦,如果不进行修改就可以的话,只能说明原有代码就有bug,而且在进行多系统整合的时候还有很多注意项:比如权限... 解决方案二: 几乎可以肯定的是,完全不修改原有代码是不可能的.除非原有系统本身有漏洞.因为本质上来说,不修改原有程序意味着可以通过欺骗的办法绕过登录逻辑. 解决方案三: 做软件开发不是拼

utf-8-c# 操作xml文件进行修改 请看下面代码

问题描述 c# 操作xml文件进行修改 请看下面代码 这是一个app.xml文件中的 <?xml version="1.0" encoding="utf-8"?> <appSettings> <appSetting key="张三" value="1" notes="上次读取到的表面位移模块当前月数据表的记录DataID字段值" /> <appSetting key

网页设计与开发-请帮忙修改优化php的代码

问题描述 请帮忙修改优化php的代码 我的APMServ用不了,看不到效果,请高手帮忙优化一下代码,也就是说看看还能做成怎样更好的效果.我这里是一个成绩查询系统.输入关键字母,会自动根据关键字母检索出含有该关键字母的学生姓名和相应成绩. 解决方案 select * from 表 where Name like '%{$key}%'; like匹配就可以了