Problem with dimension of an image loaded from a database

Hi,
I succeed in saving image in a MSAccess database with this code:
Image img;
image = new ImageIcon("d:\\prova\\comore.jpg");
img=image.getImage();
try{
int[] pix = new int[img.getWidth(null) * img.getHeight(null)];
PixelGrabber pg = new PixelGrabber(img, 0, 0, img.getWidth(this), img.getHeight(this), pix, 0, img.getWidth(this));
pg.grabPixels();
System.out.println(pix.length);
byte[] pixels = new byte[img.getWidth(this) * img.getHeight(this)*4];
for(int j=0;j<pix.length;j++){
pixels[j] = new Integer(pix[j]).byteValue();
String sql="insert into Immagini values ('1',?)";
PreparedStatement ps = con.prepareStatement(sql);
ps.setBytes(1,pix);
ps.executeUpdate();
}catch(Exception except){
except.printStackTrace();
then, I've load the image with this code:
try{
String query = "select * from Immagini where IDprog = 1";
Statement s = con.createStatement();
s.executeQuery(sql);
ResultSet rs=s.getResultSet();
rs.next();
Viaggio vi = new Viaggio(rs.getInt(1),rs.getBytes(2));
byte[] b=vi.getBytesImage();
int[] intImage = new int[b.length];
for(int j=0;j<b.length;j++){
intImage[j]=(int)b[j];
Image img = createImage(new MemoryImageSource(124,100,intImage,0,124));
ImageIcon imgic = new ImageIcon(img);
jLabel3.setIcon(imgic);
}catch(Exception tps){
tps.printStackTrace();
All works correctly;
but I've two problems:
How do I do to take the dimension of the image from the byte array?
infact in the code up written I've used 124 and 100 as image dimension;
but I can have images of different dimension.
The other problem is:
Why in the image that is loaded are not the same number of colors of the image saved, but only a few, so that the image seems to be out of focus?
Thank and excuse me for my english.
I'm Italian.

Noone can help me?
Thank

Similar Messages

  • Problem with "Back" Button in pages loaded from Google search results

    I am using Windows XP Home 32bit and Mozilla Firefox Ver 5.0
    I do a search using Google and I go to page 3 of the returned queries (links) and then go to one of the sites from the search results. When I hit the return button while in the site chosen from the search results, instead of returning to page 3, it always returns to page 1 of the search results.
    This happens on any page ie I go to page 22 and use a link then hit return button it still returns to page 1.
    Only started happening in past couple of days and it's very annoying. I have not updated Firefox or added any new extensions/add-ons. i have cleared cookies, uninstalled and reinstalled Firefox and issue still appears.
    I have Google Chrome and IE and tried the same query in both and it works as it should work, ie returns to the correct page, so my conclusion is that it may be a Firefox Ver 5 issue.

    If I turn off the "Use a secure HTTPS connection when available." setting in the google search settings, then the problem goes away...

  • ERR "Could not load "image-loading" from icon theme"

    Just finished installing OpenBox on a virtualbox
    But cannot get nitrogen to set background.
    while running nitrogen from command line
    [utkarsh@myhost ~] $ nitrogen
    ERR: Could not load "image-loading" from icon theme, this indicates a problem with your Gtk/Gtkmm install

    I too had to the same problem. Couldn't find why we get that error. But could set the wallpaper using the command line.

  • How do I fix problem with linked and cropped image frames not printing properly when spanning pages?

    We are using InDesign (ID) to develop and print church bulletins which contain a combination of text frames and graphics. One of the graphic types we use are TIF files which are high-resolution scans of hymns.
    A hymn usually has a combination of the musical score, plus the lyrics - with many verses., so the modular structure is 'staff' composed of a treble clef, followed by verses, followed by a base clef.
    If the example above had 6 verses instead of one, we would crop the image by adjusting the frame, so that the treble clef and the desired verses showed through the frame.
    We would then copy and link the frame - piggy back - adjusting the next content window etc....so we build a custom version of the music as a series of linked frames - each with the same base image, but a different frame position.
    So this works fine, when we do this on a single page, but when we then add a 'last staff' at the top of the following page, we encounter print problems with some output devices.
    Imagine a two-page spread, with a full page of music on the left, and the last staff (treble clef, verses, base clef) unit as a separately linked frame at the top of the right page of the spread.
    It displays correctly, and will print individually as pages correctly, but when we print it as a booklet, the last frame drops out and we have blank space.
    I can print the document to PDF and it works fine, but if I print it to a copier or laser printer I get drop out.
    It is inconsistent.
    Previews are always okay. Individual page prints are okay, but when you print the entire document, the last frame in this kind of linked series gets blanked.
    If we create and name the image differently, and call it in as a new image - (not linked to the previous), but it is still a large image that is cropped to a small piece, then it doesn't print.
    If we save the last frame as a different image type (take the TIFF file into photoshop, crop it and save it as a jpg - so it is only the 'snippet') and then import it, it works fine.
    So my question to you InDesigners....is there some setting or tip or trick I need to know to be able to link a series of frames with the same base image, but different crops and make it span across two pages properly.
    Or do we need to play this game of crop and trim the image so that it doesn't drop out?
    Any thoughts, advice, direction would be gratefully received!

    I did a lot of such hymn things in the past, but I was alway working on the scans in Photoshop, like adjusting, retouching spots and cropping. And I was always seperating those images to be more flexible so I never run into such a problem.
    I am always scanning in a higher quality level than I would need, I scan it in color, this allows me to eliminate paper color easily, even if I need 1-bit images at the end, I do it in color, so I can also turn the image.
    I did once run into a similar problem with a scan I have got from a copier-scanner machine (it was not a song). But saving as PSD resolved my problem.
    So I would suggest: Open your files in Photoshop, resave them as PSD files and use those instead. If you use 1-bit images (which is fine for this type of images) you should use a resolution equal to the printer's resolution.

  • Have been trying all weekend to upload Jpegs- either Send does not work or shows files uploading then shows error- never had this problem with Send Now-16 images total size 92MB-largest image 13MB

    Have been trying all weekend to upload Jpegs- either Send does not work or shows files uploading then shows error- never had this problem with Send Now-16 images total size 92MB-largest image 13MB

    Hi Ciaran19,
    Are you sending files from the Adobe Send interface, Adobe Reader, or the Outlook plug-in?
    Have you checked to see whether the files that you're sending appear in the Recent Files/Sent Files list when you're logged on to https://cloud.acrobat.com? (It could be that they're uploading, but not being sent.)
    It would also be worthwhile to send the files in smaller batches, to see whether a particular file or files is problematic, and causing the error.
    Please let us know how it goes. If you're still having trouble, please let us know where you're sending from, and whether you're able to send the files in smaller batches. It would also be helpful to know the exact error message that you're receiving.
    Best,
    Sara

  • Problem with shares on Windows 2003R2 server from a Windows 8.1 PC

    I'm having problem with shares on Windows 2003R2 server from a Windows 8.1 PC.  It times out when I try to copy a file from my PC to the server and I get an error message saying "There is a problem accessing network drive W:\. Make sure you are
    connected to the network and try again."
    I have no problem copying files from the server to the PC.
    Any ideas?

    Hi,
    How about your problem now? Have you test other machine also installed Windows 8.1? Did they have this problem?
    To diagnose this problem, firstly, please check Windows 2003R2 firewall settings, also can disable firewall temporarilly for test.
    Secondly, try to use Network Monitor to capture network communication package for test.
    Network Monitor:
    http://www.microsoft.com/en-us/download/details.aspx?id=4865
    Roger Lu
    TechNet Community Support

  • Jasper report on HTML when one image loaded from database and for the other

    How to generate jasper report on HTML when one image loaded from database and for the other we give a image path
    My code
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
              exporter = new JRHtmlExporter();
              exporter.setParameter(JRExporterParameter.JASPER_PRINT, print);
              exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, baos);
              exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, strImageInputDirectory);
         exporter.setParameter(JRHtmlExporterParameter.IMAGES_DIR_NAME, strImageOutputPath == null ? "." : strImageOutputPath);
         exporter.setParameter(JRHtmlExporterParameter.IS_OUTPUT_IMAGES_TO_DIR, Boolean.TRUE);
         exporter.setParameter(JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN, Boolean.FALSE);
         exporter.setParameter(JRHtmlExporterParameter.IS_WHITE_PAGE_BACKGROUND, Boolean.FALSE);
              exporter.exportReport();
              byte[] bdata = ((ByteArrayOutputStream) baos).toByteArray();
    Can any one help pls
    Message was edited by:
    ameet.au

    hey sorry for posting it in this forum.
    but do u have sample code for making it work.. since i am able to do it on PDF format(image from Database and another stored in the webserver) using
    byte image[] =(byte[]) outData.get("image");
                        ByteArrayInputStream img = new ByteArrayInputStream(image);
                        hmimg.put("P_PARAMV3", img);
    print = JasperFillManager.fillReport(reportFileName, hmimg, jrxmlds);
    bdata= JasperExportManager.exportReportToPdf(print);

  • I had already update mi new factory unlocked iPhone 4S to iOS 5.1.1 and I still having problems with "invalid sim". I'm from Argentina and here we don't have official service. PLEASE HELP ME, WHAT CAN I DO??? In Argentina is too expensive an iPhone 4S.

    I had already update mi new factory unlocked iPhone 4S to iOS 5.1.1 and I still having problems with "invalid sim". I'm from Argentina and here we don't have official service. PLEASE HELP ME, WHAT CAN I DO??? In Argentina is too expensive an iPhone 4S. Please I need help to continue believing in Apple. Thanks a lot. If anybody speak spanish better.  

    Was it purchased from an official Apple Store, not a reseller?  Only Apple Stores sell official factory unlocked phones.  The others sell hacked to unlock phones, and the unlocking is unstable.
    Try these steps, as needed:
    1. Reset phone - press both home and on/off buttons for at least 10 seconds until the Apple logo appears.
    2. Settings > General > Reset > Reset Network Settings.
    3. Replace SIM card (and reset network settings again)
    4. Restore Phone in iTunes using a backup
    5. Restore in iTunes as new, without using a backup

  • I have problems with activation, after delete mi Iphone from Icloud.

    I have problems with activation, after delete mi Iphone from Icloud.

    Hello Sikiz 21,
    Thanks for using Apple Support Communities.
    For more information on this, take a look at:
    iPhone: Troubleshooting activation issues
    http://support.apple.com/kb/TS3424
    iOS: Troubleshooting FaceTime and iMessage activation
    http://support.apple.com/kb/TS4268
    Best of luck,
    Mario

  • Had a problem with newest update and the advice from turingtest2 resolved my problem just to say thanks! Had never used this route before so was less painful than thought it would be again thanks.

    Had a problem with newest update and the advice from turingtest2 resolved my problem just to say thanks! Had never used this route before so was less painful than thought it would be again thanks.

    how can i find out what the fix is that works..please

  • I have a HP workforce 610 and cannot scan.  I just spoke with HP and they told me it is a software problem with my MAC for image capture.  Anyone else having difficulty?

    I have a HP workforce 610 and cannot scan.  I just spoke with HP and they told me it is a software problem with my MAC for image capture.  Anyone else having difficulty?

    If Image Capture doesn't work you could try the paid for app VueScan ( www.hamrick.com ). You can try it for free in demo mode to see if it works before purchase.

  • The ios8 update is causing innumerable problems with my ipad. The info from my calendar just disappeared, I am typing blind with the keyboard most of the time, and I cannot upload pics or paste to FB. When will this be fixed and what can I do in the

    The ios8 update is causing innumerable problems with my ipad. The info from my calendar just disappeared, I am typing blind with the keyboard most of the time, and I cannot upload pics or paste to FB. When will this be fixed and what can I do in the Meantime?

    Have you tried yesterday's update to iOS8.0.2?
    iOS 8.0.2
    This release contains improvements and bug fixes, including:
      •  Fixes an issue in iOS 8.0.1 that impacted cellular network connectivity and Touch ID on iPhone 6 and iPhone 6 Plus
      •  Fixes a bug so HealthKit apps can now be made available on the App Store
      •  Addresses an issue where 3rd party keyboards could become deselected when a user enters their passcode
      •  Fixes an issue that prevented some apps from accessing photos from the Photo Library
      •  Improves the reliability of the Reachability feature on iPhone 6 and iPhone 6 Plus
      •  Fixes an issue that could cause unexpected cellular data usage when receiving SMS/MMS messages
      •  Better support of Ask To Buy for Family Sharing for In-App Purchases
      •  Fixes an issue where ringtones were sometimes not restored from iCloud backups
      •  Fixes a bug that prevented uploading photos and videos from Safari
    For information on the security content of this update, please visit this website:
      http://support.apple.com/kb/HT1222

  • Anyone having problems with the Abc app no loading since it has been added?

    Anyone having problems with the Abc app no loading since it has been added?

    Hi Popalotofstyle,
    Thanks for using Apple Support Communities.  It may be worth trying a restart of your Apple TV to see if that allows the ABC app to load:
    Apple TV: How to restart your Apple TV
    http://support.apple.com/kb/ht3180
    Cheers,
    - Ari

  • Hi, I have a problem with my CD Cover image.

    Hi, I have a problem with my CD Cover image. I already released my Single to iTunes store. But the quality of Picture is bad'( Not like original one! Could you help me with this pls! Cheer's)

    If I was having the problem, I'd remove the email account completely off my iPod then re-add it.  If that doesn't work, I'd reset my password and try again.  These are all just ideas and not real concrete solutions.  Hope something works for you.

  • I am having problems with my droid incredible 2 loading texts and so I thought maybe I had too many saved, I tried to delete some of them and it wont seem to delete either?

    I am having problems with my droid incredible 2 loading texts and so I thought maybe I had too many saved, I tried to delete some of them and it wont seem to delete either?

    Did you pull the battery?

Maybe you are looking for