我试图将以下图像绘制到画布上,但尽管定义了画布的大小,但它看起来很模糊.正如您在下面看到的,图像清晰而清晰,而在画布上,图像模糊且像素化.
这是它的外观(左边是原始的,右边是绘制的画布,模糊不清.)
我究竟做错了什么?
console.log('Hello world')
var c = document.getElementById('canvas')
var ctx = c.getContext('2d')
var playerImg = new Image()
// http://i.imgur.com/ruZv0dl.png sees a CLEAR, CRISP image
playerImg.src = 'http://i.imgur.com/ruZv0dl.png'
playerImg.width = 32
playerImg.height = 32
playerImg.onload = function() {
ctx.drawImage(playerImg, 0, 0, 32, 32);
};Run Code Online (Sandbox Code Playgroud)
#canvas {
background: #ABABAB;
position: relative;
height: 352px;
width: 512px;
z-index: 1;
}Run Code Online (Sandbox Code Playgroud)
<canvas id="canvas" height="352" width="521"></canvas>Run Code Online (Sandbox Code Playgroud)
无论出于何种原因,我browserify并gulp停止工作.例如,这是我的gulp js脚本捆绑我的JavaScript.
gulp.task('js', function() {
gulp.src('src/js/*.js')
.pipe(plumber())
.pipe(gulp.dest('js'));
return browserify('./src/js/main', { debug: true })
.bundle()
.pipe(source('bundle.js'))
/* .pipe(streamify(uglify()))*/
.pipe(gulp.dest('.'))
.pipe(notify({ message: 'JavaScript has been bundled with Browserify!'}));
// .pipe(livereload());
});
Run Code Online (Sandbox Code Playgroud)
这是main.js:
var ajaxChng = require('./ajax-changelog');
ajaxChng();
Run Code Online (Sandbox Code Playgroud)
里面src/js/ajax-changelog.js是这样的:
module.exports = {
console.log('Hello World');
};
Run Code Online (Sandbox Code Playgroud)
但当我这样做时gulp js,我得到:
? gulp js
[19:11:50] Using gulpfile c:\wamp\www\osrsmap\gulpfile.js
[19:11:50] Starting 'js'...
events.js:85
throw er; // Unhandled 'error' event
^
SyntaxError: Unexpected token
Run Code Online (Sandbox Code Playgroud)
... 我究竟做错了什么?
我一直在讨论这个MySQL查询.
假设我有这个:
$add = "INSERT INTO books (title) VALUES(?)";
if ($stmt = $mysqli->prepare($add)) {
$arr = array($title);
foreach ($arr as $value) {
echo var_dump($value);
}
$stmt->bind_param("s", $title);
Run Code Online (Sandbox Code Playgroud)
有了foreach- > var_dump:
string 'Medieval Times (History)' (length=24)
int 1422843281
int 1420844341
string '127.0.0.1' (length=9)
string 'MY_EMAIL@gmail.com' (length=22)
string '' (length=0)
int 1420844805
int 6
int 3
int 1
int 0
int 0
int 1
int 1
int 1
int 1
Run Code Online (Sandbox Code Playgroud)
好吧,当它到达这一行时它会停止并且我收到此错误:
Fatal error: Call to a member function bind_param() …
所以,我有这个函数可以获得一个JSON对象,但我想让它更简单,所以我创建了一个函数来获取JSON对象的值.为什么不起作用?
var itemData = {
weapon: function () {
return {
1: {
'name': 'Dagger',
'extra_skill': 'none',
'cost': 500,
'attack': 5
},
2: {
'name': 'Pickaxe',
'extra_skill': 'mining',
'cost': 25,
'attack': 5
}
}
},
getWeapon: function (value, x) {
var obj = JSON.parse(value);
return itemData.weapon()[x].obj
}
}
// outputs: Dagger
console.log(itemData.weapon()[1].name)
// Get the name of weapon 1
// however, it outputs: Uncaught SyntaxError: Unexpected token a
console.log('Getting weapon... ' + itemData.getWeapon('name', 1))Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?