【发布时间】:2011-06-21 17:02:21
【问题描述】:
如何将位图的中间区域剪掉? 这是我的示例代码:
public void onPictureTaken(byte[] paramArrayOfByte, Camera paramCamera)
{
FileOutputStream fileOutputStream = null;
try {
File saveDir = new File("/sdcard/CameraExample/");
if (!saveDir.exists())
{
saveDir.mkdirs();
}
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 5;
Bitmap myImage = BitmapFactory.decodeByteArray(paramArrayOfByte, 0,paramArrayOfByte.length, options);
Bitmap bmpResult = Bitmap.createBitmap(myImage.getWidth(), myImage.getHeight(),Config.RGB_565);
int length = myImage.getHeight()*myImage.getWidth();
int[] pixels = new int[length];
myImage.getPixels(pixels, 0, myImage.getWidth(), 0,0, myImage.getWidth(), myImage.getHeight());
Bitmap TygolykovLOL = Bitmap.createBitmap(pixels, 0, myImage.getWidth(), myImage.getWidth(),myImage.getHeight(), Config.RGB_565);
Paint paint = new Paint();
Canvas myCanvas = new Canvas(bmpResult);
myCanvas.drawBitmap(TygolykovLOL, 0, 0, paint);
fileOutputStream = new FileOutputStream("/sdcard/CameraExample/" + "1ggggqqqqGj2.bmp");
BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream );
bmpResult.compress(CompressFormat.PNG, 100, bos);
bos.flush();
bos.close();
【问题讨论】:
-
乍一看,该代码确实使用 getPixels() 剪切了位图的中间部分。您是否遇到错误或尝试做其他事情?
-
当我指向 XY 时出现错误,更准确地说,我不明白如何指定一个坐标位置以在 myImage 的中间切出一个矩形。
-
如果您只说“错误”而不提供错误消息,这很难提供帮助。
标签: android