Thursday, April 27, 2006

Sample site using the image library

I got my baby's site up... It uses the image library I posted :)
So, even it looks quite simple, there is a high tech engine behind it. lol

http://www.adamelek.com

The site is in Turkish, but all you need to know is "Resimler" means "Images"...

I got samples of grayscale images, applying borders, creating thumbnails, and creating a thumbnail from an album (inspired from Picasa)...

So, all my wife has to do is upload the new month's images every month using PICASA (because it creates an XML index, which I merge to get my library file)

Wednesday, April 26, 2006

.net 2.0 Image Transformation Library

I have been using the most addvanced technology of all times, copy & paste, for my bitmap transformations.

Recently I have wrapped my functions in a Helper class, and posted it on XMLPitStop...

you can download it here


Hope it helps :)

Keep up with MSDN events

The more I atend to those events, the more I want to attend the next one...

Learned a lot again.

There is a GREAT value in those events, if you think that you need to know what you are talking about, do not miss them.

Monday, November 21, 2005

How to bind one datagrid column multiple fields in asp.net 1.1

Here is how :)

Works for one or even more fields...

Monday, July 25, 2005

How to resize images dynamically

How many times did you need to resize an image in an image editor to standardize the image sizes on your web site?

How many times dod you need to create thumbnails of the images?

How about adding a border ?

If it is part of your daily work, smile :)

Here is how you do it in ASP.NET : Copy the code below into the Load event handler in an aspx page, and set the src of your image to this aspx page with the relevant parameters...

Don't forget to reference System.Drawing.Drawing2D and system.Drawing.Imaging in your code.



Copy below the line
--------------
public void Page_Load(object sender, System.EventArgs e){
string myImg = Request["i"];
if(myImg == null myImg == "") { myImg = "defaultimage.jpg"; }
string myBorder = Request["b"];
if(myBorder == null myBorder == "") { myBorder = "border.gif"; }
Bitmap original = new Bitmap(Server.MapPath(@"~/images/" + myImg),true );
int mySize = original.Size.Width ;
Bitmap border=new Bitmap(Server.MapPath(@"~/images/" + myBorder), true);
Bitmap outputbitmap = new Bitmap(mySize, mySize);
// using statement makes sure that the graphics object is properly disposed
using(Graphics g = Graphics.FromImage(outputbitmap))
{
//Make it high Quality;
g.CompositingQuality = CompositingQuality.HighQuality;
g.SmoothingMode= SmoothingMode.HighQuality;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.PixelOffsetMode = PixelOffsetMode.HighQuality;
g.DrawImage(original, new Rectangle(0,0,mySize, mySize ));
border.MakeTransparent(Color.Black );
g.DrawImage(border, new Rectangle(0,0,mySize, mySize));

}
//' get the requested size,the example is a square
if(Request.QueryString["s"]!= null && Request.QueryString["s"]!= "" )
{ mySize = int.Parse(Request.QueryString["s"]); }
System.Drawing.Image outputimage =
outputbitmap.GetThumbnailImage( mySize, mySize, null, new IntPtr());
Response.Clear();
// set the mime type
Response.ContentType="image/Jpeg";
//' send the image to the viewer
outputimage.Save(Response.OutputStream, ImageFormat.Jpeg);
}
--------

How to create dynamic enumerations...

Don't ask WHY :)

Sometimes you really want something like this...
And sometimes people can say "you can't" on the discussion boards...
(http://www.dotnet247.com/247reference/__site/85/2004/7/7)

Keep trying until you find the "System.Reflection.Emit.EnumBuilder" class.

(http://msdn2.microsoft.com/library/zkb4f47s(en-us,vs.80).aspx)

Do not get scared, it is supported from ground to top, starting with .net framework 1.0 .

Cool isn't it ?

Friday, July 22, 2005

How to serialize an object to a datacolumn in a dataset

The image column is represented as byte[] in a dataset, so all you have to do is, assign and read the value of the column.

I looked for an example around, but could not find exactly same thing.

So I had to write it my own.

If you have a similar challenge, here is the code to "leverage":

public static byte[] SerializeObject(object obj)
{
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter f = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
using (System.IO.MemoryStream ms = new System.IO.MemoryStream() )
{
f.Serialize(ms, obj);
return ms.GetBuffer();
}
}
public static object DeSerializeObject(byte[] buffer)
{
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter f = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
using (System.IO.MemoryStream ms = new System.IO.MemoryStream(buffer) )
{
return f.Deserialize(ms);
}
}

Monday, February 14, 2005

How to Convert a Dataset in to a delimited text file ?

Why ?
Because the contents of a single table, 1800 row dataset weights 2.5MB in XML format, while it weights 500KB in delimited text file...

Again why ?
Because you need to send it over an XML Web Service...

Again why ?
Bacause the SOAP proxy created with Visual Studio .NET 2003 does not support HTTP 1.1 compression...

I will try to figure this out in a clean way...
So far the best resource is brendan tompkins blog .

But seems to be a problem with handling multiple tables.

So long.

Friday, October 29, 2004

How to get a nullable DateTime Field or DataColumn?

Janusys has a Calendar Control that allows null values.

But unfortunately I am using Typed Datasets and having a hell of a time to work with null DateTime Values...

You can set the DateTime Field's MinOccurs Property to "", which allows you to store null values.. but then what ???
Like how do you clear it after you assign a date to it ?

Let's say you have two tables in the TypedDataset dsCustomer, Customers and Orders.
The Built in method :
dsCustomer.Customers.AddCustomersRow( .. , .. , .. , .. )
is a great way to make sure you have everything in place,
but what about the hell with the DateTime Fields ??? LastOrderDate ...

By the way, one other issue for ppl that heve not faced it yet, DateTime.MinValue DOES NOT get stored on a SQL Server. It is smaller then the allowed minimum date in SQL. So, if you try to do so, you get an exception right from the SQL server... :)

So, lets say you tweaked it by giving a DateTime.MinDate during the initialization... Then how am I gonna make it null ?

I will tell you when i find about it ...

Duray AKAR