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 1079493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:52:42+00:00 2026-05-16T21:52:42+00:00

I want to be able to save an image as text in a xml

  • 0

I want to be able to save an image as text in a xml file and I can’t manage to find a efficient way to do it !

So far I tried :

QByteArray ImageAsByteArray;
QBuffer ImageBuffer(&ImageAsByteArray);
ImageBuffer.open(QIODevice::WriteOnly);
rImage.save(&ImageBuffer, "PNG"); 

return QString(ImageAsByteArray.toBase64());

Despite the fact it’s working, the result is a file that is huge ! I tried adding some QCompress in there but without much success… Actually the QCompress doesn’t seem to compress anything…

I think I’m doing it the wrong way, but could someone enlight my path please ?

  • 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-16T21:52:43+00:00Added an answer on May 16, 2026 at 9:52 pm

    Are you loading the image file to QImage and then getting the bytes from that QImage? If yes, then you are base64 encoding the raw image. In that case it really doesn’t matter at all how much the original image file is compressed.

    You should read the original image file (png or jpg) as a binary stream and base64 encode that stream. Example:

    QFile* file = new QFile("Image001.jpg");
    file->open(QIODevice::ReadOnly);
    QByteArray image = file->readAll();
    int originalSize = image.length();
    
    QString encoded = QString(image.toBase64());
    int encodedSize = encoded.size();
    

    My test image’s originalSize is 1028558 bytes, and encodedSize is 1371412 bytes, which is 33% more than the originalSize (see Jérôme’s comment to your question).

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

Sidebar

Related Questions

I want to be able to save a bitmap image with text from a
I want to save my program's DataModel objects to a file, and be able
I want to be able to save any C# object in a single column
I want to be able to generate a different image (with watermark) when the
I need to be able to draw a text on a png file at
I've poured over similar questions but can't find the answer. I want to be
I want to be able to save a link such as example.com/get.php?id=4 I want
I want to be able to save a CGContext into my NSUndoManager using these
I'm trying to save an image using a JFileChooser. I only want the user
Given an image (format is part of the question) I want to be able

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.