Better thumbnail creation then "GetThumbnailImage" in C sharp
2/21/2010 03:03:00 PM
Posted by RIAlog
In many cases you may want to create a smaller version of your images. maybe for mobile devices or for images view on your page.
One known way is to use the "ready-made" GetThumbnailImage function. That will generally do the job (another way is below):
int Width; int Height; int ThumbWidth; int ThumbHeight; string SavePath = "[Some save path"]; string FilenameWOext = "[]"; string FileExtention; Bitmap btmp1 = new Bitmap(SavePath + FilenameWOext + FileExtention); Width = btmp1.Width; Height = btmp1.Height; System.Drawing.Image.GetThumbnailImageAbort myCallBack = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback); if (ThumbWidth > Width && ThumbHeight > Height) { ThumbWidth = Width; ThumbHeight = Height; } System.Drawing.Image myThumbnail1 = btmp1.GetThumbnailImage(ThumbWidth, ThumbHeight, myCallBack, IntPtr.Zero); myThumbnail1.Save(SavePath + ThumbFile); btmp1.Dispose();
HOWEVER, this will sometimes wont work. when using images from some digital cameras, there is addotional EXIF data that makes the generated image to be blur.
Fortunatly, there is another way using Graphics.DrawImage
Bitmap resized = new Bitmap(ThumbWidth, ThumbHeight); Graphics g = Graphics.FromImage(resized); g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic; g.DrawImage(btmp1, new Rectangle(0, 0, resized.Width, resized.Height)); g.Dispose();
This way will work with EXIF images or any other image with high quality too!
Enjoy!
Adobe P2P VideoPhone with asp.net registration
2/14/2010 11:44:00 PM
Posted by RIAlog
The Adobe p2p and Stratus are not that new. its sample application is cool and shows more than just textual p2p connection like other tutorials, but actually shows a good enough voice and image transfer.
BUT, as a .Net programmer, the registration Python code was a bit wierd to work with. Moreover, the application is literally poor in user management, so I needed a good start point to have that registration use real DB.
So, you want to use ASP.NET with Adobe Stratus VideoPhone ? here you go: ( I used Linq to SQL for this one. DB name is simply "P2P")
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; namespace P2PRegistration { ////// Summary description for $codebehindclassname$ /// [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class reg : IHttpHandler { public void ProcessRequest(HttpContext context) { RegistrationDBDataContext db = new RegistrationDBDataContext(); string user = context.Request.QueryString["username"]; string identity = context.Request.QueryString["identity"]; string friendsString = context.Request.QueryString["friends"]; List friends = new List(); if (friendsString != null && friendsString != "") { friends = friendsString.Split(',').ToList(); } context.Response.ContentType = "text/plain"; context.Response.Write(@""); context.Response.Write(@""); if (user != null && user != "" && identity != null && identity != "") { context.Response.Write(@" "); } public bool IsReusable { get { return false; } } } }"); try { var rUser = from p in db.registrations where (p.m_username == user) select p; if (rUser.Count() > 0) { //update rUser.First().m_username = user; rUser.First().m_identity = identity; rUser.First().m_updatetime = DateTime.Now; } else { registration newReg = new registration(); newReg.m_username = user; newReg.m_identity = identity; newReg.m_updatetime = DateTime.Now; db.registrations.InsertOnSubmit(newReg); } db.SubmitChanges(); context.Response.Write("true"); } catch { context.Response.Write("false"); } context.Response.Write(@" "); } foreach (string f in friends) { context.Response.Write(@""); context.Response.Write(@" "); } context.Response.Write(@""); context.Response.Write(context.Server.UrlEncode(f)); context.Response.Write(@" "); var rFriends = from p in db.registrations where p.m_username == f && p.m_updatetime > DateTime.Now.AddHours(-1) select p; foreach (registration r in rFriends) { string ident = r.m_identity; if (ident == null) ident = ""; context.Response.Write(@""+context.Server.UrlEncode(ident)+@" "); if (f != r.m_username) { context.Response.Write(@""+r.m_username+" "); } } context.Response.Write(@"
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[registrations]') AND type in (N'U')) BEGIN CREATE TABLE [dbo].[registrations]( [m_username] [varchar](100) NOT NULL, [m_identity] [varchar](100) NULL, [m_updatetime] [datetime] NULL, CONSTRAINT [PK__registrations__7C8480AE] PRIMARY KEY CLUSTERED ( [m_username] ASC )WITH (PAD_INDEX = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] END
... // please insert your webservice URL here for exchanging private const WebServiceUrl:String = "http://[your domain here]/reg.ashx"; ...
allowFullScreen is not working in IE but do work in FF
2/09/2010 12:45:00 PM
Posted by RIAlog