Click here to Skip to main content
15,908,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I Have One filed that is signature in these ,I am used File upload control... i am upload the image ..user give some signature image..based on that ....what is size and what is pixel format of picture ...I am want to set that signature image to "180X35" pixel size ...but here image width and height is .....get property ..but i am used Bitmap ...but It show Only" Light Gray" not show any image...........the following code is below....can replay me...you how to set pixel size of image in .aspx.cs file

byte[] fileData;
if (ImgImages.UploadedFiles.Count > 0)
{
UploadedFile file = ImgImages.UploadedFiles[0];

RadBinaryImage RadBi = new RadBinaryImage();
System.Drawing.Image myImage = System.Drawing.Image.FromStream(file.InputStream);
Bitmap b = new Bitmap(myImage);
System.Drawing.Imaging.BitmapData bi=new System.Drawing.Imaging.BitmapData();
Bitmap biImageConvert = new Bitmap(180, 35,bi.Stride , myImage.PixelFormat,bi.Scan0);

byte [] f1=imageToByteArray(biImageConvert);
oCheck.Signature = f1;

}

public byte[] imageToByteArray(System.Drawing.Bitmap imageIn)
{
MemoryStream ms = new MemoryStream();
imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
return ms.ToArray();
}

where wrong with bitmap in above code...why i am getting gray color image not original one...type image after converstion.
Posted

System.Drawing.Image myImage = System.Drawing.Image.FromStream(file.InputStream);
Bitmap b = new Bitmap(myImage);

This is a waste of time. Last time I looked at the framework code, your image is already a bitmap and can be cast. Either way, why not just create the Bitmap to start with ? And, you don't need to do all this, you can create a bitmap with a constructor that takes a bitmap, and the new size you want the image to be.
 
Share this answer
 
if (ImgImages.UploadedFiles.Count > 0)
{
UploadedFile file = ImgImages.UploadedFiles[0];
fileData = new byte[file.InputStream.Length];
System.Drawing.Image myImage = System.Drawing.Image.FromStream(file.InputStream);
// Compute thumbnail size.
Size thumbnailSize = GetThumbnailSize(myImage);
// Get thumbnail.
System.Drawing.Image thumbnail = myImage.GetThumbnailImage(thumbnailSize.Width, thumbnailSize.Height, null, IntPtr.Zero);
fileData = imageToByteArray(thumbnail);
oCheck.Signature = fileData;
}

static Size GetThumbnailSize(System.Drawing.Image original)
{
// Maximum size of any dimension.
const int MaxWidth = 180;
const int Maxheight = 35;
// Width and height.
int originalWidth = original.Width;
int originalHeight = original.Height;

// Compute best factor to scale entire image based on larger dimension.
double factor;
double factor1;
if (originalWidth > originalHeight)
{
factor = (double) MaxWidth / originalWidth;
factor1 = (double)Maxheight / originalHeight;
}
else
{
factor = (double)MaxWidth / originalWidth;
factor1 = (double)Maxheight / originalHeight;
}

// Return thumbnail size.
//return new Size((int)(originalWidth * factor), (int)(originalHeight * factor));
return new Size((int)(originalWidth*factor),(int) (originalHeight*factor1));
}

public byte[] imageToByteArray(System.Drawing.Image imageIn)
{
MemoryStream ms = new MemoryStream();
imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);/* here we are seen format type like that you can save any format ".png or .Jpeg or .bmp" */
return ms.ToArray();
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900