|
This is probably a simple problem as the most I've ever done with GDI was a simple ray tracer that drew a circle on a flat plain using drawline ALOT. Needless to say... I'm a GDI nub.
So anyway, I tried to use Bitmap.Save to take a screenshot of each of the windows on a WinForm application. This works great on the first run, but if I run the function a second time an exception is thrown where I called the save.
I decided to use a filestream so I'd have control over the stream instead of passing a pathname. Even though I close the stream when I'm done with it, it throws a file in use exception when I try to create the stream on the second go around.
Here's my current code:
<br />
Bitmap mybmp = new Bitmap(formwidth, formheight,PixelFormat.Format32bppArgb)<br />
<br />
System.IO.FileStream fs = System.IO.File.Open(imagePath, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.ReadWrite);<br />
<br />
mybmp.Save(fs, ImageFormat.Jpeg);<br />
fs.Close();<br />
Am I missing something here?
|
|
|
|
|
This doesn't help much, but your code works fine for me - calling it multiple times.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
If you were to open the same file using Bitmap bm = new Bitmap(imagePath) somewhere, THEN it would be locked as long as that bitmap was open. Using a filestream to open a bitmap and closing the stream, solves the problem.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Take a GIF.
My GIF for example:
http://reelix.googlepages.com/ReeFlame.gif[^]
Look at in in the browser... Looks good, hey? (Well, my opinion anyways)
Save it to Windows (I can only test with XP - Not sure if it does it in Vista)
Open it in Windows Default Image Viewer.
Laaaaaaggg....
Any reason for this?
Was looking into C# GDI+ GIF Animation, and this... Issue arose...
Any ideas, anyone?
- Reelix
|
|
|
|
|
Looks the same to me either way. Also animating at the same speed.
Best Wishes,
-David Delaune
|
|
|
|
|
Found it does the same in IE (Seems to be the same Bug) - Sure you're not an IE Fan? :p
Try the same GIF in FireFox.
Havn't tried Opera Yet...
- Reelix
P.S: If anyone is interested... I suceeded with my C# GDI+ GIF Animation:
http://reelix.googlepages.com/gifAnimation.txt[^]
|
|
|
|
|
Reelix wrote: Sure you're not an IE Fan?
Like many people these days I use multiple browsers. I have checked the GIF file in IE Opera and Safari and there is no lag I can detect visually.
Reelix wrote: Try the same GIF in FireFox.
I'll take your word for it instead. I am not a big fan of past releases of Firefox. I will take a look at the next generation of Firefox when it is released. I have read an article about how they optimized image cache and greatly improved memory management. But for now I am happy with IE and Opera.
Best Wishes.
-David Delaune
|
|
|
|
|
Hi all,
I have created a double buffering drawing method,the code as below:
BufferedGraphicsContext CurrentContext = BufferedGraphicsManager.Current;
BufferedGraphics bg = CurrentContext.Allocate(this.CreateGraphics(), this.ClientRectangle);
bg.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
bg.Graphics.Clear(this.BackColor);
this.draw(bg.Graphics)
bg.Render();
bg.Dispose();
My question is how can i draw the graphic to bitmat or any type of picture?
Note: This drawing method is build in custom user control
thanks in advance
cocoon
|
|
|
|
|
Hi all,
I got the solution,very simple. Thanks for those who are read through my question.Thanks
|
|
|
|
|
Hello there,
I have already used DirectX.Capture to preview what my web cam sees on a panel in my form.
Now I need to somehow transmit this to a client through the network. All I now about
network programming, is that I can only send byte arrays to the client. Any ideas on how
I will get that?
|
|
|
|
|
Chandrias wrote: All I now about
network programming, is that I can only send byte arrays to the client. Any ideas on how
I will get that?
Then you need to send arrays of bytes which represent the pixels in the frames of video.
If your available bandwidth isn't able to handle the number of bytes-per-second required
to transmit the given video dimensions and frame rate, then you'll need to compress the video
somehow. The Video Compression Manager[^] or the Windows Media Format SDK[^] are two
possible solutions for compressing/decompressing video. There's also lots of 3rd party video
codecs.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
How to check in C# if directx is installed and which version of it?
|
|
|
|
|
By checking in the registry, there are entries for DirectX version, etc.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
|
|
dapa wrote: Hello! I need the sample of code of "warp mode image transformation" in photoshop.
http://en.wikipedia.org/wiki/Spline_interpolation[^]
_________________________
Asu no koto o ieba, tenjo de nezumi ga warau.
Talk about things of tomorrow and the mice in the ceiling laugh. (Japanese Proverb)
John Andrew Holmes "It is well to remember that the entire universe, with one trifling exception, is composed of others."
|
|
|
|
|
|
Thank you, Y will to try to do it
|
|
|
|
|
As the subject says I'm looking for an algorithm to scan an image and extract the rectagles that have the same pixel color.
Thanks in advance.
modified on Monday, April 14, 2008 11:44 AM
|
|
|
|
|
Hi,
first of all we have a "math and algo" forum, you should ask there.
I don't know of any official algorithm that matches your request, but it sounds fairly
simple to me; here is some pseudo-code:
rectCollection=empty;
foreach (point P in image and not in rectCollection) {
w=number of identically colored points to the right of P
h=number of identically colored points below P
check rectangle at P with size (w,h) has homogeneous color
if so, add to rectCollection
if not, reduce w and or h based on the position of the first non-matching point
}
done!
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
This could work Luc, thank you, but it looks very inefficient. I have to do this at least twice every second.
|
|
|
|
|
Hi,
there may be better algorithms, it probably depends on the kind of image you are dealing with.
what is the image size?
make sure you use pointers, don't rely on Bitmap.GetPixel, that is way too slow.
are the consecutive images similar?
do the rectangles found have a good chance of being there again on the next image?
if so, make use of it!
you do realize there is no single solution to your problem? if you have
AA
AB
then you can describe it as:
1) A A
A B
2) AAA
A B
3) A A
A
A B
It might help if you describe the intended application a bit...
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
modified on Tuesday, April 15, 2008 8:05 PM
|
|
|
|
|
My friend and I were having an argument about the drawing speed of GDI+. First he presented the flicker problem, but I fixed that with
SetStyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
then, after awhile, he presented the following:
<br />
using System;<br />
using System.Drawing;<br />
using System.Drawing.Imaging;<br />
using System.Runtime.InteropServices;<br />
using System.Windows.Forms;<br />
<br />
namespace SlowGdi {<br />
public partial class SlowGdiForm : Form {<br />
<br />
private Random RandomSource = new Random();<br />
<br />
private int[] RandomPixels = new int[512 * 512];<br />
<br />
private Bitmap RandomBitmap = new Bitmap(512, 512);<br />
<br />
public SlowGdiForm()<br />
{<br />
InitializeComponent();<br />
this.Disposed += (sender, e) => this.RandomBitmap.Dispose();<br />
Application.Idle += (sender, e) => this.Invalidate();<br />
}<br />
<br />
private void SlowGdiForm_Paint(object sender, PaintEventArgs e)<br />
{<br />
for (int i = 0; i < RandomPixels.Length; i++) {<br />
this.RandomPixels[i] = this.RandomSource.Next();<br />
}<br />
var Locked = this.RandomBitmap.LockBits(new Rectangle(0, 0, 512, 512), ImageLockMode.WriteOnly, PixelFormat.Format32bppRgb);<br />
Marshal.Copy(this.RandomPixels, 0, Locked.Scan0, 512 * 512);<br />
this.RandomBitmap.UnlockBits(Locked);<br />
e.Graphics.DrawImage(this.RandomBitmap, 0, 0, 512, 512);
}<br />
<br />
private void SlowGdiForm_Load(object sender, EventArgs e)<br />
{<br />
SetStyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);<br />
}<br />
}<br />
}<br />
<br />
This looks all cool, but do a quick Ctrl+Alt+Delete, and notice the 100% Processor Usage (50% on Dual Core)
Anyone have any idea on how to optimise the code to NOT annihilate the processor?
Thanks
- Reelix
P.S: Thread.Sleep(1); helps abit, but not all that much...
P.P.S: Apparently it works perfectly on Vista...
modified on Monday, April 14, 2008 7:58 AM
|
|
|
|
|
Reelix wrote: Application.Idle += (sender, e) => this.Invalidate();
it doesn't matter if you are doing GDI or OpenGL, this will run full out on any machine you are "allowed" to have full access to the CPU. You don't force a redraw on idle you force a redraw on vertical retrace or other unless you do want all the CPU.
|
|
|
|
|
HI ,
i want to do a project on graphics as part of my engineering course .
i have decided to do a project other than game ..i have to use all the basic algorithms and some of the in built functions that are available in turbo C ... please suggest me different topics on which i can do a project .. the code shoudnt exceed 900 lines ...
i have plans to do animation(changing the face with user interface) , simulating towers of hanoii problem ,etc ..suggest me better ideas/topics to do the same
thanks
|
|
|
|