0

I use an asp file uploader to upload a bitmap image. The original image is saved in hard disk in 24 bit format but the uploader converted it to 32 bit and subsequently gives wrong result in my web application

How can I upload image as its original 24 bit?

Dim face As search_eng.face 
face = New face() ' initialize object (face)
If (Not System.IO.Directory.Exists(getpath() + "\pics\")) Then 
    System.IO.Directory.CreateDirectory(getpath() + "\pics\") 
End If

Dim i = 0
While System.IO.File.Exists(getpath() + "\pics\" + i.ToString + ".jpg") 
    i += 1
End While

FileUpload1.SaveAs(getpath() + "\pics\" + i.ToString + ".jpg")
Image1.ImageUrl = "\pics\" + i.ToString + ".jpg"
Dim fs As System.IO.FileStream   ' define a file stream
fs = New IO.FileStream(getpath() + "\pics\" + i.ToString + ".jpg",  IO.FileMode.Open, IO.FileAccess.Read)  ' open for read

Dim img As System.Drawing.Image
img = System.Drawing.Image.FromStream(fs)
fs.Dispose()

Dim btimg As System.Drawing.Bitmap   
Dim Original_img As System.Drawing.Bitmap
btimg = New Drawing.Bitmap(img, img.Width, img.Height)
Original_img = New Drawing.Bitmap(img, img.Width, img.Height)

img = btimg
Original_img = btimg
Original_img.Save("d:\after_open_Web.bmp")
phuclv
  • 37,963
  • 15
  • 156
  • 475
wathiq
  • 1
  • 1
  • What format are we talking about here and what kind of file uploader are you using? What platforms are involved? – Pekka Jun 07 '15 at 21:54
  • By default, the uploader open image as 32 bit/ pixel . But I want to open an image as 24 bit format. I tried to convert it to 24 bit and see the result, but the subsequent operations on image will give error result. I do not want to convert image I want to open it as 24 bit – wathiq Jun 08 '15 at 11:35
  • Yes, but what image format is this, in what kind of file uploader? Can you show some code, what does the form look like that you're using to upload the file? – Pekka Jun 08 '15 at 14:23
  • thank for your comments. the asp page shows normal image as it appear in picture box in widows form but it use 32 bit while the original image in hard disk is 24 bit. I read some sites in which I knew that the extra byte is for alpha channel. How can I remove or ignore alpha ? or try to do any thing in order to give an image exactly as original one. – wathiq Jun 08 '15 at 15:04
  • Can you show some code? How (at which point) do you know it uses 32 bit? – Pekka Jun 08 '15 at 15:12
  • I attached my code above. the image variable ( Original_img) uses 32 bit. When it upload and open it is 32 bit. But when open it in windows application it use 24 bit which is proper format as original. – wathiq Jun 08 '15 at 16:32
  • I don't know ASP, but the solution lies probably where you create the new bitmap. This looks good: https://msdn.microsoft.com/en-us/library/zy1a2d14%28v=vs.110%29.aspx and https://msdn.microsoft.com/en-us/library/system.drawing.imaging.pixelformat(v=vs.110).aspx – Pekka Jun 08 '15 at 16:40

0 Answers0