|
I have the following code that creates a thumbnail for a given image and saves the new image to disk. It works but the images cannot be displayed by MSIE, and it appears that they are a different format than jpeg. Here's the code:
private void MakeThumbImage(string sSrcFilename, string sDestFilename)
{
Image orgImg = Image.FromFile(sSrcFilename);
int iHeight = orgImg.Height;
int iWidth = orgImg.Width;
int iNewHeight = iHeight;
int iNewWidth = iWidth;
if (orgImg.Width >= 96)
{
iNewWidth = 96;
}
else
{
iNewWidth = orgImg.Width;
}
double ratio = (double)iWidth / iNewWidth;
iNewHeight = (iHeight / (int)ratio);
Image.GetThumbnailImageAbort myCallback = new Image.GetThumbnailImageAbort(ThumbnailCallback);
Image thumb = orgImg.GetThumbnailImage(iNewWidth, iNewHeight, myCallback, IntPtr.Zero);
if (thumb != null)
{
thumb.Save(sDestFilename);
}
orgImg.Dispose();
thumb.Dispose();
}
private bool ThumbnailCallback()
{
return false;
}
I need to create a thumb for whatever file type it is (e.g., gif, png, jpg).
Thanks,
Mark
|
|
|
|
|
It may be a bmp. You should read up on the Save method, and how to specify a file format with it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanks. That fixed it fine!
Mark
-- modified at 12:45 Saturday 10th March, 2007
|
|
|
|
|
I have been trying to identify a solution to this problem for some time. I have a control on the form. I change the location of that control on a path from an ending point back to the starting point.
I accomplish this by mappint the path incrementally along 64 points along a line. I put all of those points into an array and then loop through the array with a for-each loop. This part works fine, but now, here is the problem.
When the control is displayed on the form at its new location, I would like for that location image to be cleared before displaying the control at its next location. The way it displays now is that there is a path of displayed locations for the control from its ending point back to its starting point, kind of like ghost images.
private static void ProvideDragPathReturnToParent(Control ctrl, int intX_end, int intY_end,
int intX_start, int intY_start)
{
Point pt0 = new Point(intX_start, intY_start);
Point pt64 = new Point(intX_end, intY_end);
Point pt32 = new Point(((pt0.X + pt64.X)/2), ((pt0.Y + pt64.Y)/2));
Point pt16 = new Point(((pt0.X + pt32.X)/2), ((pt0.Y + pt32.Y)/2));
Point pt48 = new Point(((pt32.X + pt64.X)/2), ((pt32.Y + pt64.Y)/2));
Point pt8 = new Point(((pt0.X + pt16.X)/2), ((pt0.Y + pt16.Y)/2));
Point pt24 = new Point(((pt16.X + pt32.X)/2), ((pt16.Y + pt32.Y)/2));
Point pt40 = new Point(((pt32.X + pt48.X)/2), ((pt32.Y + pt48.Y)/2));
Point pt56 = new Point(((pt48.X + pt64.X)/2), ((pt48.Y + pt64.Y)/2));
Point pt4 = new Point(((pt0.X + pt8.X)/2), ((pt0.Y + pt8.Y)/2));
Point pt12 = new Point(((pt8.X + pt16.X)/2), ((pt8.Y + pt16.Y)/2));
Point pt20 = new Point(((pt16.X + pt24.X)/2), ((pt16.Y + pt24.Y)/2));
Point pt28 = new Point(((pt24.X + pt32.X)/2), ((pt24.Y + pt32.Y)/2));
Point pt36 = new Point(((pt32.X + pt40.X)/2), ((pt32.Y + pt40.Y)/2));
Point pt44 = new Point(((pt40.X + pt48.X)/2), ((pt40.Y + pt48.Y)/2));
Point pt52 = new Point(((pt48.X + pt56.X)/2), ((pt48.Y + pt56.Y)/2));
Point pt60 = new Point(((pt56.X + pt64.X)/2), ((pt56.Y + pt64.Y)/2));
Point pt2 = new Point(((pt0.X + pt4.X)/2), ((pt0.Y + pt4.Y)/2));
Point pt6 = new Point(((pt4.X + pt8.X)/2), ((pt4.Y + pt8.Y)/2));
Point pt10 = new Point(((pt8.X + pt12.X)/2), ((pt8.Y + pt12.Y)/2));
Point pt14 = new Point(((pt12.X + pt16.X)/2), ((pt12.Y + pt16.Y)/2));
Point pt18 = new Point(((pt16.X + pt20.X)/2), ((pt16.Y + pt20.Y)/2));
Point pt22 = new Point(((pt20.X + pt24.X)/2), ((pt20.Y + pt24.Y)/2));
Point pt26 = new Point(((pt24.X + pt28.X)/2), ((pt24.Y + pt28.Y)/2));
Point pt30 = new Point(((pt28.X + pt32.X)/2), ((pt28.Y + pt32.Y)/2));
Point pt34 = new Point(((pt32.X + pt36.X)/2), ((pt32.Y + pt36.Y)/2));
Point pt38 = new Point(((pt36.X + pt40.X)/2), ((pt36.Y + pt40.Y)/2));
Point pt42 = new Point(((pt40.X + pt44.X)/2), ((pt40.Y + pt44.Y)/2));
Point pt46 = new Point(((pt44.X + pt48.X)/2), ((pt44.Y + pt48.Y)/2));
Point pt50 = new Point(((pt48.X + pt52.X)/2), ((pt48.Y + pt52.Y)/2));
Point pt54 = new Point(((pt52.X + pt56.X)/2), ((pt52.Y + pt56.Y)/2));
Point pt58 = new Point(((pt56.X + pt60.X)/2), ((pt56.Y + pt60.Y)/2));
Point pt62 = new Point(((pt60.X + pt64.X)/2), ((pt60.Y + pt64.Y)/2));
Point pt1 = new Point(((pt0.X + pt2.X)/2), ((pt0.Y + pt2.Y)/2));
Point pt3 = new Point(((pt2.X + pt4.X)/2), ((pt2.Y + pt4.Y)/2));
Point pt5 = new Point(((pt4.X + pt6.X)/2), ((pt4.Y + pt6.Y)/2));
Point pt7 = new Point(((pt6.X + pt8.X)/2), ((pt6.Y + pt8.Y)/2));
Point pt9 = new Point(((pt8.X + pt10.X)/2), ((pt8.Y + pt10.Y)/2));
Point pt11 = new Point(((pt10.X + pt12.X)/2), ((pt10.Y + pt12.Y)/2));
Point pt13 = new Point(((pt12.X + pt14.X)/2), ((pt12.Y + pt14.Y)/2));
Point pt15 = new Point(((pt14.X + pt16.X)/2), ((pt14.Y + pt16.Y)/2));
Point pt17 = new Point(((pt16.X + pt18.X)/2), ((pt16.Y + pt18.Y)/2));
Point pt19 = new Point(((pt18.X + pt20.X)/2), ((pt18.Y + pt20.Y)/2));
Point pt21 = new Point(((pt20.X + pt22.X)/2), ((pt20.Y + pt22.Y)/2));
Point pt23 = new Point(((pt22.X + pt24.X)/2), ((pt22.Y + pt24.Y)/2));
Point pt25 = new Point(((pt24.X + pt26.X)/2), ((pt24.Y + pt26.Y)/2));
Point pt27 = new Point(((pt26.X + pt28.X)/2), ((pt26.Y + pt28.Y)/2));
Point pt29 = new Point(((pt28.X + pt30.X)/2), ((pt28.Y + pt30.Y)/2));
Point pt31 = new Point(((pt30.X + pt32.X)/2), ((pt30.Y + pt32.Y)/2));
Point pt33 = new Point(((pt32.X + pt34.X)/2), ((pt32.Y + pt34.Y)/2));
Point pt35 = new Point(((pt34.X + pt36.X)/2), ((pt34.Y + pt36.Y)/2));
Point pt37 = new Point(((pt36.X + pt38.X)/2), ((pt36.Y + pt38.Y)/2));
Point pt39 = new Point(((pt38.X + pt40.X)/2), ((pt38.Y + pt40.Y)/2));
Point pt41 = new Point(((pt40.X + pt42.X)/2), ((pt40.Y + pt42.Y)/2));
Point pt43 = new Point(((pt42.X + pt44.X)/2), ((pt42.Y + pt44.Y)/2));
Point pt45 = new Point(((pt44.X + pt46.X)/2), ((pt44.Y + pt46.Y)/2));
Point pt47 = new Point(((pt46.X + pt48.X)/2), ((pt46.Y + pt48.Y)/2));
Point pt49 = new Point(((pt48.X + pt50.X)/2), ((pt48.Y + pt50.Y)/2));
Point pt51 = new Point(((pt50.X + pt52.X)/2), ((pt50.Y + pt52.Y)/2));
Point pt53 = new Point(((pt52.X + pt54.X)/2), ((pt52.Y + pt54.Y)/2));
Point pt55 = new Point(((pt54.X + pt56.X)/2), ((pt54.Y + pt56.Y)/2));
Point pt57 = new Point(((pt56.X + pt58.X)/2), ((pt56.Y + pt58.Y)/2));
Point pt59 = new Point(((pt58.X + pt60.X)/2), ((pt58.Y + pt60.Y)/2));
Point pt61 = new Point(((pt60.X + pt62.X)/2), ((pt60.Y + pt62.Y)/2));
Point pt63 = new Point(((pt62.X + pt64.X)/2), ((pt62.Y + pt64.Y)/2));
Point[] arrPoint = {pt64, pt63, pt62, pt61, pt60, pt59, pt58, pt57, pt56,
pt55, pt54, pt53, pt52, pt51, pt50, pt49, pt48, pt47,
pt46, pt45, pt44, pt43, pt42, pt41, pt40, pt39, pt38,
pt37, pt36, pt35, pt34, pt33, pt32, pt31, pt30, pt29,
pt28, pt27, pt26, pt25, pt24, pt23, pt22, pt21, pt20,
pt19, pt18, pt17, pt16, pt15, pt14, pt13, pt12, pt11,
pt10, pt9, pt8, pt7, pt6, pt5, pt4, pt3, pt2, pt1, pt0};
foreach (Point pt in arrPoint)
{
ctrl.Location = pt;
ctrl.Update();
}
}
-- modified at 8:55 Saturday 10th March, 2007
|
|
|
|
|
You are only redrawing the control itself. As you are not giving control to the system until the loop ends, the form never gets a chance to redraw itself.
I would suggest that you use a timer control to move the control, that way the form gets a chance to erase the old control.
By the way: you use a lot of code to create the array, when it can easily be done in a loop.
---
single minded; short sighted; long gone;
|
|
|
|
|
How could it be done in a loop, and how would a timer be used to get the form to redraw itself? I have tried to apply code like this but it does not work properly.
private static void ProvideDragPathReturnToParent(Control ctrl, int intX_end, int intY_end,
int intX_start, int intY_start)
{
int x = 0, y = 0;
if ((intX_end > intX_start) & (intY_end > intY_start))
{
for (x = intX_end; x >= intX_start; x--)
{
for (y = intY_end; y >= intY_start; y--)
{
ctrl.Location = new System.Drawing.Point(x, y);
ctrl.Update();
}
}
}
else if ((intX_end < intX_start) & (intY_end < intY_start))
{
for (x = intX_end; x <= intX_start; x++)
{
for (y = intY_end; y <= intY_start; y++)
{
}
}
}
else if ((intX_end > intX_start) & (intY_end < intY_start))
{
for (x = intX_end; x <= intX_start; x++)
{
for (y = intY_end; y <= intY_start; y++)
{
}
}
}
else if ((intX_end < intX_start) & (intY_end > intY_start))
{
for (x = intX_end; x <= intX_start; x++)
{
for (y = intY_end; y <= intY_start; y++)
{
}
}
}
}
The problem here is that I do not know when the control will fit each of the conditions for position on the form. The x and y coordinates for the start and end points are based, I presume, upon PointToClient coordinates which goes from (0, 0) to (max, max) screen cordinates. However, I do not know the results of where it will be dropped.
Also, the x-coordinates must be completed before moving on to the y-coordinates. I would need to have one x-coordinate completed before moving on to the y-Coordinate, and then go back again to the next x-coordinate. I would request some input as to how to proceed.
-- modified at 13:12 Saturday 10th March, 2007
|
|
|
|
|
We start with this:
new_phoenix wrote: and how would a timer be used to get the form to redraw itself?
If you use a timer to trigger the movement of the control, the main message pump would handle messages in between the timer events. If you just change the location of the control, both the control and the previous area of the control will be invalidated. This creates messages that will be handled by the message pump. The message pump will call the Paint event of the control and the form, which will repaint the control and the part of the form that was invalidated.
new_phoenix wrote: How could it be done in a loop
The x position of a point on the line can be interpolated like this:
x = startX + (endX - startX) * index / 64
where index is the index of the point from 0 to 64.
The y position can be calculated in the same way.
You don't even have to create an array of points, you can just calculate the position directly in the timer event.
---
single minded; short sighted; long gone;
|
|
|
|
|
Forgive my ignorance, Guffa, but I have never heard of using a timer control to trigger the movement of a control. I would need an example because all that I am aware of that a Timer control could do would be to provide time ticks().
Also, because I am implementing this code in a function that is part of a sealed static class, I do not have access to the this keyword, or any timer controls. How would I proceed with these suggested and appreciated improvments?
New_Phoenix
|
|
|
|
|
Drag a timer control to the form, set it's Interval property as you like, and create a Tick event for it.
Create a member variables in the form to hold the current index of the movement and the starting and ending points:
private int _index, startX, startY, endX, endY;
In the method for the Tick event you put the code that changes the Location of the control. Example:
private void Timer1_Tick(object sender, EventArgs e) {
int x = startX + (endX - startX) * 64 / _index;
int y = startY + (endY - startY) * 64 / _index;
MyLittleControl.Location = new Point(x, y);
_index++;
if (_index > 64) {
Timer1.Enabled = false;
}
}
To start the movement, set the variables for starting and ending point, set _index to zero, and set Timer1.Enabled to true.
---
single minded; short sighted; long gone;
|
|
|
|
|
Guffa:
I tried to implement your suggestions but appeared to have hit a snag. First, the mathematics for the formula do not appear to work properly. For example, if the startX point for the first plotted point is zero and the endX point is 700, then the value for x would be 44800 since 0 + (700 - 0) * 64 / 1 = 44800. Then when second point is plotted it would be 22400, and the third point would be 14933.33.
The second issue is that what if the contol is dropped at a point in which the end value for x and/or y is less than the start values? This presents the possibility in which a control could be dropped above and to the right, or below and to the right, or above and to the left, or below and to the left, or directly above, or directly below, or directly left, or directly right, or an any place on the form.
For this reason, I believe that it would be necessary to apply the point plotting strategy as mentioned in the original message, by plotting 64 points. However, I am intrigued with your statement of utilizing the Timer control as a method to get control back from the process before showing the control at its next location.
Is there a way to get the timer clock to trade control back and forth between showing the control and ticking another period of time. In this way, the desired effect would be achieved. The control would show at its next plotted point, but the previous display of the control would be removed from the screen. This would effectively remove the trail of controls before returning control back to the process of showing its path from the drop point back to the dragged from point (ie starting point). Could you kindly show me how to shift control back and forth between the timer control and the plotting/displaying loop of updated control locations?
|
|
|
|
|
new_phoenix wrote: First, the mathematics for the formula do not appear to work properly.
Yes, you are right. It should be (endX - startX) * _index / 64 instead of (endX - startX) * 64 / _index .
new_phoenix wrote: The second issue is that what if the contol is dropped at a point in which the end value for x and/or y is less than the start values?
That is not a problem. In that case endX - startX becomes a negative value, so the control moves in the other direction from the start point.
new_phoenix wrote: Is there a way to get the timer clock to trade control back and forth between showing the control and ticking another period of time.
That is the entire purpose of the Elapsed event. The timer triggers the event for every tick, making control go to the event handler code. Once the event handler code has done it's work, control is returned to normal operation.
---
single minded; short sighted; long gone;
|
|
|
|
|
Hi.I'm new in c#. Can anyone tell me hoe to convert this coding to a class?
#region dragDrop panel3
private bool isDragging3=false;
public int x3,y3;
private void panel3_MouseDown(System.Object sender,
System.Windows.Forms.MouseEventArgs e)
{
isDragging3 = true;
x3 = e.X;
y3 = e.Y;
}
private void panel3_MouseUp(System.Object sender,
System.Windows.Forms.MouseEventArgs e)
{
isDragging3 = false;
}
private void panel3_MouseMove(System.Object sender,
System.Windows.Forms.MouseEventArgs e)
{
if (isDragging3 == true)
{
panel3.Left = e.X + panel3.Left - x3;
panel3.Top = e.Y + panel3.Top - y3;
}
}
#endregion
|
|
|
|
|
To make a class of that code, you just put the code in a class, but what is it that you wish to accomplish by doing so?
---
single minded; short sighted; long gone;
|
|
|
|
|
One way to do this would be to derive a class from Panel and overload the OnMouseDown, OnMouseUp and OnMouseMove methods.
class myPanel : Panel
{
...
protect override void OnMouseDown(MouseEventArgs e)
{
isDragging3 = true;
x3 = e.X;
y3 = e.Y;
}
...
}
Mike
Started out with nothing and still have most of it left!
|
|
|
|
|
thank for the solution. It's very helpful
|
|
|
|
|
There are error to compile this code because panel3.left is not defined in the class. How to overcome this?
if (isDragging3 == true)
{
panel3.Left = e.X + panel3.Left - x3;
panel3.Top = e.Y + panel3.Top - y3;
}
|
|
|
|
|
Most likely panel3 IS the class (i.e. this )
|
|
|
|
|
Sorry I cut and paste in a hurry as Mr. MacKay has suggested the proper syntax is;
if (isDragging3 == true)
{
this.Left = e.X + this.Left - x3;
this.Top = e.Y + this.Top - y3;
}
Hope this helps.
Mike
Started out with nothing and still have most of it left!
|
|
|
|
|
Thanks. This really works...
|
|
|
|
|
hi!
i am currently working on securing a webservice by using WSE. I have managed to use UsernameTokens to authenticate the caller of the webmethods...but i cannot find a proper example that uses X509 tokens instead of UsernamTokens. I need an example that uses X509 certificates to digitally sign a SOAP header and also to encrypt the body of the SOAP message, and of course the code used in the webmethod to identify the caller's ID based on the certificate. Also i didn't quite get how to create and install a test certificate sa that i can use it in my test application.
So if anyone could help with a sample project or some guidelines, i would appreciate it. Thanks!
|
|
|
|
|
Hi everybody . I have some problems in converting a time string value into DateTime object .
I have used the following code to do this :
{
IFormatProvider Culture = new CultureInfo("en-US", false)
DateTime.Parse(txt_updateTime.Text,Culture,DateTimeStyles.NoCurrentDefaultDate) ;
}
but It doesn't work properly and throw an exception with this message :"Input string is not in correct format " while the txt_updateTime.Text value is , for example, 05:44
with the best regards
|
|
|
|
|
I think the "en-US" culture expects a time to have those AM/PM stuff. If you know the time is entered in a fix format, you can use the DateTime.ParseExact (or preferrably TryParseExact in Framework > 1.1) method that lets you specify the expected format of the string to parse.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
hi
i use crystal report in my app,but i want work with it professionally,for example i want to pass my dataTable to crystal report by code and bind my crystal report fields to my dataTable columns by code(dinamically),but how to do ??
thanks
|
|
|
|
|
Yor question is good,
but I did it by dataset
but I am sorry I couldn't do it programittacly ?
please I f you got it by code?
sent it to me !
my email is
hatem_ibr@yahoo.com
|
|
|
|
|
i need to control a button.enabled property on my Form using a thread but visual studio gives me an exception telling me "Cross-thread operation not valid: Control 'button1' accessed from a thread other than the thread it was created on." and ask me to set CheckForIllegalCrossThreadCalls to false
how can i set it to false??
or if there is another solution for this without setting CheckForIllegalCrossThreadCalls to false
pleas help
thanks allot
|
|
|
|
|