473,414 Members | 1,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

save/restore screen area

I'm making a slider widget with a <canvas>.

First I draw the background. I'd like to save this drawing. Something
like:
slider.drawBackground();
slider.back = new ScreenArea( left, top, width, height );

Next, draw the pointer. When the user slides the slider, I'd like to
restore the saved background and then redraw the pointer. Any way of
doing this directly? Something like:
slider.back.restore();
slider.drawPointer();

I've been playing with indirection: using context.toDataURL() (after
drawing the background) but I haven't found a way to take that string
and use it to construct an Image object. What I want is:
slider.back = new Image( context.toDataURL() ); // in my dreams!

Or maybe:
slider.back = new Image( wid, hgt );
slider.back.src = context.toDataURL(); // still dreaming
Oct 22 '08 #1
8 2878
On Oct 22, 1:12*pm, MartinRineh...@gmail.com wrote:
I'm making a slider widget with a <canvas>.
Why?
Oct 22 '08 #2
On Oct 22, 7:12 pm, MartinRineh...@gmail.com wrote:
(...)
I've been playing with indirection: using context.toDataURL() (after
drawing the background) but I haven't found a way to take that string
and use it to construct an Image object. What I want is:
slider.back = new Image( context.toDataURL() ); // in my dreams!

Or maybe:
slider.back = new Image( wid, hgt );
slider.back.src = context.toDataURL(); // still dreaming
var img= document.createElement('img');
img.src= context.toDataURL();

--
Jorge.
Oct 23 '08 #3
David Mark wrote:
On Oct 22, 1:12�pm, MartinRineh...@gmail.com wrote:
I'm making a slider widget with a <canvas>.

Why?
Because I need a slider for my color chooser which I'm writing after
asking my very smart friend Mr. Google about JS color choosers. He led
me to many. But when I said "I want to be able to pick a color by
clicking in a color wash, by supplying RGB values, by entering hex or
by picking from a palette of recent choices, Mr. Google told me I was
on my own.
Oct 23 '08 #4

Jorge wrote:
var img= document.createElement('img');
img.src= context.toDataURL();
Thank you!

Any reason why this works but 'new Image()' doesn't?
Oct 23 '08 #5
On Oct 23, 3:29*pm, MartinRineh...@gmail.com wrote:
Jorge wrote:
var img= document.createElement('img');
img.src= context.toDataURL();

Thank you!

Any reason why this works but 'new Image()' doesn't?
No idea. I didn't know that new Image() existed. What other tags have
a constructor ?

--
Jorge.
Oct 23 '08 #6
Still not working. Here I've got a second 'test' canvas. Attempt to
save image and redraw in the test area. Code:

var img = document.createElement( 'img' );
img.src = slider.canvas.toDataURL( 'image/png' );
alert( img.src.length )
var t = document.getElementById( 'test' );
var pen2 = t.getContext( '2d' );
pen2.drawImage( img, 0, 0 );

This is called after painting the background from <bodyonload(). The
alert() gives different results (from a low around 250 to a high over
10,000).

P.S. WORKING! I have no clue why. Trivial change, looks functionally
identical.

var img = document.createElement( 'img' );
var str = slider.canvas.toDataURL( 'image/png' );
alert( str.length )
img.src = str;
var t = document.getElementById( 'test' );
var pen2 = t.getContext( '2d' );
pen2.drawImage( img, 0, 0 );

The alert gives different results, but in the 300 to 315 range.
Oct 23 '08 #7
Jorge wrote:
No idea. I didn't know that new Image() existed. What other tags have
a constructor ?
Since 'document.createElement()' works and 'new Image()' doesn't, I'm
going to pretend the former is the real constructor.
Oct 23 '08 #8
On Oct 23, 8:05*pm, MartinRineh...@gmail.com wrote:
Jorge wrote:
No idea. I didn't know that new Image() existed. What other tags have
a constructor ?

Since 'document.createElement()' works and 'new Image()' doesn't, I'm
going to pretend the former is the real constructor.
document.createElement('img') way of creating an image object is a
part of the DOM specification; new Image() isn't. The valid
invocations of the Image constructor are:
var i = new Image();
i.src = 'images/ah.png';

var i = new Image(250 /*width*/, 250 /*height*/);
i.src = 'images/ah.png';

/sasuke
Oct 24 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Andras Gilicz | last post by:
Hi VB fans I'm working on a relatively large project in VB6 with about a dozen forms, including graphs, labels, text boxes, etc. The software itself is actually a flow simulator with more or...
1
by: Dave Romig | last post by:
Can anyone provide guidance for saving and restoring an XMLDOM object as a binary blob? In a VB application, I need to repeatedly save and restore a large, dynamic XML document. Currently, the...
5
by: Paul Sullivan | last post by:
We are a state agency that views protected medical information via our intranet. The screens even have privacy shields. Alarmingly, uses can "Print" and "Save As" which destroys the protection of...
5
by: JezB | last post by:
There are a few references on the net about how to restore a page's scroll position over a postback. This is a simple one which works for me: eg....
7
by: Wayne | last post by:
I have found the following code on this newsgroup that removes the Access Application minimize, restore and close buttons. Private Const GWL_EXSTYLE = (-20) Private Const GWL_STYLE = (-16) ...
14
by: fdu.xiaojf | last post by:
Hi, I have a program which will continue to run for several days. When it is running, I can't do anything except waiting because it takes over most of the CUP time. Is it possible that the...
13
by: Joe | last post by:
does anyone know why this source code throws an error?? Dim myBitmap As System.Drawing.Bitmap Dim myGraphics As Graphics myBitmap = New System.Drawing.Bitmap(fileName:="C:\test.tif")...
2
by: Alan Forsyth | last post by:
That rather long subject says it. In Access97 running on XP - I want to display a Maximized size Form01, then open a Restore size Datasheet View Form02 on top of the first Form. PopUp won't give...
4
by: mike | last post by:
I have the opportunity to rescue a project that uses a mouse to sense the relative position of a machine. The hardware is built...just needs to be programmed. Stop snickering!!! I didn't do it...I...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.