Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cannot save Zbar barcode image

 
ibrahim yener
Ranch Hand
Posts: 202
Android Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to use barcode scanner into my application and i am using Zbar library
however, i can scan barcode but i want to save scanned image into sd card.

So far, i can able to capture image and save into SD but when i try to open it i have broken image error and cannot display it.

What am i using is :


I really appreciate for any help because i am trying to solve this problem almost 48 hours non-stop.

Regards
 
Paul Clapham
Sheriff
Posts: 21572
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sorry, but I don't see how that code captures an image. I see that you're outputting the value of the 'globalData' variable, but that value was set before the image was even created.
 
ibrahim yener
Ranch Hand
Posts: 202
Android Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Paul
Thanks for reply, the original code is not capturing image it reads barcode and stop preview of screen.

So, i want to get that frozen frame.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are just writing raw bytes to a file and assuming they are in PNG format. Where do you get the bytes from? Are they in PNG format?
 
ibrahim yener
Ranch Hand
Posts: 202
Android Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Steve

What we learn so far for saving picture is something like this:



and there is no raw file or something as you mention.
As you can see, data2file method have two parameters which is byte array and file name.

I found that i am mistaking to save picture.
Could you give me some hint or help to handle this problem, i am trying to solve it almost 3 days non-stop and i have serious headache
to thinking too much about it.

I also searched many resources but not found correct/permanent solution.

Regards
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't ever do this:

catch(Exception e)
{
}

At least print the error message to where you will see it. Otherwise, how will you know that there are problems?
 
ibrahim yener
Ranch Hand
Posts: 202
Android Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Ulf
i already tried to get error. But there is no error output in catch.
 
Paul Clapham
Sheriff
Posts: 21572
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ibrahim yener wrote:So far, i can able to capture image and save into SD


This statement in your original post implies that you have some idea of what you are doing. And all the posts so far have accepted that is the case. But clearly it isn't. You don't have any idea about how to get a formatted version of the image, do you? And that's really your question, the code is just a diversion. So let's start from there instead.

I have to say that I don't have any idea either. But I do know that the raw data that you fed into the Image object isn't what you want (and that's what your code does so far). I would either look at the Image object and see if the documentation tells you how to extract a formatted image from it, or perhaps have a look at whatever type the "scanner" variable is and see if you can use that.
 
ibrahim yener
Ranch Hand
Posts: 202
Android Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:

This statement in your original post implies that you have some idea of what you are doing. And all the posts so far have accepted that is the case. But clearly it isn't. You don't have any idea about how to get a formatted version of the image, do you? And that's really your question, the code is just a diversion. So let's start from there instead.

I have to say that I don't have any idea either. But I do know that the raw data that you fed into the Image object isn't what you want (and that's what your code does so far). I would either look at the Image object and see if the documentation tells you how to extract a formatted image from it, or perhaps have a look at whatever type the "scanner" variable is and see if you can use that.


Perhaps you are right.
I have been developing php for 9 years and just 5 months ago i started to learn java and android
as you may guess i am not familiar oop (my knowledge was very limited)

so, i have no idea how to extract image from Image Object.
Also i see no difference between my code in my first post and code in my later post. You may see difference but i don't.

scanner variable/object is part of Zbar barcode reader and it accept only Y800 format(i also have no idea what is it and why is it)

I appreciate give me some idea and/or help.

Regards
 
ibrahim yener
Ranch Hand
Posts: 202
Android Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is logcat logs until barcode scanner scan it and stop preview

12-24 02:27:15.496: W/KeyCharacterMap(14638): Can't open keycharmap file
12-24 02:27:15.496: W/KeyCharacterMap(14638): Error loading keycharmap file '/system/usr/keychars/pm8058-keypad.kcm.bin'. hw.keyboards.0.devname='pm8058-keypad'
12-24 02:27:15.496: W/KeyCharacterMap(14638): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
12-24 02:27:40.016: D/dalvikvm(14638): GC_FOR_MALLOC freed 492K, 51% free 3403K/6919K, external 1705K/2133K, paused 17ms
12-24 02:27:40.066: D/dalvikvm(14638): GC_FOR_MALLOC freed 511K, 52% free 3352K/6919K, external 1705K/2133K, paused 32ms
12-24 02:27:40.146: D/dalvikvm(14638): GC_FOR_MALLOC freed 17K, 46% free 3794K/6919K, external 1705K/2133K, paused 21ms
12-24 02:27:40.196: D/dalvikvm(14638): GC_FOR_MALLOC freed 909K, 52% free 3344K/6919K, external 1705K/2133K, paused 19ms
12-24 02:27:40.246: D/dalvikvm(14638): GC_FOR_MALLOC freed 451K, 52% free 3352K/6919K, external 1705K/2133K, paused 15ms
12-24 02:27:40.306: D/dalvikvm(14638): GC_FOR_MALLOC freed 17K, 46% free 3794K/6919K, external 1705K/2133K, paused 16ms
12-24 02:27:40.356: D/dalvikvm(14638): GC_FOR_MALLOC freed 909K, 52% free 3344K/6919K, external 1705K/2133K, paused 15ms
12-24 02:27:40.416: D/dalvikvm(14638): GC_FOR_MALLOC freed 459K, 52% free 3344K/6919K, external 1705K/2133K, paused 16ms
12-24 02:27:40.466: D/dalvikvm(14638): GC_FOR_MALLOC freed 459K, 52% free 3344K/6919K, external 1705K/2133K, paused 15ms
12-24 02:27:40.526: D/dalvikvm(14638): GC_FOR_MALLOC freed 459K, 52% free 3344K/6919K, external 1705K/2133K, paused 15ms
12-24 02:27:40.576: D/dalvikvm(14638): GC_FOR_MALLOC freed 459K, 52% free 3344K/6919K, external 1705K/2133K, paused 15ms
12-24 02:27:40.636: D/dalvikvm(14638): GC_FOR_MALLOC freed 459K, 52% free 3344K/6919K, external 1705K/2133K, paused 15ms
12-24 02:27:40.696: D/dalvikvm(14638): GC_FOR_MALLOC freed 459K, 52% free 3344K/6919K, external 1705K/2133K, paused 15ms
12-24 02:27:40.746: D/dalvikvm(14638): GC_FOR_MALLOC freed 459K, 52% free 3344K/6919K, external 1705K/2133K, paused 18ms
12-24 02:27:40.806: D/dalvikvm(14638): GC_FOR_MALLOC freed 459K, 52% free 3344K/6919K, external 1705K/2133K, paused 16ms
12-24 02:27:40.856: D/dalvikvm(14638): GC_FOR_MALLOC freed 459K, 52% free 3344K/6919K, external 1705K/2133K, paused 18ms
12-24 02:27:40.926: D/dalvikvm(14638): GC_FOR_MALLOC freed 451K, 52% free 3352K/6919K, external 1705K/2133K, paused 21ms

end of the log file, there is no error, no warning nothing.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The bytes you are getting are from the camera - raw pixel data. There is no header or meta data associated with it. Sending those bytes to a file named .png does not add the header and meta data. in Android, you need to make a Bitmap out of those bytes so they get constructed into an understandable image. Then you can look at the API for Bitmap and see how you can convert the image to various file formats, such as JPEG or PNG.
 
ibrahim yener
Ranch Hand
Posts: 202
Android Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for late reply. I caught cold and i was so sick yesterday but getting better now.

I am going to search Bitmap tonight. I hope i can figure out and solve this issue.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic