05.30.06
Posted in Programming at by chenty
I recently received the following error randomly:
########## System.IO.FileNotFoundException ##########
Could not load file or assembly ‘App_Web_*******, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null’ or one of its dependencies. The system cannot find the file specified.
It seems that .NET 2.0 has some problems to handle temporary files. After googling a lot regarding this issue during the past few months, I found a temp solution:
The solution is to modify the offending file a bit. For example, add a space and then delete the space, then save the file. Refresh the page at the end.
Here is a post on ASP.NET forum addressing this problem:
http://forums.asp.net/1290177/ShowThread.aspx
There is a hotfix from Microsoft as one of the persons on forum mentioned, but nobody knows whether the hotfix can resolve the problem. I will continue to research on this issue, and post my update later.
Permalink
05.26.06
Posted in Programming at by chenty
I posted a sample code for automatically shrink size for uploaded picture last week. However, after I implemented in my program, the result wasn’t good. It looked fine when shrinked picture had small dimension, but it looked aweful when the picture is a bit big. I searched over the Internet, and many people has raised problem with GetThumbnailImage. There are two explanation why the results are bad:
1. some digital camera stored thumbnail in the picture. Therefore, when calling GetThumbnailImage, GDI+ will simply pulled out that one. Therefore for bigger size, it’s not really downsize, but upsize from pre-stored thumbnail.
2. GetThumbnailImage uses low quality Interpolation Mode.
Most solution is to use Graphics object instead of use GetThunmbnailImage method. Here is a sample program:
http://www.devhood.com/tools/tool_details.aspx?tool_id=498
However, I found a very interesting solution from here:
http://www.dotnet247.com/247reference/msgs/25/128742.aspx
In this article, there is one person rotate the picture 360 degree before call GetThumbnailImage method. I tested this method and it works very well. Threrefore, I wrote an update version of my last code. In this code, another change is I get rid of the callback:
void resize2()
{
//declare var for size
int limitX = 600;
int limitY = 400;
int x = 0;
int y = 0;
int newX = 0;
int newY = 0;
try
{
//load image
System.Drawing.Image objImage = System.Drawing.Image.FromFile(Server.MapPath("foo.jpg"));
//determine what are the new dimensions
x = objImage.Width;
y = objImage.Height;
if (x > limitX || y > limitY)
{
if (x*1.0/y >= limitX*1.0/limitY)
{
//shrink according to x
newX = limitX;
newY = Convert.ToInt32(y*(limitX * 1.0/x));
}
else
{
newY = limitY;
newX = Convert.ToInt32(x*(limitY * 1.0/y));
}
}
else
{
newX = x;
newY = y;
}
//resize the image
objImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
objImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
objImage = objImage.GetThumbnailImage(newX, newY, objCallback, IntPtr.Zero);
//save image
objImage.Save(Server.MapPath("minifoo.jpg"));
}
catch (Exception error)
{
//do whatever
}
}
-
void resize2()
-
{
-
//declare var for size
-
int limitX = 600;
-
int limitY = 400;
-
int x = 0;
-
int y = 0;
-
int newX = 0;
-
int newY = 0;
-
-
try
-
{
-
//load image
-
System.Drawing.Image objImage = System.Drawing.Image.FromFile(Server.MapPath("foo.jpg"));
-
-
//determine what are the new dimensions
-
x = objImage.Width;
-
y = objImage.Height;
-
if (x > limitX || y > limitY)
-
{
-
if (x*1.0/y >= limitX*1.0/limitY)
-
{
-
//shrink according to x
-
newX = limitX;
-
newY = Convert.ToInt32(y*(limitX * 1.0/x));
-
}
-
else
-
{
-
newY = limitY;
-
newX = Convert.ToInt32(x*(limitY * 1.0/y));
-
}
-
}
-
else
-
{
-
newX = x;
-
newY = y;
-
}
-
-
//resize the image
-
objImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
-
objImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
-
objImage = objImage.GetThumbnailImage(newX, newY, objCallback, IntPtr.Zero);
-
-
//save image
-
objImage.Save(Server.MapPath("minifoo.jpg"));
-
}
-
catch (Exception error)
-
{
-
//do whatever
-
}
-
}
Permalink
05.21.06
Posted in Miscellaneous at by chenty
Today is 1st anniversary of my blog.
Here is the summary:
Total Post: 52 (including this)
Achievement: none
Fun: unlimited
I found my blog is quite useful to help me remeber techniques I posted here. Even though this blog does not have many visitors (several hundreds per month roughly), I still receive emails for questions. In the coming year, I will post more technical stuff and I will start posting business related blog since I enroll in Commerce program in University of Toronto this fall (too bad I couldn’t get in graduate school for Computer Engineering).
Permalink
Posted in Programming at by chenty
Websites usually limit uploaded picture size in order to save server resources. For example, a website may limit uploaded picture size to be 600*400, and less than 20kB. Of course, website users can resize their pictures in Photoshop or these free image processing software. However, not everyone can do that easily. Therefore, it will be much easier if the program can automatically shrink the picture size if the picture too big.
In this tutorial, I will only use JPEG format as an example. The sample code here will:
1. load the original image “foo.jpg”
2. resize to meet the requirement 600*400pixel (3:2)
3. save the shrinked image in a new file “minifoo.jpg”
Here is the code:
void resize()
{
//declare var for size
int limitX = 600;
int limitY = 400;
int x = 0;
int y = 0;
int newX = 0;
int newY = 0;
try
{
//load image
System.Drawing.Image objImage = System.Drawing.Image.FromFile(Server.MapPath("foo.jpg"));
//determine what are the new dimensions
x = objImage.Width;
y = objImage.Height;
if (x > limitX || y > limitY)
{
if (x*1.0/y >= limitX*1.0/limitY)
{
//shrink according to x
newX = limitX;
newY = Convert.ToInt32(y*(limitX * 1.0/x));
}
else
{
newY = limitY;
newX = Convert.ToInt32(x*(limitY * 1.0/y));
}
}
else
{
newX = x;
newY = y;
}
//resize the image
System.Drawing.Image.GetThumbnailImageAbort objCallback = new System.Drawing.Image.GetThumbnailImageAbort(fooCallback);
objImage = objImage.GetThumbnailImage(newX, newY, objCallback, IntPtr.Zero);
//save image
objImage.Save(Server.MapPath("minifoo.jpg"));
}
catch (Exception error)
{
//do whatever
}
}
bool fooCallback()
{
return false;
}
-
void resize()
-
{
-
//declare var for size
-
int limitX = 600;
-
int limitY = 400;
-
int x = 0;
-
int y = 0;
-
int newX = 0;
-
int newY = 0;
-
-
try
-
{
-
//load image
-
System.Drawing.Image objImage = System.Drawing.Image.FromFile(Server.MapPath("foo.jpg"));
-
-
//determine what are the new dimensions
-
x = objImage.Width;
-
y = objImage.Height;
-
if (x > limitX || y > limitY)
-
{
-
if (x*1.0/y >= limitX*1.0/limitY)
-
{
-
//shrink according to x
-
newX = limitX;
-
newY = Convert.ToInt32(y*(limitX * 1.0/x));
-
}
-
else
-
{
-
newY = limitY;
-
newX = Convert.ToInt32(x*(limitY * 1.0/y));
-
}
-
}
-
else
-
{
-
newX = x;
-
newY = y;
-
}
-
-
//resize the image
-
System.
Drawing.
Image.
GetThumbnailImageAbort objCallback =
new System.
Drawing.
Image.
GetThumbnailImageAbort(fooCallback
);
-
objImage = objImage.GetThumbnailImage(newX, newY, objCallback, IntPtr.Zero);
-
-
//save image
-
objImage.Save(Server.MapPath("minifoo.jpg"));
-
}
-
catch (Exception error)
-
{
-
//do whatever
-
}
-
}
-
-
bool fooCallback()
-
{
-
return false;
-
}
And don’t ask me why there is a delegate and what the IntPtr.Zero is. Just use my code and enjoy
Permalink
05.20.06
Posted in Programming at by chenty
I bought a new server for my company last week, and when I checked log today, I got the following error in Event Viewer -> Application:
Error: The Template Persistent Cache initialization failed for Application Pool ‘DefaultAppPool’ because of the following error: Could not create a Disk Cache Sub-directory for the Application Pool. The data may have additional error codes..
After searching on google, I found this article from MSDN:
http://support.microsoft.com/?kbid=332097
It seems that when you setup IIS on a Windows 2003 domain controller, ASP page will receive the above error. After giving permissions on all folders to IIS_WPG (The first part of the KB solution), the problem is fixed.
I hope this helps.
Permalink
05.15.06
Posted in Life at by chenty
When I review my previous post, I just realize today is my birthday.
I am officially 25 now!
Permalink
Posted in Programming at by chenty
I haven’t written anything recently because I am waiting for the result for graduate school. Even though, I don’t think I can get it, but I can’t plan my future until I know the result.
Anyway, the past several weeks, I didn’t do much work except continuing working on my .NET project. I got very bad luck with Microsoft!
1. I got a new PDA (Palm OS), and I decide to use this to replace my bulky notebook (not notebook computer, but real notebook). However, then I realize, even I PAID Microsoft for email service, it does not support export contacts…
My choice is simple: manually enter 100+ contacts
or
Paid almost $100 to get Outlook Live. After trying to manually do that a bit, I gave up… Bravo Microsoft!
2. I made so many forms in my .NET project. .NET makes programming very easy. However, today, when I am testing some of these forms, I found “Maxlength” is not working! Then I read that “maxlength” does NOT work with “multiline” mode, due to HTML limitation. Now I have to roll back one week work and manually check lengths……
Now I understand why so many people so upset with Microsoft.
Permalink