Android 缩放期间无法读取图像内容
当我用手指缩放图像时,我无法读取图像的内容。这是我的代码:-Android 缩放期间无法读取图像内容,android,bitmap,image-gallery,android-gallery,Android,Bitmap,Image Gallery,Android Gallery,当我用手指缩放图像时,我无法读取图像的内容。这是我的代码:- if(!(it.isEmpty() )) { Collections.sort(it); for(int i=0; i<it.size();i++) { ImageViewTouch imageView = new ImageViewTouch(GalleryTouchTestActivity.this); imageView.setLayoutParams(new Galler
if(!(it.isEmpty() )) {
Collections.sort(it);
for(int i=0; i<it.size();i++) {
ImageViewTouch imageView = new ImageViewTouch(GalleryTouchTestActivity.this);
imageView.setLayoutParams(new Gallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
final Options options = new Options();
options.outHeight = (int) scaleHeight; // new smaller height
options.outWidth = (int) scaleWidth; // new smaller width
options.inScaled = true;
options.inPurgeable = true;
options.inSampleSize = 8;
String photoURL = it.get(i);
Bitmap bitmap = BitmapFactory.decodeFile(photoURL,options);
imageView.setImageBitmap(bitmap);
arrayAdapter.add(imageView);
}
if(!(it.isEmpty()){
集合。排序(it);
对于(int i=0;i尝试将值更改为2
options.inSampleSize = 2;
使用此函数代替BitmapFactory.decodeFile(photoURL,选项)
将filecache类的对象设置为filecache filecache=new filecache(上下文)
和复制流的乐趣
public static void CopyStream(InputStream is, OutputStream os)
{
final int buffer_size=1024;
try
{
byte[] bytes=new byte[buffer_size];
for(;;)
{
int count=is.read(bytes, 0, buffer_size);
if(count==-1)
break;
os.write(bytes, 0, count);
}
}
catch(Exception ex){}
}
您可以为此使用WebView
:
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setAllowFileAccess(true);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setBuiltInZoomControls(true);
String base = Environment.getExternalStorageDirectory().getAbsolutePath().toString();
String imagePath = "file:/"+ base + "/test.jpg";
String html = "<html><head></head><body><img src=\""+ imagePath + "\"></body></html>";
mWebView.loadData(html, "text/html","utf-8");
mWebView=(WebView)findViewById(R.id.WebView);
mWebView.getSettings().setAllowFileAccess(true);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().SetBuilTinZoomControl(true);
String base=Environment.getExternalStorageDirectory().getAbsolutePath().toString();
字符串imagePath=“文件:/”+base+“/test.jpg”;
字符串html=“”;
loadData(html,“text/html”,“utf-8”);
谢谢您的回复,但我也使用了它,并且获得了异常AutofmemoryError异常BitmapFactory.decodeFile异常是在我使用选项时生成的。InInInSampleSize=2感谢您的回复。但是在“fileCache”和“Utils2”中我需要使用什么。使用此变量的位置是DoutpOutstream os=new FileOutputStream(f);Utils2.CopyStream(is,os);我需要为“f”和“Utils2”使用什么值,先生,,这段代码在“f”和“Utils2”中显示错误。我们需要为这个变量设置值。OutputStream os=new FileOutputStream(f);Utils2.CopyStream(is,os);您好,先生,这段代码没有运行。如果您同意,我可以给您我的项目。请帮助我。它返回空位图图像setImageBitmap:null这解决了您的问题吗?这是一个非常简单有效的方法。
public static void CopyStream(InputStream is, OutputStream os)
{
final int buffer_size=1024;
try
{
byte[] bytes=new byte[buffer_size];
for(;;)
{
int count=is.read(bytes, 0, buffer_size);
if(count==-1)
break;
os.write(bytes, 0, count);
}
}
catch(Exception ex){}
}
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setAllowFileAccess(true);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setBuiltInZoomControls(true);
String base = Environment.getExternalStorageDirectory().getAbsolutePath().toString();
String imagePath = "file:/"+ base + "/test.jpg";
String html = "<html><head></head><body><img src=\""+ imagePath + "\"></body></html>";
mWebView.loadData(html, "text/html","utf-8");