Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7129085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:12:21+00:00 2026-05-28T11:12:21+00:00

I see in my code I’m not passing the re-scaled image into the InputStream,

  • 0

I see in my code I’m not passing the re-scaled image into the InputStream, I’m passing in the original file-base. Is it possible to pass in newImage in some way as its of a different type?

I’m using MVC2 .NET 3.5

Here’s the controller for uploading:

[HttpPost]
public ActionResult ImageUpload(HttpPostedFileBase fileBase, PhotoViewModel photoViewModel)
{
    if (photoViewModel.Button == "Upload")
    {
        photoViewModel.ImageValid = "Valid";
        ImageService imageService = new ImageService();

        if (fileBase != null && fileBase.ContentLength > 0 && fileBase.ContentLength <= 2097152 && fileBase.ContentType.Contains("image/"))
        {
            Path.GetExtension(fileBase.ContentType);
            var extension = Path.GetExtension(fileBase.FileName);

            if (extension.ToLower() != ".jpg" && extension.ToLower() != ".gif") // only allow these types
            {
                photoViewModel.ImageValid = "Not Valid";
                ModelState.AddModelError("Photo", "Wrong Image Type");
                return View(photoViewModel);
            }
            EncoderParameters encodingParameters = new EncoderParameters(1);
            encodingParameters.Param[0] = new EncoderParameter(Encoder.Quality, 100L); // Set the JPG Quality percentage

            ImageCodecInfo jpgEncoder = imageService.GetEncoderInfo("image/jpeg");
            var uploadedimage = Image.FromStream(fileBase.InputStream, true, true);

            Bitmap originalImage = new Bitmap(uploadedimage);
            Bitmap newImage = new Bitmap(originalImage, 274, 354);

            Graphics g = Graphics.FromImage(newImage);
            g.InterpolationMode = InterpolationMode.HighQualityBilinear;
            g.DrawImage(originalImage, 0, 0, newImage.Width, newImage.Height);

            var streamLarge = new MemoryStream();
            newImage.Save(streamLarge, jpgEncoder, encodingParameters);

            var fileExtension = Path.GetExtension(extension);
            string newname;
            if (photoViewModel.photoURL != null)
            {
                newname = photoViewModel.photoURL;
            }
            else
            {
                newname = Guid.NewGuid() + fileExtension;
            }

            //changed this up now, so it stores the image in db as apposed to physical path
            photoViewModel.photo = newname;
            photoViewModel.ContentType = fileBase.ContentType;
            Int32 length = fileBase.ContentLength;
            byte[] tempImage = new byte[length];
            fileBase.InputStream.Read(tempImage, 0, length);
            photoViewModel.ImageData = tempImage;          

            TempImageUpload tempImageUpload = new TempImageUpload();
            tempImageUpload.TempImageData = tempImage;
            tempImageUpload.ContentType = photoViewModel.ContentType;

            photoViewModel.TempImageId = _service.InsertImageDataBlob(tempImageUpload);

            originalImage.Dispose();
            streamLarge.Dispose();
            return View(photoViewModel);
        }

        if (fileBase != null)
        {
            if (fileBase.ContentLength > 0) ModelState.AddModelError("Photo", "Image size too small");
            if (fileBase.ContentLength <= 2097152) ModelState.AddModelError("Photo", "Image size too big");
            if (fileBase.ContentType.Contains("image/")) ModelState.AddModelError("Photo", "Wrong Image Type");
        }
        else ModelState.AddModelError("Photo", "Please upload a image");

        if (!ModelState.IsValid)
        {
            photoViewModel.ImageValid = "Not Valid";
            return View(photoViewModel);
        }
    }
    return View(photoViewModel);
}

Here’s my repository class:

public int InsertImageDataBlob(TempImageUpload tempImageUpload)
{
  int ReturnedPhotoId;

  try
  {
    var phototempdata = new Photo
             {
                  ImageData = tempImageUpload.TempImageData,
                  contentType = tempImageUpload.ContentType,
                  dateUploaded = DateTime.Now
             };
    _db.Photos.InsertOnSubmit(phototempdata);
    Save();
    ReturnedPhotoId = phototempdata.id;
    return ReturnedPhotoId;
  }
  catch (Exception ex)
  {
    //ErrorLogging;
  }
  return 0;
}

And image data field (image type) in the database gets populated with data.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T11:12:21+00:00Added an answer on May 28, 2026 at 11:12 am

    I actually got it to work with this code:

          photoViewModel.photo = newname;
          photoViewModel.ContentType = fileBase.ContentType;
          streamLarge.Position = 0;
          byte[] tempImage = new byte[streamLarge.Length + 1];
          streamLarge.Read(tempImage, 0, tempImage.Length);
          photoViewModel.ImageData = tempImage;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a executable jar file and i want to see code behind it.
Please see code below: <?php require_once(initvars.php); require_once(config.php); if( !$auth->id ){ //NOT logged in header(location:
See code just bellow Our generic interface public interface Repository<INSTANCE_CLASS, INSTANCE_ID_CLASS> { void add(INSTANCE_CLASS
See code below: I want Page 1 to alert #testing... This works in C
Sometimes I see code like let (alt : recognizer -> recognizer -> recognizer) =
I often see code like int hashCode(){ return a^b; } Why XOR?
In my other question You can see code of my arr structure and PriorityQueue
In a lot of TDD tutorials I see code like this: public class MyClass
I'm looking at shadow mapping in OpenGL. I see code like: // This is
See this code: var jsonString = '{id:714341252076979033,type:FUZZY}'; var jsonParsed = JSON.parse(jsonString); console.log(jsonString, jsonParsed); When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.