Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Complex Image Handling  (Read 2183 times)

0 Members and 1 Guest are viewing this topic.

Psychohyena

  • Newbie
  • *
  • Posts: 6
    • View Profile
Complex Image Handling
« on: May 04, 2011, 02:21:19 pm »
Hi Guys,

So cutting to the chase and avoiding beating around the bush here is what I want to do:

I have created a .dat file (binary) which contains the Uint8 information for a jpg. What I want to do is using iostream load that file into my application and then load it into an sf::Image.

So far I can restore the information into the application as Data (void*) where I get stuck is the converting this information back into Uint8. Does anyone have any ideas as to how I might do this?

Cheers,

Aaron

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Complex Image Handling
« Reply #1 on: May 04, 2011, 02:37:49 pm »
What does "Uint8" refer to? Pixel components, or bytes of a JPG file? In other words, what kind of information is there in the data that you load from your file?
Laurent Gomila - SFML developer

Psychohyena

  • Newbie
  • *
  • Posts: 6
    • View Profile
Complex Image Handling
« Reply #2 on: May 04, 2011, 03:11:45 pm »
Quote from: "Laurent"
What does "Uint8" refer to? Pixel components, or bytes of a JPG file? In other words, what kind of information is there in the data that you load from your file?


I'm using the GetPixelPtr function to fill the dat file through the ofstream and then using the ifstream to pull it back. It appears to be working up until I'm pulling the data back through the ifstream and then it crashes.

The code looks something like this:
Code: [Select]

sf::Uint8* myImageArray;
sf::Image test;
void myFunction()
{
  test.LoadFromFile("Image1.jpg");
 
  ofstream arrayData("C:\\array.dat", ios::out);
  ifstream inData("C:\\array.dat", ios::in);

  arrayData << test.GetPixelsPtr() << endl;
  arrayData.close();

  inData >> myImageArray;
  test.LoadFromPixels(600, 600, myImageArray);
};

It's changed slightly as I've been experimenting while waiting, so now what happens is the application crashes on the inData >> myImageArray. Rather than getting an error at compile about being unable to convert to sf::Uint8.

I feel what I have is possibly close to what I need.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Complex Image Handling
« Reply #3 on: May 04, 2011, 03:35:06 pm »
With this code, what you write/read is the value of a pointer. If you want to write the actual values that are pointed by this pointer, you have to write them one by one in the output stream.
And you also need to write the width and height to know how many elements are stored in the file.
Laurent Gomila - SFML developer

Psychohyena

  • Newbie
  • *
  • Posts: 6
    • View Profile
Complex Image Handling
« Reply #4 on: May 04, 2011, 10:36:44 pm »
Quote from: "Laurent"
With this code, what you write/read is the value of a pointer. If you want to write the actual values that are pointed by this pointer, you have to write them one by one in the output stream.
And you also need to write the width and height to know how many elements are stored in the file.


Ahhh righto then. I'll get onto that, thanks for your help mate.

 

anything