صورة ملفوف واكتب ملف الصور المنقذ في بلاك بيري

StackOverflow https://stackoverflow.com/questions/2863277

  •  30-09-2019
  •  | 
  •  

سؤال

أنا أستخدم الكود التالي لتغيير حجم وحفظ الملف في جهاز BlackBerry. بعد مقياس الصورة ، أحاول كتابة ملف الصورة في الجهاز. لكنه يعطي نفس البيانات. (ارتفاع وعرض الصورة متشابهة).

يمتد Class ResizeImage MainScreen الأدوات FieldChangelistener {private string path = "file: ///sdcard/blackberry/pictures/test.jpg" ؛ Private Buttonfield BTN ؛ ResizeImage () {btn = new buttonfield ("write file") ؛ btn.setchangelistener (هذا) ؛ إضافة (BTN) ؛ } public void fieldChanged (حقل الحقل ، سياق int) {if (field == btn) {try {
inputStream inputStream = null ؛ // الحصول على اتصال الملف fileConnection fileConnection = (fileConnection) connector.open (path) ؛ if (fileConnection.exists ()) {inputStream = fileConnection.openinputStream () ؛ // byte data [] = inputStream.toString (). getBytes () ؛

                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    int j = 0;
                    while((j=inputStream.read()) != -1) {
                    baos.write(j);
                    }
                    byte data[] = baos.toByteArray();                
                    inputStream.close();
                    fileConnection.close();  

                    WriteFile("file:///SDCard/BlackBerry/pictures/org_Image.jpg",data);           


                    EncodedImage  eImage = EncodedImage.createEncodedImage(data,0,data.length);                               
                    int scaleFactorX = Fixed32.div(Fixed32.toFP(eImage.getWidth()), Fixed32.toFP(80));
                    int scaleFactorY = Fixed32.div(Fixed32.toFP(eImage.getHeight()), Fixed32.toFP(80));
                    eImage=eImage.scaleImage32(scaleFactorX, scaleFactorY);   

                    WriteFile("file:///SDCard/BlackBerry/pictures/resize.jpg",eImage.getData());

                    BitmapField bit=new BitmapField(eImage.getBitmap());                       
                    add(bit);

                }       
            }
            catch(Exception e)
            {
                System.out.println("Exception is ==> "+e.getMessage());
            }

        }
   }


   void WriteFile(String fileName,byte[] data)
   {
       FileConnection fconn = null;
        try
        {
            fconn = (FileConnection) Connector.open(fileName,Connector.READ_WRITE);
        } 
        catch (IOException e) 
        {
            System.out.print("Error opening file");
        }

        if (fconn.exists())
        try 
        {
            fconn.delete();
        }
        catch (IOException e)
        {
            System.out.print("Error deleting file");
        }
        try 
        {
            fconn.create();
        }
        catch (IOException e) 
        {
            System.out.print("Error creating file");
        }
        OutputStream out = null;
        try
        {
            out = fconn.openOutputStream();
        } 
        catch (IOException e) {
            System.out.print("Error opening output stream");
        }

        try 
        {
            out.write(data);
        }
        catch (IOException e) {
            System.out.print("Error writing to output stream");
        }

        try
        {
            fconn.close();
        } 
        catch (IOException e) {
            System.out.print("Error closing file");
        }
    }

}

هل كانت مفيدة؟

المحلول

تحقق من getScaledheight () و getScaledWidth () في encodedImage.

إنها خدعة قذرة.

إذا قمت بتقشير النقطة المعتادة باستخدام getBitMap () التي سيكون لها getheight () و getWidth ().

ثم إذا كنت ترغب في حفظ تلك الصورة المقوسة كـ JPEG ، فأنت بحاجة إلى إعادة تشفير.

على سبيل المثال

Bitmap scaledBMP = scaledEI.getBitmap();
JPEGEncodedImage finalJPEG = JPEGEncodedImage.encode(scaledBMP, 80); // int arg is quality
raw_media_bytes = finalJPEG.getData();
raw_length = finalJPEG.getLength();
raw_offset = finalJPEG.getOffset();

// don't forget to use the length and offset info, because getData() is
// not guaranteed to work by itself.

AFAIK ، قبل 5.0 على الأقل لا يوجد تحجيم محلي في jpeg مع التحويل مع صورة نقطية.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top