我遇到了一個問題,現在我被困在很長時間,我希望你們能幫助我。 我得到了一段代碼,可以打開圖像,更改飽和度(使用seekbar)。那麼我想保存更改後的圖像。但是最後一部分並不適合。使用此代碼,我可以更改飽和度,然後保存更改後的位圖,但它將ImageView的大小保存爲位圖(480 x 517),但是他確實應用了飽和度更改(這很好)。無法保存已更改的位圖(已更改飽和度)
ColorMatrix cm = new ColorMatrix();
System.out.println(progress2);
cm.setSaturation(progress2);
ColorFilter = new ColorMatrixColorFilter(cm);
bitmap_image = BitmapFactory.decodeFile(filePath);
ImageView img = (ImageView) findViewById(R.id.gallery1);
img.setColorFilter(ColorFilter);
img.setImageBitmap(bitmap_image);
img.buildDrawingCache(true);
img.setDrawingCacheEnabled(true);
Bitmap b = img.getDrawingCache();
Bitmap resizedBitmap = Bitmap.createBitmap(bitmap_image, 0, 0, 3264, 2448);
File file = new File(sdcard+"/DCIM/Camera/image3.jpg");
try {
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
**b.compress(CompressFormat.JPEG, 100, ostream);**
ostream.close();
} catch (Exception e)
{
System.out.println("WRITING HAS FAILED");
e.printStackTrace();
}
而下一個代碼,我也可以改變飽和度,但是當我保存位圖時,它確實保存了原始高度和寬度(3264 x 2448)的位圖,但不保存飽和度更改。
ColorMatrix cm = new ColorMatrix();
System.out.println(progress2);
cm.setSaturation(progress2);
ColorFilter = new ColorMatrixColorFilter(cm);
bitmap_image = BitmapFactory.decodeFile(filePath);
ImageView img = (ImageView) findViewById(R.id.gallery1);
img.setColorFilter(ColorFilter);
img.setImageBitmap(bitmap_image);
img.buildDrawingCache(true);
img.setDrawingCacheEnabled(true);
Bitmap b = img.getDrawingCache();
Bitmap resizedBitmap = Bitmap.createBitmap(bitmap_image, 0, 0, 3264, 2448);
File file = new File(sdcard+"/DCIM/Camera/image3.jpg");
try {
file.createNewFile();
FileOutputStream ostream = new FileOutputStream(file);
**resizedBitmap.compress(CompressFormat.JPEG, 100, ostream);**
ostream.close();
} catch (Exception e)
{
System.out.println("WRITING HAS FAILED");
e.printStackTrace();
}
但我需要的是可以節省的飽和度變化(代碼1),並保持原來的寬度 - 高度(代碼2),但不知何故,我似乎並沒有得到這些代碼2一起工作。
請把我放在好的方向。代碼可能是一團糟,嘗試了很多東西,結構並沒有越來越好。
**code** that is the line that changed.
編輯: 當我這樣做:(瑞奇的建議)
Bitmap resizedBitmap = Bitmap.createBitmap(b, 0, 0, 3264, 2448);
我得到這個錯誤日誌:
03-09 15:03:02.880: E/AndroidRuntime(847): FATAL EXCEPTION: main
03-09 15:03:02.880: E/AndroidRuntime(847): java.lang.NullPointerException
03-09 15:03:02.880: E/AndroidRuntime(847): at android.graphics.Bitmap.createBitmap(Bitmap.java:409)
03-09 15:03:02.880: E/AndroidRuntime(847): at android.graphics.Bitmap.createBitmap(Bitmap.java:383)
03-09 15:03:02.880: E/AndroidRuntime(847): at com.dlv.groenmeter.GroenMeterActivity$13.onStopTrackingTouch(GroenMeterActivity.java:937)
03-09 15:03:02.880: E/AndroidRuntime(847): at android.widget.SeekBar.onStopTrackingTouch(SeekBar.java:115)
03-09 15:03:02.880: E/AndroidRuntime(847): at android.widget.AbsSeekBar.onTouchEvent(AbsSeekBar.java:303)
03-09 15:03:02.880: E/AndroidRuntime(847): at android.view.View.dispatchTouchEvent(View.java:3938)
03-09 15:03:02.880: E/AndroidRuntime(847): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
03-09 15:03:02.880: E/AndroidRuntime(847): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
03-09 15:03:02.880: E/AndroidRuntime(847): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
03-09 15:03:02.880: E/AndroidRuntime(847): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
03-09 15:03:02.880: E/AndroidRuntime(847): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1730)
03-09 15:03:02.880: E/AndroidRuntime(847): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1142)
03-09 15:03:02.880: E/AndroidRuntime(847): at android.app.Activity.dispatchTouchEvent(Activity.java:2102)
03-09 15:03:02.880: E/AndroidRuntime(847): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1714)
03-09 15:03:02.880: E/AndroidRuntime(847): at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2218)
03-09 15:03:02.880: E/AndroidRuntime(847): at android.view.ViewRoot.handleMessage(ViewRoot.java:1889)
03-09 15:03:02.880: E/AndroidRuntime(847): at android.os.Handler.dispatchMessage(Handler.java:99)
03-09 15:03:02.880: E/AndroidRuntime(847): at android.os.Looper.loop(Looper.java:123)
03-09 15:03:02.880: E/AndroidRuntime(847): at android.app.ActivityThread.main(ActivityThread.java:3691)
03-09 15:03:02.880: E/AndroidRuntime(847): at java.lang.reflect.Method.invokeNative(Native Method)
03-09 15:03:02.880: E/AndroidRuntime(847): at java.lang.reflect.Method.invoke(Method.java:507)
03-09 15:03:02.880: E/AndroidRuntime(847): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
03-09 15:03:02.880: E/AndroidRuntime(847): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
03-09 15:03:02.880: E/AndroidRuntime(847): at dalvik.system.NativeStart.main(Native Method)
七號線(標有**「代碼'**),這是唯一的改變,其餘的代碼是相同的IDD,但它應該給我更好的視角。 – Bigflow 2012-03-09 14:01:45
我現在看到了,thnx – Caner 2012-03-09 14:11:57