感谢Schermvlieger在anddev.org上提出这个问题,
我只是把他的问题复制到SO,因为没有人在另一个网站上回复,我也面临同样的问题.
我想知道BitmapFactory.Options.inSampleSize关于显示图像的速度的最佳用途是什么.
文档提到使用2的幂的值,所以我正在使用2,4,8,16等.
我想知道的是:
OutOfMemoryError?BitmapFactory对于较大的文件,setImageURI()对于较小的文件)显示图像是否有效.我正在使用一种ImageSwitcher方式.Bitmap,BitmapFactory.Options并inTempStorage在应用程序的开头或只对动态创建它们,在需要的时候?我正在开发一个应用程序,我需要从中选择一个图像sd card并在图像视图中显示它.现在我希望用户通过单击按钮减小/增加其宽度,然后将其保存回SD卡.
我已经完成了图像拾取并在ui上显示它.但无法找到如何调整它的大小.任何人都可以建议我如何实现它.
我想知道是否有一种确保Image对象引用完全黑色图像的超高效方法,因此位图中的每个像素都是ARGB(255,0,0,0).
你会推荐什么?这些位图中的大多数将是1024 x 6000像素(尽管假设它们总是那么大,这是不安全的).
我需要这个,因为我们遇到了PrintWindow API的问题.我们发现近20%的时间,至少图像的某些部分将是黑色方块(后续捕获将成功).我想解决这个问题的方法是在每个子窗口中调用PrintWindow或WM_PRINT,然后将窗口的整个图像重新组合在一起.如果我能找到一种有效的方法来检测PrintWindow为特定子窗口返回黑色图像,那么我可以在该捕获上再次快速调用PrintWindow.它很糟糕,但PrintWindow是捕获适用于所有窗口(我想要的)窗口的唯一方法,并支持捕获隐藏和/或屏幕外的窗口.
当PrintWindow失败时,它不会设置错误代码或返回任何指示失败的内容.当它出现这个黑色方块问题时,它总是整个窗口或子窗口返回黑色.因此,通过分别捕获每个子窗口,我可以确定每个捕获都有效,只要它包含至少一个非黑色像素.
显然,PrintWindow在Vista及更高版本中更好,但在这种情况下,我们仅限于Server 2003.
我想将Bitmap打印到移动蓝牙打印机(Bixolon SPP-R200) - SDK不提供direkt方法来打印内存中的图像.所以我想过转换像这样的Bitmap:
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Run Code Online (Sandbox Code Playgroud)
到单色位图.我使用Canvas在上面给出的Bitmap上绘制黑色文本,效果很好.但是,当我将上面的位图转换为ByteArray时,打印机似乎无法处理这些字节.我怀疑我需要一个每像素一位的数组(一个像素将是白色= 1或黑色= 0).
由于似乎没有方便的,开箱即用的方式,我有一个想法是使用:
bitmap.getPixels(pixels, offset, stride, x, y, width, height)
Run Code Online (Sandbox Code Playgroud)
获取像素.我假设,我必须按如下方式使用它:
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int [] pixels = new int [width * height];
bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
Run Code Online (Sandbox Code Playgroud)
但是 - 我不确定一些事情:
这种方法有意义吗?有没有更简单的方法?仅仅将位图设置为黑白是不够的,主要问题是将每个像素的颜色信息减少为一位.
UPDATE
根据Reuben的建议,我首先将Bitmap转换为单色Bitmap.然后我将迭代每个像素:
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int[] pixels = new int[width * height];
bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
// …Run Code Online (Sandbox Code Playgroud) 我正在为我的方形平台平台游戏制作一个二维地图编辑器,当我意识到我真的可以使用一个图像编辑器,它能够重新绘制相邻的像素等等,所以我想我应该尝试通过应用程序读取绘制的水平然后将其转换为轻量级格式.
我不确定是否使用位图格式是必须的,但我猜,读取特定像素比使用PNG更容易.
所以我的目标是打开一个图像,遍历每个像素,寻找那些适合我的图块方案的颜色,并将相应的图块放入块数组中.
注意:我已经有了轻量级格式,所以我只需要将像素值读入数组.
Bitmap myBitmap = new Bitmap(@"input.png");
for (int x = 0; x < myBitmap.Width; x++)
{
for (int y = 0; y < myBitmap.Height; y++)
{
Color pixelColor = myBitmap.GetPixel(x, y);
// things we do with pixelColor
}
}
Run Code Online (Sandbox Code Playgroud)
Bitmap myBitmap = new Bitmap(@"input.png");
for (int x = 0; x < myBitmap.Width; x++)
{
for (int y = 0; y < myBitmap.Height; y++)
{
// Get the color of a pixel within myBitmap.
Color …Run Code Online (Sandbox Code Playgroud) 开发者网站只是声明getHeight()将返回位图的高度,但有人可以告诉我这是像素单位还是dp单位?
每当我调用UploadActivity.java时,我都会收到java.lang.OutOfMemoryError
第176行是:
Bitmap bm = BitmapFactory.decodeFile(strPath);
Run Code Online (Sandbox Code Playgroud)
查看我的日志:
12-07 17:57:10.585: E/AndroidRuntime(16708): FATAL EXCEPTION: main
12-07 17:57:10.585: E/AndroidRuntime(16708): java.lang.OutOfMemoryError
12-07 17:57:10.585: E/AndroidRuntime(16708): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
12-07 17:57:10.585: E/AndroidRuntime(16708): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:650)
12-07 17:57:10.585: E/AndroidRuntime(16708): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:389)
12-07 17:57:10.585: E/AndroidRuntime(16708): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:449)
12-07 17:57:10.585: E/AndroidRuntime(16708): at com.example.camera.UploadActivity$ImageAdapter.getView(UploadActivity.java:176)
12-07 17:57:10.585: E/AndroidRuntime(16708): at android.widget.AbsListView.obtainView(AbsListView.java:2465)
12-07 17:57:10.585: E/AndroidRuntime(16708): at android.widget.ListView.makeAndAddView(ListView.java:1775)
12-07 17:57:10.585: E/AndroidRuntime(16708): at android.widget.ListView.fillDown(ListView.java:678)
12-07 17:57:10.585: E/AndroidRuntime(16708): at android.widget.ListView.fillFromTop(ListView.java:739)
12-07 17:57:10.585: E/AndroidRuntime(16708): at android.widget.ListView.layoutChildren(ListView.java:1628)
12-07 17:57:10.585: E/AndroidRuntime(16708): at android.widget.AbsListView.onLayout(AbsListView.java:2300)
12-07 17:57:10.585: E/AndroidRuntime(16708): at …Run Code Online (Sandbox Code Playgroud) 我得到了下一个异常:当设置为true 时,问题解码到现有位图inBitmap ;
引起:java.lang.IllegalArgumentException:
在android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:460)解码到现有位图时出现问题
...
有趣的是,在运行时,相同的代码在不同的地方失败:
这是我的代码,它是这个DevBytes:Bitmap Allocation视频中显示的副本.
private BitmapFactory.Options options;
private Bitmap reusedBitmap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ImageView imageView = (ImageView) findViewById(R.id.image_view);
// set the size to option, the images we will load by using this option
options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
options.inMutable = true;
BitmapFactory.decodeResource(getResources(), R.drawable.img1, options);
// we will create empty bitmap by using the option
reusedBitmap = Bitmap.createBitmap(options.outWidth, options.outHeight, …Run Code Online (Sandbox Code Playgroud) 我需要将System.Drawing.Bitmap转换为System.Windows.Media.ImageSource类,以便将其绑定到WizardPage(扩展WPF工具包)的HeaderImage控件中.位图设置为我编写的程序集的资源.它被引用如下:
public Bitmap GetBitmap
{
get
{
Bitmap bitmap = new Bitmap(Resources.my_banner);
return bitmap;
}
}
public ImageSource HeaderBitmap
{
get
{
ImageSourceConverter c = new ImageSourceConverter();
return (ImageSource) c.ConvertFrom(GetBitmap);
}
}
Run Code Online (Sandbox Code Playgroud)
这个转换器是我在这里找到的:http://www.codeproject.com/Questions/621920/How-to-convert-Bitmap-to-ImageSource 我得到一个NullReferenceException at
return (ImageSource) c.ConvertFrom(Resources.my_banner);
如何初始化ImageSource以避免此异常?或者还有另一种方式吗?我想在之后使用它:
<xctk:WizardPage x:Name="StartPage" Height="500" Width="700"
HeaderImage="{Binding HeaderBitmap}" Enter="StartPage_OnEnter"
Run Code Online (Sandbox Code Playgroud)
提前感谢您的任何答案.
bitmap ×10
android ×7
c# ×3
image ×3
.net ×1
imagesource ×1
java ×1
monochrome ×1
rgb ×1
wpf ×1