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

  • Home
  • SEARCH
  • 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 8056511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:43:36+00:00 2026-06-05T08:43:36+00:00

this may be impossible, or rather, not very popular, but I was wondering how

  • 0

this may be impossible, or rather, not very popular, but I was wondering how I’d go about creating a data file for images, that would actually compress them? Say I had 200MB total of image files, is there some system I can use to store them in a single file, that would compress them to a total size of like 150MB? (Just example numbers, ratios not important).

I know I can encode the images with Base64 and then store them in an SQLite database, but I read that storing images in their encoded forms actually resulted in a slightly larger size than the original image file itself.

I was also thinking of a ZIP file, but I wasn’t sure if it could be used as a ‘library’ as such?

If something like this doesn’t exist as a predefined class, could someone lead me on the right track?

This is a mock of what I’m sort of looking for:

class ImageLibrary {
  //this is where the code would go for the library?
}

class MyProgram{
  public MyProgram() 
  {
    ImageLibrary library = new ImageLibrary();
    library.Add(<Image object here, with an ID of sorts>);
    library.Add(<Another image object here, also with an ID>);
    Load += new FormLoadEventHandler(MyProgram_Load);
  }

  void MyProgram_Load(object sender, EventArgs e)
  {
    PictureBox.Image = library.Get(<image id here>);
  }
}

I hope this is possible. Else, I’ll just put up with a slightly larger file size and Base64 encode them. But, because I have, at the moment, almost 500 images I want to store, a kB saved is a kB earned. 🙂 Also, please don’t judge the quality of my code example, it’s just a mock up and I wrote it off the cuff.

Cheers, and thankyou in advance.

  • 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-06-05T08:43:38+00:00Added an answer on June 5, 2026 at 8:43 am

    If save your images as binary files will help this is a code I use to convert them to binary and then save into SQLite:

    public byte[] ImageToByte(Image image, System.Drawing.Imaging.ImageFormat format){
            using (MemoryStream ms = new MemoryStream())
            {
                // Convert Image to byte[]
                image.Save(ms, format);
                byte[] imageBytes = ms.ToArray();
                return imageBytes;
            }
        }
        public Image ByteToImage(byte[] imageBytes)
        {
            // Convert byte[] to Image
            MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);
            ms.Write(imageBytes, 0, imageBytes.Length);
            Image image = new Bitmap(ms); 
            return image;
        }
    

    And then to save the binary:

    void SaveImage(byte[] image){
            string conStringDatosUsuarios = @" Data Source = \Program Files\GPS___CAM\Data\DatosUsuarios.s3db ";            
            SQLiteConnection con = new SQLiteConnection(conStringDatosUsuarios); 
            SQLiteCommand cmd = con.CreateCommand();
            cmd.CommandText = String.Format("INSERT INTO Users (Foto) VALUES (@0);");
            SQLiteParameter p = new SQLiteParameter("@0", System.Data.DbType.Binary);
            p.Value = image;
            cmd.Parameters.Add(p);            
            con.Open(); 
            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (Exception exc1)
            {
                MessageBox.Show(exc1.Message);
            }
            con.Close();
        }
    

    Hope it helps

    EDIT As you asked, I’m updating with the load image code:
    (to convert the byte to image you must use the ByteToImage function)

    void LoadImage(string tag){
            string query = "SELECT Foto FROM Users;";
            string conString = @" conection to your database ";
            SQLiteConnection con = new SQLiteConnection(conString); 
            SQLiteCommand cmd = new SQLiteCommand(query, con);            
            con.Open();
            try
            {
                SQLiteDataReader rdr = cmd.ExecuteReader();
                try
                {
                    while (rdr.Read())
                    {
                        pictureBox1.Image = ByteToImage((System.Byte[])rdr[0]);
                    }
                }
                catch (Exception exc) { MessageBox.Show(exc.Message); }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
            con.Close();
        }
    

    EDIT 2 Try this to see which type of data are you trying to load:

    System.Type checkType = rdr[0].GetType();
    pictureBox1.Image = ByteToImage((System.Byte[])rdr[0]);
    

    add the first line in your code and put a breakpoint in that line. Check checkType’s type. Probably it isn’t binary. Let me know the result to help you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I realise that this question may be almost impossible to answer definitively, but: Is
This may be impossible, but I was wondering if it was possible to keep
This is a rather complicated question that may simply be impossible with what's currently
This may be rather noobish but I'm gonna ask anyhow. I have a class
This may seem as an almost impossible question, but I wish to know how
I think what I am trying to do here may be impossible, but this
This may sound impossible but read on. I need to learn jQuery a little
I know this may be impossible but... I just got an app approved, and
This may be stupadly easy, or just impossible - but it's worth asking in
This may be impossible, but I'm going to ask anyway. Without going into the

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.