对于一个项目,我正致力于使用隐写技术隐藏图像中的文本。我在我的应用程序中实现了一个类,要求我选择一个图像(.png)并修改每个像素的最低有效位。现在的问题是我有一个整数数组,我必须从中创建一个新的Image(.png)并将其保存到外部存储器中。我怎样才能做到这一点? PS:我不能使用BufferedImage!
这是在修改最低有效位之前的代码。
package com.dev.paolo.sicinf;
import android.content.CursorLoader;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v7.app.ActionBarActivity;
import java.io.File;
import java.math.BigInteger;
import java.sql.SQLException;
public class SendKey extends ActionBarActivity{
private static final int FILE_SELECT_CODE=0;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("file/");
startActivityForResult(Intent.createChooser(intent, "Select an Image"), FILE_SELECT_CODE);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode)
{
case FILE_SELECT_CODE:
if(resultCode==RESULT_OK)
{
Uri uri2 = data.getData();
String[] proj = {MediaStore.Images.Media.DATA};
CursorLoader cursorLoader = new CursorLoader(this,uri2,proj,null,null,null);
Cursor cursor = cursorLoader.loadInBackground();
int column_index=cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
String uri = cursor.getString(column_index);
File file = new File(uri);
Bitmap img = BitmapFactory.decodeFile(uri);
int height = img.getHeight();
int width = img.getWidth();
int[] pixel = new int[height * width];
img.getPixels(pixel, 0, width, 1, 1, width-1, height-1);
String key = "prova";
byte[] b = key.getBytes();
int count = 0;
for (byte current_byte : b) {
for (int j = 7; j >= 0; j--) {
int lsb = (current_byte >> j) & 1;
pixel[count] = (pixel[count] & 0xfffffffe) + lsb;
count++;
}
}
//from int[] create image and save to external memory
}
break;
}
}
}
答案 0 :(得分:0)
使用Bitmap.createBitmap(int [] colors,int offset,int stride,int width,int height,Bitmap.Config config)创建位图对象。然后使用Bitmap.compress()将其写入文件