}//end of genPassword() //resizes a image public static SD.Image resizeImage(SD.Image imgBigImage, int ingMaxWidth, int ingMaxHeight) { int intNewWidth = 0;//holds the new width of the new image int intNewHeight = 0;//holds the new height of the new image int intCurrentWidth = imgBigImage.Width;//holds the current width of the image int intCurrentHeight = imgBigImage.Height;//holds the current height of the image //checks if the width is larger then the heigth if so then //floors the width and set the height to be apporenit to the width if ((intCurrentWidth / (double)ingMaxWidth) > (intCurrentHeight / (double)ingMaxHeight)) { //adjuest the height to be apporent now and floors the width intNewWidth = ingMaxWidth; intNewHeight = Convert.ToInt32(intCurrentHeight * (ingMaxWidth / (double)intCurrentWidth)); //checks if the new height is not bigger then the max if (intNewHeight > ingMaxHeight) { //adjuest the width to be apporent now and floors the height intNewWidth = Convert.ToInt32(ingMaxWidth * (ingMaxHeight / (double)intNewHeight)); intNewHeight = ingMaxHeight; }//end of if }//end of if //else floors the height and set the width to be apporenit to the height else { //adjuest the width to be apporent now and floors the height intNewWidth = Convert.ToInt32(intCurrentWidth * (ingMaxHeight / (double)intCurrentHeight)); intNewHeight = ingMaxHeight; //checks if the new width is not bigger then the max if (intNewWidth > ingMaxWidth) { //adjuest the height to be apporent now and floors the width intNewWidth = ingMaxWidth; intNewHeight = Convert.ToInt32(ingMaxHeight * (ingMaxWidth / (double)intNewWidth)); }//end of if }//end of else SD.Bitmap bitNewImage = new SD.Bitmap(intNewWidth, intNewHeight);//holds the new bitmap of the image //web resolution; bitNewImage.SetResolution(72, 72); SD.Graphics grImage = SD.Graphics.FromImage(bitNewImage);//holds the graphics object grImage.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Low; //creates a new holder of where the new image will be drawen to grImage.FillRectangle(new SD.SolidBrush(SD.Color.White), 0, 0, bitNewImage.Width, bitNewImage.Height); //Re-draw the image to the specified height and width grImage.DrawImage(imgBigImage, 0, 0, bitNewImage.Width, bitNewImage.Height); return bitNewImage; }//end of resizeImage()
}//end of useUser #endregion #region Private Funcation //crop an image base on what the user has selected using jCrop private byte[] cropImage(string strImageName, int intImageWidth, int intImageHeight, int intImageX, int intImageY) { try { using (SD.Image OriginalImage = SD.Image.FromFile(strImageName)) { int intNewImageHeight = intImageHeight;//holds the height of the new image that will be create out of the crop old image int intNewImageWidth = intImageWidth;//holds the width of the new image that will be create out of the crop old image int intNewImageYStart = 0;//holds the Y coordinate to center the image at the start int intNewImageXStart = 0;//holds the X coordinate to center the image at the start //checks if the intNewImageWidth is not intDefaultWidth if(intNewImageWidth != intDefaultWidth) { //does the calucations for the center the image for the X coordinate intNewImageXStart = ((intDefaultWidth - intNewImageWidth) / 2); //default intNewImageWidth to the max width allowed in order to created bars on the side intNewImageWidth = intDefaultWidth; }//end of if //checks if the intNewImageHeight is not intDefaultHeight if(intNewImageHeight != intDefaultHeight) { //does the calucations for the center the image for the Y coordinate intNewImageYStart = ((intDefaultHeight - intNewImageHeight) / 2); //default intNewImageHeight to the max height allowed in order to created bars intNewImageHeight = intDefaultHeight; }//end of if using (SD.Bitmap bmp = new SD.Bitmap(intNewImageWidth, intNewImageHeight)) { bmp.SetResolution(OriginalImage.HorizontalResolution, OriginalImage.VerticalResolution); using (SD.Graphics Graphic = SD.Graphics.FromImage(bmp)) { Graphic.SmoothingMode = SmoothingMode.AntiAlias; Graphic.InterpolationMode = InterpolationMode.HighQualityBicubic; Graphic.PixelOffsetMode = PixelOffsetMode.HighQuality; Graphic.DrawImage(OriginalImage, new SD.Rectangle(intNewImageXStart, intNewImageYStart, intImageWidth, intImageHeight), intImageX, intImageY, intImageWidth, intImageHeight, SD.GraphicsUnit.Pixel); MemoryStream ms = new MemoryStream(); bmp.Save(ms, OriginalImage.RawFormat); return ms.GetBuffer(); }//end of using }//end of using }//end of using }//end of try catch (Exception ex) { throw (ex); }//end of catch }//end of cropImage()
public void renderDisplayFrame(byte[] data) { // convert 8 bit data to 24 bit RGB var rgbuffer = new byte[256 * 256 * 3]; var z = 0; foreach (var c in data) { if (c > 215) { z = z + 3; } else { int blue = c % 6; int green = ((c - blue) / 6) % 6; int red = ((c - blue - (6 * green)) / 36) % 6; rgbuffer[z++] = (byte)(blue * 0x33); rgbuffer[z++] = (byte)(green * 0x33); rgbuffer[z++] = (byte)(red * 0x33); } } // Gerate bitmap. var b = new SD.Bitmap(256, 256, SDI.PixelFormat.Format24bppRgb); var rect = new SD.Rectangle(0, 0, 256, 256); var bitmapdata = b.LockBits(rect, SDI.ImageLockMode.WriteOnly, b.PixelFormat); System.Runtime.InteropServices.Marshal.Copy(rgbuffer, 0, bitmapdata.Scan0, 256 * 256 * 3); b.UnlockBits(bitmapdata); // convert to png (which xna can use) using (var ms = new MemoryStream()) { b.Save(ms, SDI.ImageFormat.Png); // create texture object which can then be rendered in the next Draw() call texture = Texture2D.FromStream(gd, new MemoryStream(ms.GetBuffer())); } }