前端如何应用php和js来实现显示pgm图片

问题描述

canvas无法直接显示,我想用php读取也是乱码,或者告诉我怎么用php读取pgm格式的图片

问题出现的环境背景及自己尝试过哪些方法

查过github,以及各种各样的网站

相关代码

 public function scy()
    {
        $file_path = "E:/map.pgm";
        if(file_exists($file_path)) {
            $str = file_get_contents($file_path);//将   整个文件内容读入到一个字符串中
            $str = str_replace("\r\n", "<br />", $str);
//            $substr
            echo $str;
        }
    }
        mapview(function (url) {
        zhenmapview(url);
    });
    function mapview(callblack){
//        console.log(886);
//        var cvs =document.getElementById("canvas");
//
//        var ctx =cvs.getContext("2d");
        var img = new Image();
        var Num = Math.random()*10;
        img.src ="__STATIC__/img/map.pgm?"+Num;
//        canvas_mapW = img.width;
//        canvas_mapH = img.height;
//        console.log(canvas_mapW,canvas_mapH);
//        cvs.height = img.height;
//        cvs.width = img.width;
        img.onload=function (){
//            ctx.drawImage(img,0,0);
            callblack(img.src);

        };
        function getEventPosition(ev){
            var x, y;
//        if (ev.layerX || ev.layerX == 0) {  这是兼容的写法,以后有问题看这里
            y = ev.offsetY;
//        }
            return {x: x, y: y};
        }
        //********************************在地图上画点**********************************************************

    }
阅读 3k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题