|
|
Thanks for the info Maysam!
I'm new to programming... it seems like a lot of code to
hide a variable with each listbox item. Is it because listbox
was not originally designed to have hidden variables?
Ron
|
|
|
|
|
I have a bitmap...
Bitmap bmp = new Bitmap("tiff48bppRgb.tiff")
The pixel format for the bitmap is...
System.Drawing.Imaging.PixelFormat.Format48bppRgb
My problem is that when I call bmp.GetPixel(0,0), I get a Color object that only represents 32bppArgb. So the extra information (48bppRgb) is lost.
Please Help! I have spent the last week programming an application, and I really need to extract 48bppRgb info from the Bitmap object, otherwise all is lost.
Dave
|
|
|
|
|
You can't use GetPixel because the Color it returns only supports 8 bits per channel.
You'll have to write your own code to return the colors and manipulate them on a per pixel basis. Start by reading this[^] series of excellent articles by Christian Graus. He demonstrates the technique your looking for.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Fantastic, this has really helped. Thanks very much!
As a side note, my TIFF files were originally recorded by a camera that is built for the scientific community. Unlike most commercial cameras, this camera does not automatically transform the amount of photons it collects on each pixel (this transformation is similar to a gamma correction). After I applied the solution you suggested, I found that my numbers were systematically off. I had to correct my numbers by the following transform...
[R G B] is what I get from Bitmap.GetPixel
[r g b] is what I got from the unsafe code that I executed.
R = 2.5 * r^(1/2.4) - 0.056
G = 2.5 * g^(1/2.4) - 0.056
B = 2.5 * b^(1/2.4) - 0.056
Applying this transform reduced by Mean-Squared-Error per pixel to about 10^-7.
It seems liike the tags inside of the TIFF file recorded the fact that a transform had not been applied, so GDI+ does the transform automatically when creating the Bitmap object. Add that to the list of things that GDI+ does without us knowing!
Dave
|
|
|
|
|
It does this probably because of the color management profile for the video device (monitor/video card). Go to the Display Properties Control Panel/Settings/Advanced/Color Management tab for a look at what I'm talking about.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Good idea, but I didn't find anything there. My machine's gamma / contrast / brightness settings don't predict what I'm seeing.
Apparently, the transform only happens when I use 48-bpp TIFF files from the special camera because it didn't happen when I used normal 24-bpp BMP files.
For the special camera's TIFF files, the GDI+ generates a decompressed pixel value equal to P, whereas the raw stored value is actually p.
gamma = 2.45
P = gamma * p^(1/gamma)
So it must be something with the TIFF decompressor in combination with a tag set by the camera. Thanks again for the help. Case closed.
Dave
|
|
|
|
|
I'm posting the C# solution to my original problem so that anybody who runs into the same problem can have the solution.
First, you need to import a very nice C++ DLL called BMGLib. Get it from here: http://members.cox.net/scottheiman/bmglib.htm (please see website for associated credits).
Next, create a Bitmap object (call it bmp) using UnsafeSupport.OpenBitmap. (NOTE: I am giving you the UnsafeSupport class at the end of this e-mail.)
To extract the color information from each pixel, execute the following steps. Given a pixel (int x, int y) and a Bitmap (bmp), you want a vector (float[3] rgb which contains values between 0 and 1 for each color).
float[] rgb = new float[3];
int[] xargbBppCum = UnsafeSupport.XargbBitsPerPixel(BmpOrig.PixelFormat);
for(int i=1; i<xargbBppCum.Length; i++)
xargbBppCum[i] += xargbBppCum[i-1]; //cumulative value
UnsafeSupport.GetRgb(ref rgb, xargbBppCum, x, y, bmp);
That's it. Here is the UnsafeSupport class. It encapsulates the BMGLib DLL. OH, and special thanks to Dave and the article he referenced earlier in the thread.
public unsafe class UnsafeSupport
{
/// <summary>
/// Enumeration supporting LibTiff (and ultimately Bmglib.dll).
/// </summary>
enum TiffCompressionEnum
{ NONE, CCITTRLE, CCITTFAX3, CCITTFAX4, LZW, JPEG6,
JPEG_DCT, NeXT, CCITTRLEW, MACINTOSH, THUNDERSCAN,
PIXARFILM, PIXARLOG, ZIP, KODAK, JBIG };
/// <summary>
/// Enumeration supporting LibTiff (and ultimately Bmglib.dll).
/// </summary>
enum TiffPhotometricEnum
{ MINISWHITE, MINISBLACK, RGB, PALETTE, MASK,
SEPARATED, YCBCR, CIELAB, CIE_LOGL, CIE_LOGLUV };
/// <summary>
/// Enumeration supporting LibTiff (and ultimately Bmglib.dll).
/// </summary>
enum TiffOrientationEnum { TOPLEFT, BOTTOMLEFT };
/// <summary>
/// Enumeration supporting LibTiff (and ultimately Bmglib.dll).
/// </summary>
public struct TIFFInfoStruct
{
TiffCompressionEnum compression;
TiffPhotometricEnum photometric;
TiffOrientationEnum orientation;
ushort predictor;
}
/// <summary>
/// The single import from Bmglib.dll. Supported formats and credits associated with the DLL are listed at
/// http://members.cox.net/scottheiman/bmglib.htm
/// </summary>
/// <param name="filename">string The full path of the bitmap file. The file extension determines the type of decompression.</param>
/// <param name="parameters">(void*)TIFFInfoStruct* Only returns information when a TIFF is decompressed.</param>
/// <param name="blend">int Alpha blending.</param>
/// <returns>IntPtr Handle to a GDI BITMAP object. Use Bitmap.FromHbitmap(IntPtr) to generate a Bitmap object.
/// The high-bit color information will be preserved.</returns>
[DllImport("Bmglib.dll", ExactSpelling=true, SetLastError=true)]
public static extern IntPtr CreateBitmapFromFile( [MarshalAs(UnmanagedType.LPStr)] string filename,
void* parameters, int blend );
/// <summary>
/// Because GDI+ loses 16-bit color information (only preserves 8-bit info) when opening a Bitmap object, this method
/// creates a Bitmap object by using GDI (thus skirting the GDI+ problem). After the GDI BITMAP object
/// is created, the GDI+ bitmap object is then created from the HBITMAP associated to the GDI BITMAP object. The end result
/// is that the 16-bit-color inforamtion is not lost. The endeavor is accomplished by calling the CreateBitmapFromFile method
/// in Bmglib.dll. The file extension determines the type of decompression. Supported formats and credits associated with
/// the DLL are listed here: http://members.cox.net/scottheiman/bmglib.htm
/// </summary>
public static Bitmap OpenBitmap(string filename)
{
TIFFInfoStruct tis = new TIFFInfoStruct();
IntPtr hb = CreateBitmapFromFile( filename, (void*) &tis, 0 );
return Bitmap.FromHbitmap( hb );
}
/// <summary>
/// Because GDI+ loses 16-bit color information (only preserves 8-bit info), this method searches the bitmap object and extracts
/// the appopriate 16-bit information about the RGB values for a pixel.
/// </summary>
/// <param name="RGB">float[2] Contains the output. Outputs the RGB values as values within the range of 0 to 1.</param>
/// <param name="xargbBppCum">int[5] 0, wasted bits per pixel; 1, bits per alpha pixel; 2, bits per red pixel; 3, bits per green pixel; 4, bits per blue pixel.</param>
/// <param name="x">int The x-coordinate of the pixel.</param>
/// <param name="y">int The y-coordinate of the pixel.</param>
/// <param name="bmp">Bitmap The bitmap object to extract the pixel information from.</param>
public static void GetRgb(ref float[] RGB, int[] xargbBppCum, int x, int y, Bitmap bmp)
{
RGB[0]=RGB[1]=RGB[2] = 0.0f;
BitmapData bd = bmp.LockBits( new Rectangle(x,y,1,1), ImageLockMode.ReadWrite, bmp.PixelFormat);
// bits per pixel = xargbBppCum[4]
int bypp = xargbBppCum[4]/8;
int jump = bypp*(x+bmp.Width*y);
int i;
ulong pixVal = 0ul;
ulong temp;
for(i=bypp-1; i>=0; i--)
{
pixVal = pixVal << 8;
temp = (ulong)* ( ((byte*)(void*)bd.Scan0) +i );
pixVal += (ulong)* ( ((byte*)(void*)bd.Scan0) +i );
}
int ctBit = xargbBppCum[4];
i=4;
ulong pval = 1ul;
while(ctBit >= 0 && i>1)
{
if(ctBit > xargbBppCum[i-1])
{
if(pixVal % 2ul == 1ul) RGB[i-2] += (float)pval;
pval = pval << 1;
pixVal = pixVal >> 1;
}
else
{
if(bmp.PixelFormat == PixelFormat.Format48bppRgb)
RGB[i-2] /= (float)(16384ul);
else
RGB[i-2] /= (float)(pval-1ul);
i--;
if(i>1)
{
if(pixVal % 2ul == 1ul) RGB[i-2] =1.0f;
pval = 2ul;
pixVal /= 2ul;
}
}
ctBit--;
if(bmp.PixelFormat == PixelFormat.Format48bppRgb)
{
RGB[0] *=2.0f;
RGB[1] *=2.0f;
RGB[2] *=2.0f;
}
}
bmp.UnlockBits(bd);
}
/// <summary>
/// Used for manually striding a Bitmap object (using pointers in unsafe mode). This has only been checked for
/// PixelFormat.Format24bppRgb and PixelFormat.Format48bppRgb. Use with caution for other formats.
/// ------
/// In order to use with GetRgb, you need to translate the output into a cumulative vector. For example, given a
/// bitmap object called bmp, do the following:
/// int[] xargbBppCum = XargbBitsPerPixel(bmp.PixelFormat);
// for(int i=1; i<xargbBppCum.Length; i++) xargbBppCum[i] += xargbBppCum[i-1]; //cumulative value
/// </summary>
/// <param name="pf">PixelFormat The pixel format.</param>
/// <returns>int[5] 0, wasted bits per pixel; 1, bits per alpha pixel; 2, bits per red pixel; 3, bits per green pixel;
/// 4, bits per blue pixel.</returns>
public static int[] XargbBitsPerPixel(PixelFormat pf)
{
int[] output = new int[5];
if(pf == PixelFormat.Format16bppArgb1555)
{
output[0] = 0;
output[1] = 1;
output[2] = 5;
output[3] = 5;
output[4] = 5;
}
else if(pf == PixelFormat.Format16bppRgb555)
{
output[0] = 1;
output[1] = 0;
output[2] = 5;
output[3] = 5;
output[4] = 5;
}
else if(pf == PixelFormat.Format16bppRgb565)
{
output[0] = 0;
output[1] = 0;
output[2] = 5;
output[3] = 6;
output[4] = 5;
}
else if(pf == PixelFormat.Format24bppRgb)
{
output[0] = 0;
output[1] = 0;
output[2] = 8;
output[3] = 8;
output[4] = 8;
}
else if(pf == PixelFormat.Format32bppArgb)
{
output[0] = 0;
output[1] = 8;
output[2] = 8;
output[3] = 8;
output[4] = 8;
}
else if(pf == PixelFormat.Format32bppPArgb)
{
output[0] = 0;
output[1] = 8;
output[2] = 8;
output[3] = 8;
output[4] = 8;
}
else if(pf == PixelFormat.Format32bppRgb)
{
output[0] = 8;
output[1] = 0;
output[2] = 8;
output[3] = 8;
output[4] = 8;
}
else if(pf == PixelFormat.Format48bppRgb)
{
output[0] = 16;
output[1] = 0;
output[2] = 16;
output[3] = 16;
output[4] = 16;
}
else if(pf == PixelFormat.Format64bppArgb)
{
output[0] = 0;
output[1] = 16;
output[2] = 16;
output[3] = 16;
output[4] = 16;
}
else if(pf == PixelFormat.Format64bppPArgb)
{
output[0] = 0;
output[1] = 16;
output[2] = 16;
output[3] = 16;
output[4] = 16;
}
return output;
}
}
Dave
|
|
|
|
|
By the way, this solution was only tested for PixelFormat.Format24bppRgb and PixelFormat.Format48bppRgb. Use with extreme caution!
Dave
|
|
|
|
|
I'm trying to make a ticker that gets its information from an rss news feed.
I can't figure out how to make the link portion be in sync with the title portion. What i mean is this.
Lets say i have titles
siteone
sitetwo
sitethree
I want it to scroll which i have it doing right now, but I want to be able to click on say sitetwo and it take me to toysrus.com or whatever and if i click on sitethree it take me to broadband.com or whatever the link in the rss file indicates. Here is what i have so far but obviously its not working. I can't figure out how to seperate if you will the links to correspond to the correct title. Never using the rss reader before so don't beat me up to bad if its an easy obvious fix.
void ticker()
{
String URLString = "http://www.local-news.net/go/-84.5374/33.8591/rss/";
XmlTextReader reader = new XmlTextReader (URLString);
string tickerstring = reader.ReadString();
while(true)
{
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.LocalName.Equals("title"))
{
tickerstring +=reader.ReadString()+" ";
}
if (reader.LocalName.Equals("link"))
link=reader.ReadString();
}
}
int removeme =-1;
for (int i=0; i<=tickerstring.Length; i++)
{
label2.Text=i.ToString();
if (i>100)
{
label1.Text = tickerstring.Substring(++removeme,label1.Text.Length);
}
else
try
{
label1.Text = tickerstring.Substring(0,i);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
Thread.Sleep(100);
}
Thread.Sleep(1000);
}
}
Win32newb
"Programming is like sex, make one mistake and you have to support it for a long time"
|
|
|
|
|
Update:
I have it reading it in and matching the links but I'm hung up on something that i thought would be obvious but its not. For some reason the link is one title behind. I see in the code that it reads the title then the link which is what it should do but as soon as it starts spitting out the title It should be linkable but the link hasn't changed. I have tried moving this segment of code all around and can't figure it out. Help would be appreciated.
if (reader.LocalName.Equals("link"))
link=reader.ReadString();
label2.Text=link.ToString();
void ticker()
{
String URLString = "http://rss.news.yahoo.com/rss/topstories";
string tickerstring="";
while(true)
{
XmlTextReader reader = new XmlTextReader (URLString);
int removeme =-1;
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.LocalName.Equals("link"))
link=reader.ReadString();
label2.Text=link.ToString();
Thread.Sleep(300);
if (reader.LocalName.Equals("title"))
{
tickerstring =reader.ReadString()+" ";
for (int i=0; i<=tickerstring.Length; i++)
{
if (i>100)
{
label1.Text = tickerstring.Substring(++removeme,label1.Text.Length);
}
else
{
try
{
label1.Text = tickerstring.Substring(0,i);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
Thread.Sleep(100);
}
}
}
}
}
}
Win32newb
"Programming is like sex, make one mistake and you have to support it for a long time"
|
|
|
|
|
hi all,
i can't access directly to the treeView.text property. my problem is how to clear the treeView content. i tryed also the resetText method but it doesn't resolve the problem.
|
|
|
|
|
Treeviews don't have text. Instead, they have nodes. Use the nodes to acess the text you want.
To clear a treeview, use this:
<br />
TreeView1.Nodes.Clear()<br />
Aaron Eldreth
TheCollective4.com
My Articles
While much is too strange to be believed,
Nothing is too strange to have happened.
- T. Hardy
|
|
|
|
|
Have a Double and want to convert it to a Date format, any suggestions how to do it?
And yes, having a date as a double is pretty stupid , but converting from double to string or long is not problem anyhow. But in the GUI I'm using one of those fancy almanacs that requires the Date format.
|
|
|
|
|
If your Double is number of ticks which should be long type , see the constructor of DateTime structure.
Mazy
"One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji
|
|
|
|
|
Where did this Double come from? Another system? If so, then you might have to do some tweaking because not all systems/languages use the same epoch as a starting point, or use the same units of measure. Some count the milliseconds from a specific date and time, others count the number of ticks from a date/time...
With that in mind, you can use
DateTime myDateTime(ticks
where ticks is the number of 100-nanosecond intervals since 12:00am on Jan 1, 0001. Yes you read that right, the year 1.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Search "zedgraph" in codeproject search.
there are a class to solve it!
|
|
|
|
|
I am new to .Net and C#. I have written a few programs but am having trouble figuring out how to create an exe file.
Where are the settings for creating a distributable executable when I do a build?
Thanks
Gary
|
|
|
|
|
If your using visual studio, make an application project, same with #develop...if you not using either of those, you can use csc.exe from the framework (the compiler).
To those who didn't make it, we will remember you. To those who did is back. - Megan Forbes in Black FridayAnother Post by NnamdiOnyeyiri
|
|
|
|
|
Hi,
how to create Icon from binary reource when using namespaces ? Thanks
|
|
|
|
|
I have some questions about moving a PictureBox on another PictureBox:
1.
My Project needs to show a picture so I use a PictureBox,
and sometimes I need to insert some small pictures on it,
How can I dynamic new some pictureBoxs on the original PictureBox...??
2.
After adding a PictureBox on it,
I need to move the PictureBox to the position I want with my mouse,
How can I draw a ---(dot line) Rectangle in my MouseMove event to avoid flickering problem...??
Please give me a hand,thanks!!
|
|
|
|
|
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
Dim pic1 As System.Windows.Forms.PictureBox
pic1.Width = 50
pic1.Height = 50
pic1.Image = CType(Resources.GetObject("PictureBox1.Image"), System.Drawing.Bitmap)
PictureBox1.Controls.Add(pic1)
Aaron Eldreth
TheCollective4.com
My Articles
While much is too strange to be believed,
Nothing is too strange to have happened.
- T. Hardy
|
|
|
|
|
First your gonna run into the problem of the picture box not being transparent. Cause the control is not a transparent control. You have to derive a class from the picturebox and then override the onpaint function to draw your image otherwise its gonna cover up whats behind it looking all crappy.
The flickering problem if you will look at my article on anti flicker you will see how to enable double buffering. Double buffering is turned off by default.
Hope this helps. If you need more information just ask I will try to help.
Win32newb
"Programming is like sex, make one mistake and you have to support it for a long time"
|
|
|
|
|
First thanks for you answers,
I design my project with no transparent picture now,
maybe I have to show it with transparent finally...I hope not... >_<
I type my code below:
<br />
private Point startMoveLocation = Point.Empty;<br />
private Point moveAmount = Point.Empty;<br />
.<br />
.<br />
.<br />
private void pictureBox1_MouseEnter(object sender, System.EventArgs e)<br />
{<br />
pictureBox1.Cursor = System.Windows.Forms.Cursors.Hand;<br />
}<br />
<br />
private void pictureBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)<br />
{<br />
pictureBox1.Capture = true;<br />
startMoveLocation = new Point(e.X, e.Y); <br />
}<br />
<br />
private void pictureBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)<br />
{<br />
if (pictureBox1.Capture == true)<br />
moveAmount = new Point(e.X-startMoveLocation.X,e.Y-startMoveLocation.Y); <br />
}<br />
<br />
private void pictureBox1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)<br />
{<br />
pictureBox1.Location = new Point(pictureBox1.Location.X + moveAmount.X,pictureBox1.Location.Y + moveAmount.Y);<br />
pictureBox1.Capture = false;<br />
}<br />
Now I can move the picture as I wish,
but during mouse move,I don't know how to draw a dot line rectangle
to let user know the process,
Can you help me solve this question...??
Thank you very much !!
|
|
|
|
|
Hi All,
Can anybody help me?....
I am using a datareader to read from the database, i have the select query for this & reading the contents of the table ok...
I am getting the correct output using a datareader for the datagrid ....as....
DGShow.DataSource=dread;
DGShow.DataBind();
...but i want to put the same contains in the textbox also....but whenever i read the contains i am getting this error message....
Exception Details: System.InvalidOperationException: Invalid attempt to read when no data is present.
the code is......
while(dread.Read())
{
txtEmpID.Text=dread.GetString(0);
txtEmpName.Text =dread.GetString(1);
txtcity.Text=dread.GetString(2);
txtphone.Text=dread.GetInt32(3);
}
as i am not sure that i m on right track please help me..
thanks
|
|
|
|
|