Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #32238
| Newsgroups | comp.lang.javascript |
|---|---|
| Date | 2017-01-21 10:51 -0800 |
| References | <c96cc74a-57a5-450f-a21c-4301e65a0963@googlegroups.com> <381d6ef0-6409-4d4b-969f-9bc3caea1a8e@googlegroups.com> <e998931a-614e-4b40-ada6-8f49d7ef75b9@googlegroups.com> |
| Message-ID | <cc15f276-e0be-4603-988b-46e8d77cf281@googlegroups.com> (permalink) |
| Subject | Re: Save png |
| From | jonas.thornvall@gmail.com |
Den lördag 21 januari 2017 kl. 19:44:20 UTC+1 skrev jonas.t...@gmail.com:
> Den lördag 21 januari 2017 kl. 19:18:24 UTC+1 skrev jonas.t...@gmail.com:
> > Den lördag 21 januari 2017 kl. 19:00:36 UTC+1 skrev jonas.t...@gmail.com:
> > > I draw to the canvas, added a eventlistener to a save button. I have no specifical image manupulation code, when the button pressed i want a snapshot of canvas. But the colors and format come out all wrong.
> > >
> > > function savepng() {
> > > var mypic = canvas.toDataURL('image/png');
> > > var anobject = document.createElement('a');
> > > anobject.href = mypic;
> > > anobject.download = document.save.filename.value;
> > > anobject.click()
> > > }
> > >
> > >
> > > Don't ask me what 'a' is, i just copied the code, but i guess it is just any name used to create space for the image object.
> > >
> > > It does save something, but the original black background comes out as white, instead of black, so anything white dissapears, first i thought it was something about the canvas background being black. So i changed color with same result the canvas come out white, i could think that the canvas background really not part of the canvas image object. Must i really make a black rectangle in background when saving?
> > >
> > > It seems weird, or maybe i missunderstand the problem to begin with, but it seem canvas background not part of the canvas.
> > >
> > > JT
> >
> > I was correct in my assesment, but there still something wrong with the saved dataformat for picture microsoft paint have no trouble open it, but the picture shower in windows refuse to show the picture. And i have hard to imagine it can't handle png.
> >
> > But isn't it weird i had to replace clearRect with fillRect in my redraw function. Why isn't canvas background part of the image object created?
> >
> > function redraw()
> > {
> > // Clear canvas
> > // ctx.clearRect(0, 0, canvas.width, canvas.height);
> > ctx.fillStyle = "black";
> > ctx.fillRect(0, 0, canvas.width, canvas.height);
> > // Redraw canvas
> > if ((connected==true) && (regular==true)) paint_out(canvas, message);
> > }
>
> https://1drv.ms/i/s!AonBnYlXpxi4gaIpJIN50FrYyKS5aA
>
> Here is the picture saved as a JPG but there must be some scaling data missing, it show up minimal in the left upper corner when in reality is a big picture. In microsoft paint it will show up at original scale when you open.
> How can i get the scaling data correct?
>
> For picture with bigger dataset painted i get download interupted network error, somewhere i read saving as jpg somehow should shrink the data but it does not help, i get the same error when there is more data in picture.
>
> Is there a way to go around "download, interupted network error" when saving pictures local?
No the picture was scaled correct it turn out, that i have a real big canvas i just forgotten.
So now i must see if i can set a range for canvas to dataUrl or simply must change the size.
Case closed, but it would be nice to find out the interupted network error anyhow.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread
Save png jonas.thornvall@gmail.com - 2017-01-21 10:00 -0800
Re: Save png jonas.thornvall@gmail.com - 2017-01-21 10:18 -0800
Re: Save png jonas.thornvall@gmail.com - 2017-01-21 10:44 -0800
Re: Save png jonas.thornvall@gmail.com - 2017-01-21 10:51 -0800
csiph-web