public class ImageZoomActivity extends Activity {
private ImageViewTouch mImageView;
int width,height;
Bitmap snoop;
int i=1,k=1;
Matrix mat ;
static Bitmap resizedBitmap;
@Override
protected void onCreate( Bundle savedInstanceState )
{
super.onCreate( savedInstanceState );
requestWindowFeature( Window.FEATURE_NO_TITLE );
setContentView( R.layout.editface );
Bundle bundle = getIntent().getExtras();
String str = bundle.getString("image");
File imgfile=new File(str);
snoop=BitmapFactory.decodeFile(imgfile.getAbsolutePath());
getWindow().addFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN );
mat = new Matrix();
mat.postRotate(0);
resizedBitmap = Bitmap.createBitmap(snoop, 0, 0,
snoop.getWidth(), snoop.getHeight(), mat, true);
mImageView.setImageBitmapReset( snoop, 0, true );
ImageView leftarrow=(ImageView)findViewById(R.id.leftarrow);
leftarrow.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mat = new Matrix();
mat.postRotate(360-k*1);
resizedBitmap = Bitmap.createBitmap(snoop, 0, 0,
snoop.getWidth(), snoop.getHeight(), mat, true);
mImageView.setImageBitmap(resizedBitmap);
i--;
k++;
}
});
ImageView rigtharrow=(ImageView)findViewById(R.id.rigtharrow);
rigtharrow.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mat = new Matrix();
mat.postRotate(1*i);
resizedBitmap = Bitmap.createBitmap(snoop, 0, 0,
snoop.getWidth(), snoop.getHeight(), mat, true);
mImageView.setImageBitmap(resizedBitmap);
i++;
k--;
}
});
}
@Override
public void onContentChanged()
{
super.onContentChanged();
mImageView = (ImageViewTouch)findViewById( R.id.imageView1 );
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.next, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle item selection
switch (item.getItemId()) {
case R.id.next:
Bitmap bt=Bitmap.createBitmap(resizedBitmap, 45, 20,240,310, mat, true);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bt.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
Intent i = new Intent(ImageZoomActivity.this,AdjustGoggles.class);
i.putExtra("btmap", bt);
i.putExtra("image", byteArray);
startActivity(i);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
使用这些代码我正在缩放和旋转图像如何获得缩放图像位图。我想在下一个活动中使用缩放图像。旋转图像返回resizedBitmap.what我想做的是为缩放图像获取ResultentBitmap。 / p>
答案 0 :(得分:0)
使用以下命令从原始位图中检索缩放后的位图,并获得与原始位图相同的分辨率
public static Bitmap getZoomedImage(Bitmap originalImage, float scale) {
Bitmap scaledBitmap = Bitmap.createScaledBitmap(originalImage, (int)(originalImage.getWidth()*scale), (int)(originalImage.getHeight()*scale), false);
return Bitmap.createBitmap(
scaledBitmap,
(scaledBitmap.getWidth()-originalImage.getWidth())/2,
(scaledBitmap.getHeight()-originalImage.getHeight())/2,
originalImage.getWidth(),
originalImage.getHeight());
}