标签: bitmap

位图到大

可能重复:
"位图太大而无法上传到纹理中"

我正在使用相机拍照,然后我将图片保存在SD卡上,然后使用

Bitmap bm = BitmapFactory.decodeFile(path);

要获得位图,那么

imageView.setImageBitmap(bm); 设置它.

但是当我把它放到我的视野中使用时

mFrameLayout.addView(imageView); 没有显示图像,我回来了 Bitmap to large to be uploaded into texture

位图是 1944 high, 2592 wide

有什么想法吗?

I am using a tablet, 10.1 inches, acer iconia, a500, running ics.

android bitmap

2
推荐指数
1
解决办法
4449
查看次数

下载图像表单Web时,BitmapFactory.decodeStream返回null

我正在尝试使用Google示例页面从网址下载图片.我在BitmapFactory.decodeStream方法中使用InputStream时读过,我不能使用两次.我试图这样做,但它不起作用'因为它在解码图像中返回null,我不知道我能做什么.

这是我的代码:

这部分是在AsyncTask类中的doInBackground方法中

Bitmap bitmapImage;
URL imageUrl = null;
try {
imageUrl = new URL(url[0]);

HttpGet httpRequest = null;
httpRequest = new HttpGet(imageUrl.toURI());

HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);

HttpEntity entity = response.getEntity();
BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
InputStream instream = bufHttpEntity.getContent();

    bitmapImage = CommonMethods.decodeSampledBitmapFromResource(instream, thumb_width, thumb_width);

instream.close();
return bitmapImage;

 } catch (URISyntaxException e) {
    e.printStackTrace();
    return null;
 } catch (MalformedURLException e) {
    e.printStackTrace();
    return null;
 } catch (IOException e) {
    e.printStackTrace(); …
Run Code Online (Sandbox Code Playgroud)

android bitmap bitmapfactory

2
推荐指数
1
解决办法
1万
查看次数

从资源中缩小位图,具有良好的质量和内存效率

我想缩小500x500px资源以适应始终由屏幕宽度决定的特定大小.

目前我使用的是Android开发者网站上的代码(有效地加载大型位图),但质量不如我在一个ImageView(作为xml中的源代码)中使用500x500px资源那么好,只是缩放ImageView而不是缩放位图.

但它很慢,我也希望扩展Bitmap内存效率和速度.

编辑:我想缩放的drawable在drawable我的应用程序的文件夹中.

Edit2:我目前的方法.

在此输入图像描述

左图是无需任何修改即可有效加载大位图的方法.中心图像是通过@Salman Zaidi提供的方法完成的,并进行了一些修改:o.inPreferredConfig = Config.ARGB_8888;o2.inPreferredConfig = Config.ARGB_8888;

右图是一个图像视图,其中图像源以xml定义,我希望用缩放的位图来达到质量.

resources android bitmap scale

2
推荐指数
1
解决办法
8121
查看次数

ComboBox简单,带位图

如何将一个位图放在一个样式框设置为简单的组合框中?例如,Google Chrome右侧有一颗星,Firefox右侧有箭头.我试过这段代码:

procedure TForm2.ComboBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
var
ComboBox: TComboBox;
bitmap: TBitmap;
begin
ComboBox := (Control as TComboBox);
Bitmap := TBitmap.Create;
try
ImageList1.GetBitmap(0, Bitmap);
with ComboBox.Canvas do
begin
  FillRect(Rect);
  if Bitmap.Handle <> 0 then Draw(Rect.Left + 2, Rect.Top, Bitmap);
  Rect := Bounds(Rect.Left + ComboBox.ItemHeight + 2, Rect.Top, Rect.Right - Rect.Left, Rect.Bottom - Rect.Top);
  DrawText(handle, PChar(ComboBox.Items[0]), length(ComboBox.Items[0]), Rect, DT_VCENTER+DT_SINGLELINE);
end;
finally
Bitmap.Free;
  end;
end;
Run Code Online (Sandbox Code Playgroud)

但只能使用样式:csOwnerDrawFixed和csOwnerDrawVariable,位图也只能在项目上显示.

谢谢.

delphi combobox bitmap

2
推荐指数
1
解决办法
1565
查看次数

在另一个Android上覆盖Bitmap

你好伙计们我​​正在尝试获取一个图像(来自资源的帧)将其覆盖在原始位图上.到目前为止,我无法使我的Bitmap进入框架,因为框架始终为空.原始位图现在显示在框架内.这是我用来完成这个的代码.

  Canvas canvas = new Canvas();
    Bitmap border = null;
    Bitmap scaledBorder = null;
    border = BitmapFactory.decodeResource(getResources(), R.drawable.frame1);
    int width = bmp.getWidth();
    int height = bmp.getHeight();
    scaledBorder = Bitmap.createScaledBitmap(border,width,height, false);
    canvas.drawBitmap(scaledBorder, 0, 0, new Paint());
    view.setImageBitmap(scaledBorder);
Run Code Online (Sandbox Code Playgroud)

bmp作为我在Gallery或Camera中的原始位图.我找不到把它们放在一起.只显示帧而不是bmp.提前致谢.

android bitmap bitmapimage android-canvas

2
推荐指数
1
解决办法
6423
查看次数

10英寸平板电脑上的Android BitmapRegionDecoder encodeRegion NullPointerException

在我的Android应用中,我使用以下代码:

BitmapRegionDecoder decoder;
...
decoder = BitmapRegionDecoder.newInstance(myStream, false);
...
int width = -1, height = -1, left = -1, top = -1;
...
Log.d("GDA", left + " " + top + " " + width + " " + height);
Rect re = new Rect(left, top, width, height);
Log.d("GDA", re.toString());
if(decoder != null)
    region = decoder.decodeRegion(re, null);
Run Code Online (Sandbox Code Playgroud)

一切都可以在智能手机和7英寸平板电脑上正常运行,但在10英寸平板电脑上(我在Samsung GT10.1和Acer A501上进行了测试),我收到此错误消息:

1152 1728 2304 2592
Rect(1152, 1728 - 2304, 2592)
java.lang.NullPointerException
    at android.graphics.BitmapRegionDecoder.decodeRegion(BitmapRegionDecoder.java:399)
Run Code Online (Sandbox Code Playgroud)

我找不到解决方案。有人遇到过同样的问题吗?有什么建议么?

android bitmap nullpointerexception

2
推荐指数
1
解决办法
2068
查看次数

在没有获取新内存地址的情况下在其他线程中加载位图

我试图在另一个线程中从磁盘加载图像以不减慢我的绘制线程,但问题是当持有位图的对象被转移到新线程时,它们有不同的指针.我不确定Java如何处理可交叉线程中的指针,但我正在寻找一种解决方案,它将使两个线程都使用相同的对象(浅层复制)而不是线程之间的对象的深度复制.

这是我的代码

new LoadImageTask().execute(ThisTimeDrawBitmaps.indexOf(bitmapWrapper), gameEngine);

private class LoadImageTask extends AsyncTask {
    protected BitmapWrapper LoadImage(BitmapWrapper bitmapWrapper, GameEngine gameEngine) {
        //loading the image in a temp object to avoid  fatal error 11
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inScaled = true;
        Bitmap tempImage = BitmapFactory.decodeResource(Sceptrum.GetResources, bitmapWrapper.getID(), options);
        tempImage = Bitmap.createScaledBitmap(bitmapWrapper.getBitmap(), (int) (bitmapWrapper.getBitmap().getWidth() * gameEngine.getScale()), (int) (bitmapWrapper.getBitmap().getHeight() * gameEngine.getScale()), false);
        //so that the image can be gc.
        Bitmap RemovePointer = bitmapWrapper.getBitmap();
        //to avoid fatal error 11
        bitmapWrapper.setBitmap(tempImage);
        //removing the old image.
        RemovePointer.recycle();
        return bitmapWrapper; …
Run Code Online (Sandbox Code Playgroud)

java multithreading android bitmap

2
推荐指数
1
解决办法
641
查看次数

图像属性的值(C#)

我正在尝试解决为Bitmap对象更改值ImageDescription的问题.添加文件的描述.搜索相关主题,我还没有找到解决方案.

我的代码:

public Bitmap ImageWithComment(Bitmap image)
{
   string filePath = @"C:\1.jpg";
   var data = Encoding.UTF8.GetBytes("my comment"); 
   var propItem = image.PropertyItems.FirstOrDefault();
   propItem.Type = 2;
   propItem.Id = 40092;
   propItem.Len = data.Length;
   propItem.Value = data;
   image.SetPropertyItem(propItem);
   image.Save(filePath);
   return image;
}
Run Code Online (Sandbox Code Playgroud)

但带有新评论的图片不保存在文件夹中((请帮帮我

c# image bitmap

2
推荐指数
1
解决办法
3639
查看次数

为什么Android分配的内存是我对图像预期的两倍?

我正在使用setImageResource()在Android应用程序中加载图像资源,并且由于某种原因,这会占用大量额外内存.

这是我加载图像时看到的内容:

03-29 15:16:56.687: D/dalvikvm(23616): GC_FOR_ALLOC freed 42K, 11% free 16175K/18119K, paused 11ms
I/dalvikvm-heap(23616): Grow heap (frag case) to 23.154MB for 7675216-byte allocation
D/dalvikvm(23616): GC_CONCURRENT freed 3K, 8% free 23667K/25671K, paused 1ms+2ms
D/dalvikvm(23616): GC_FOR_ALLOC freed 0K, 8% free 23667K/25671K, paused 10ms
I/dalvikvm-heap(23616): Grow heap (frag case) to 39.624MB for 17272816-byte allocation
D/dalvikvm(23616): GC_CONCURRENT freed 0K, 5% free 40535K/42567K, paused 1ms+2ms
Run Code Online (Sandbox Code Playgroud)

jpg是1599x1200,所以我期待第一次分配 - 1599*1200*4 = 7675200.17MB的分配是怎么回事?

android bitmap imageview

2
推荐指数
1
解决办法
175
查看次数

为什么CreateCompatibleBitmap在大约一千次执行后失败?

我正在尝试编写一个屏幕捕获/记录应用程序.以下是捕获屏幕并保存的代码部分:

width = GetSystemMetrics(SM_CXMAXTRACK)+8;
height = GetSystemMetrics(SM_CYMAXTRACK)-8;

hwindowDC=GetDC(GetDesktopWindow());
hwindowCompatibleDC=CreateCompatibleDC(hwindowDC);
SetStretchBltMode(hwindowCompatibleDC,COLORONCOLOR);  

// create a bitmap
hbwindow = CreateCompatibleBitmap( hwindowDC, width, height);
cout << " handle to newly created bitmap: " << hbwindow << "\n";

SelectObject(hwindowCompatibleDC, hbwindow); //copy from hwindowCompatibleDC to hbwindow
StretchBlt( hwindowCompatibleDC, 0,0, width, height, hwindowDC, 0, 0,width,height, SRCCOPY); //change SRCCOPY to NOTSRCCOPY for wacky colors !

src.create(height,width,CV_8UC4);   
src.empty();
GetDIBits(hwindowCompatibleDC,hbwindow,0,height,src.data,(BITMAPINFO *)&bi,DIB_RGB_COLORS); 


DeleteDC(hwindowCompatibleDC); 
DeleteObject(hbwindow);
Run Code Online (Sandbox Code Playgroud)

经过一千次左右的重复,我的cout语句将显示新创建的句柄为000000000000000 aka.空值.我的应用程序工作正常,直到那一点
我每次都删除创建的DC和位图,因此没有内存泄漏.任务管理器还确认没有内存泄漏.那么发生了什么?

感谢任何可以提供帮助的人.

c++ bitmap

2
推荐指数
1
解决办法
2053
查看次数