|
is this the fastest way to access the RGB values of a pixel of a bitmap file in c#?
the code is below
bm is previously declared Bitmap object.
Collapse
BitmapData bmd=bm.LockBits(new Rectangle(0, 0, 10, 10), System.Drawing.Imaging.ImageLockMode.ReadOnly, bm.PixelFormat);
int PixelSize=4;
for(int y=0; y<bmd.Height; y++)
{
byte* row=(byte *)bmd.Scan0+(y*bmd.Stride);
for(int x=0; x<bmd.Width; x++)
{
row[x*PixelSize]=255;
}
}
OR is there more faster way exists to access the RGB values of a pixel in C# or in VC++?
if in VC++ we can access the RGB values more faster than this so please help me.
and if the above method is the fastest way and no other faster method exists than this in c# or in VC++ so please comment as well.
thanks
|
|
|
|
|
Are you writing to a bitmap locked as ReadOnly..?
|
|
|
|
|
|
That doesn't mean you should do it
Using an uint* may be slightly faster, I'm not sure. I can take a look at it later today, my thought is that there would be a better chance that the free scaling factor in SIB addressing could be used.
edit: probably won't help if you only intend to write to 1 channel, but who knows.. making that 4 a const int or just writing it explicitly may help too
edit2: see post below. It doesn't help.
|
|
|
|
|
sir where should i use it in the code?
|
|
|
|
|
Nevermind, I just tested it, it doesn't matter - what does matter a lot though is whether the width (as used in the for loop) is a constant or not.
If it's a constant multiple of 2, the loop is unrolled by a factor 2. (or 4 for multiples of 4)
So if you know in advance that the width is going to be 10, use 10 everywhere instead of bm.Width . A const int works too, but you have to actually declare it as const otherwise it doesn't help.
All tests were done with the x64 JIT on a release build.
|
|
|
|
|
thank you sir it worked. the speed increased when i used constants in place of calling a property in the for loop.
thanks a lot
|
|
|
|
|
I've searched around but I can't seem to find anything about what I'm trying to do. What I'm trying to do is create an app that has an iTunes look to it.
See here: http://www.askdavetaylor.com/0-blog-pics/windows-itunes-store.png[^]
Notice how the file menu, program title and close/minimize/maximize buttons are all on the same row and the top of the program is one big silver block with stuff on it. How did Apple do that for the Windows version of iTunes? Valve did a similar kind of thing with Steam.
|
|
|
|
|
It's an application where the form is owner drawn. You could accomplish this, relatively easily, using WPF.
|
|
|
|
|
Hi Pete,
With Windows Phone 7 coming and the survival of Silverlight, I've pretty much decided it's time to take the plunge into WPF
When I last had a quick look in the early days there wasn't a whole lot of info around. Now there's the opposite, a plethora of stuff, most of which is probably chaff!
Any reliable sources, online or printed, free or paid that you would recommend?
|
|
|
|
|
Pete O’Hanlon, 12-AUG-2008: I've learned a lot of WPF from:
• http://www.amazon.com/Pro-WPF-2008-Presentation-Professionals/dp/1590599551/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1218549917&sr=1-1
• http://www.amazon.com/Windows-Presentation-Foundation-Unleashed-WPF/dp/0672328917/ref=pd_bbs_sr_2?ie=UTF8&s=books&qid=1218549970&sr=1-2
• http://www.amazon.com/Programming-WPF-Chris-Sells/dp/0596510373/ref=pd_bbs_sr_3?ie=UTF8&s=books&qid=1218550181&sr=1-3
The Pro WPF is the best, closely followed by the Unleashed book. The Sells book is good, but the other two are of such a high quality that they really should be your first port of call.
|
|
|
|
|
Thanks Luc, I'll check them out. Probably get the Pro WPF and put the others on the list going to Santa!
|
|
|
|
|
Hi Dave,
you're welcome.
I have the Pro WPF one, haven't opened it yet.
There may be better in the mean time, I haven't seen any higher recommendation though.
|
|
|
|
|
|
|
Sorry mate - I've been away for a couple of days; Luc's answer is pretty comprehensive - Adam Nathan has a new book out on WPF and it's really good - you can also learn a lot from Josh Smith, Karl Shifflett, Sacha Barber (or even my article on moving to WPF from ASP.NET).
|
|
|
|
|
Thanks Pete, hope you've had a good time away. I was up your way-ish last week in Hartlepool, an 'interesting' place!
I've ordered Pro WPF! I've had a search around and bookmarked a few things. Josh, Karl and Sacha are quite legendery of course I'm sure I'll be visiting their and your stuff in time. A well structured book is hard to beat though when approaching a new subject I think.
I'm quite looking forward to the challenge. It's the XAML "look at what you can do without any code at all" type things I came across that have put me off until now. I've always been a dig into the dirty code type, not a drag and drop automagic coder so that side of it doesn't really appeal to me. I'll see how it goes I suppose.
|
|
|
|
|
You should have dropped me a line - I'd have come down to meet you for a few drinks. Anyway, I started off my XAML career handcrafting it, the Cider designer used to be too buggy to use properly. If you handcraft it, you soon get a feel for how it all hangs together.
|
|
|
|
|
Source Code:
WPF GIF Animation
Current situation:
The animation is run in a list but I want that the animation run without a list.
My current code:
using System;
using System.Windows;
using System.Drawing;
using System.Diagnostics;
using WpfAnimatedControl;
using System.Windows.Documents;
using System.Collections.Generic;
namespace AnimatedControlTester
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
rich.Document = new System.Windows.Documents.FlowDocument();
Paragraph p = new Paragraph();
AnimatedImage aimg = new AnimatedImage();
aimg.Stretch = System.Windows.Media.Stretch.None;
System.Drawing.Image img;
img = AnimatedControlTester.Resources.Hexe;
aimg.LoadSmile((System.Drawing.Bitmap)img);
p.Inlines.Add(aimg);
rich.Document.Blocks.Add(p);
image1.Source = p;
}
private void aimg_AnimatedBitmapChanged(object sender, RoutedPropertyChangedEventArgs<Bitmap> e)
{
Debug.WriteLine("AnimatedBitmapChanged event occured, add extra code here if necessary.");
}
}
}
Error on line:
image1.Source = p;
Error:
Cannot implicitly convert type 'System.Windows.Documents.Paragraph' to 'System.Windows.Media.ImageSource'
|
|
|
|
|
I have solve the problem on an easier way:
XAML:
<RichTextBox Height="223" HorizontalAlignment="Left" Margin="53,72,0,0" Name="rich" VerticalAlignment="Top" Width="182" BorderThickness="0" VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Disabled">
<RichTextBox.Background>
<SolidColorBrush />
</RichTextBox.Background>
|
|
|
|
|
i have two forms(Form1 and Form2).i open Form2 as a child of Form1 with the code below..
Form2 frm2 = new Form2();
frm2.MdiParent = this;
frm2.Show();
but Form2 is opened under of Form1's controls..how i will get it front..i tried right click and send back to all controls in Form1 but still nothing..what should i do now ?
|
|
|
|
|
This question should be placed into Windows Forms forum. I will answer anyway, but try to use the right forum next time.
Usually the visible controls used within a MDIContainer Form should be MenuStrip, StatusStrip and ToolStrip. What controls are you using in Form1?
|
|
|
|
|
i have two datagridviews and buttons in parent form..but i think there will be more controls like textboxes..so what can i do now
i tried also
frm2.TopMost=true;
frm2Activate();
but i couldnt get the result
|
|
|
|
|
Ok, I see. Add a ToolStripContainer to Form1, change its Dock property to Top, and move all that stuff you have in Form1 into this ToolStripContainer.
|
|
|
|
|
thanks for the reply friend..i tried like
Form2 frm2 = new Form2();
frm2.MdiParent = this.MdiParent;
frm2.Show();
it is opened on other controls but when i want to minimize i want to stay it in main form but it is seen on task bar
how i will manage it ?
modified on Saturday, October 23, 2010 8:01 AM
|
|
|
|