标签: bitmap

如何将Uri图像压缩为位图

这段代码向我显示一个错误,我想将所选图像保存到数据库并进行检索我遵循这两个教程http://nizaqatali.wordpress.com/2011/06/21/android-dialog-select-image-from-gallery/ 这个 http://androidhub4you.blogspot.com/2012/09/hello-friends-today-i-am-going-to-share.html 但是这个问题出现了错误信息"方法压缩(Bitmap.CompressFormat,int ,ByteArrayOutputStream)未定义类型Uri"

         import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import android.app.Activity;
 import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
 import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;

 public class SQLiteDemoActivity extends Activity {



final int SELECT_PHOTO = 0;
 ArrayList<Contact> imageArry = new ArrayList<Contact>();
 ContactImageAdapter adapter;
 Button BrowseButton;
 DataBaseHandler db;

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

 db = new DataBaseHandler(this);
//get image from drawable
//Bitmap image = …
Run Code Online (Sandbox Code Playgroud)

compression android bitmap bitmapimage

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

使用firebird从delphi中的blob字段加载并保存图像

在我的Firebird数据库中,我有一个包含位图的Blob字段.我必须加载并显示在我的表格上的TImage中.随后我将在同一个字段中保存由OpenDialog选择的图像.

delphi firebird blob image bitmap

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

PictureBox在Tab键按下时抛出"参数无效"ArgumentException

我有一个表单,用户可以先扫描到位图.扫描完成后,加载位图,我有4个文本框然后启用.在每个文本框旁边,我有一个名为"从图像剪切"的按钮.当用户单击该按钮时,他们可以单击并拖动位图以使用MODI获取所选文本.

除了一个令人讨厌的bug之外,这种方法很完美:当我点击"从图像剪切"按钮并拖动一个正方形时,它会很好地获取文本框中的信息.然后,如果我点击下一个文本框,它会很顺利,但是如果我使用tab键离开该字段,我会得到一个"参数无效" ArgumentException并且它没有显示任何帮助代码中的位置崩溃了.我可以在表单中四处选择,没有任何问题,但是一旦扫描了位图,当我使用tab键时,它会像10次中的9次一样崩溃.

我尝试使用以下方法覆盖tab键(仅用于调试):

Protected Overrides Function ProcessTabKey(ByVal forward As Boolean) As Boolean
    MsgBox("TAB is currently disabled!")
    Return False 'Tried True as well, just in case
End Function
Run Code Online (Sandbox Code Playgroud)

......但它仍然崩溃.

关于什么是错的任何建议?由于我不知道从哪里开始调试,我无法分辨出要显示的代码.

编辑1

这是ArgumentException抛出的堆栈跟踪:

  • 在System.Drawing.Image.get_Width()
  • 在System.Drawing.Image.get_Size()
  • 在System.Windows.Forms.PictureBox.ImageRectangleFromSizeMode(PictureBoxSizeMode模式)
  • 在System.Windows.Forms.PictureBox.OnPaint(PaintEventArgs pe)
  • 在System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e,Int16 layer)
  • 在System.Windows.Forms.Control.WmPaint(Message&m)
  • 在System.Windows.Forms.Control.WndProc(Message&m)
  • 在System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&m)
  • 在System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&m)
  • 在System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)
  • 在System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&msg)
  • 在System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID,Int32 reason,Int32 pvLoopData)
  • 在System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason,ApplicationContext context)
  • 在System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason,ApplicationContext context)
  • 在Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
  • 在Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
  • 在Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String [] commandLine)
  • at ORC_Testing.My.MyApplication.Main(String [] Args)in 17d14f5c-a337-4978-8281-53493378c1071.vb:第81行
  • 在System.AppDomain._nExecuteAssembly(RuntimeAssembly程序集,String [] args)
  • 在System.AppDomain.ExecuteAssembly(String assemblyFile,Evidence assemblySecurity,String [] …

vb.net modi bitmap keypress winforms

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

System.Drawing - 参数无效

经过一些更多的测试后,我发现这个问题可能是由于图像以某种方式没有被及时加载以克隆到位图并显示.这是可能的还是没有?

注意:是的,标题中有此错误还有其他问题,但从一些研究来看,它似乎是一个含糊不清的错误,有许多可能的原因.我没有发现与我相同的情况有任何问题.

我收到以下错误.

System.ArgumentException was unhandled
HResult=-2147024809
Message=Parameter is not valid.
Source=System.Drawing
Run Code Online (Sandbox Code Playgroud)

它来自这段代码.似乎是随机的(即,有时候它会起作用,有时却不起作用.连续运行的次数越多,没有重新启动VS并重建项目,失败的可能性越大):

private Bitmap GetSprite(bool anim, int tsIndex, int tileIdx) {
    System.Drawing.Rectangle cloneRect;
    string prefix = (anim) ? "A" : "S";
    using (Bitmap b = new Bitmap(prefix + tsIndex.ToString() + ".png")) {
        if (anim) {
            cloneRect = new System.Drawing.Rectangle(BaseObjects.A_AnimSpriteSets[tsIndex].StaticRecs[tileIdx].X, BaseObjects.A_AnimSpriteSets[tsIndex].StaticRecs[tileIdx].Y, BaseObjects.A_AnimSpriteSets[tsIndex].RecWidth, BaseObjects.A_AnimSpriteSets[tsIndex].RecHeight);
        } else {
            cloneRect = new System.Drawing.Rectangle(BaseObjects.A_StaticSpriteSets[tsIndex].StaticRecs[tileIdx].X, BaseObjects.A_StaticSpriteSets[tsIndex].StaticRecs[tileIdx].Y, BaseObjects.A_StaticSpriteSets[tsIndex].RecWidth, BaseObjects.A_StaticSpriteSets[tsIndex].RecHeight);
        }
        return b.Clone(cloneRect, b.PixelFormat);
    }
}
Run Code Online (Sandbox Code Playgroud)

具体来说,第四行:

using (Bitmap b = new Bitmap(prefix + tsIndex.ToString() + ".png")) …
Run Code Online (Sandbox Code Playgroud)

c# system.drawing bitmap .net-4.0

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

在Android中,位图压缩PNG-&gt; JPEG,反之亦然

从PNG转换为JPEG,然后从JPEG转换为PNG时,图片尺寸出现问题。

            public void onClick(View v) {
            String imageFileName = "/sdcard/Penguins2.png";
            File imageFile = new File(imageFileName);
            if (imageFile.exists()) {
                // Load the image from file
                myBitmap = BitmapFactory.decodeFile(imageFileName);
                // Display the image in the image viewer
                myImageView = (ImageView) findViewById(R.id.my_image_view);
                if (myImageView != null) {
                    myImageView.setImageBitmap(myBitmap);
                }
            }
        }
Run Code Online (Sandbox Code Playgroud)

转换:

    private void processImage() {               
    try {
        String outputPath = "/sdcard/Penguins2.jpg";
        int quality = 100;
        FileOutputStream fileOutStr = new FileOutputStream(outputPath);
        BufferedOutputStream bufOutStr = new BufferedOutputStream(
                fileOutStr);
        myBitmap.compress(CompressFormat.JPEG, quality, bufOutStr);
        bufOutStr.flush();
        bufOutStr.close();
    } …
Run Code Online (Sandbox Code Playgroud)

png android jpeg bitmap image-processing

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

Android:内存不足错误

当我将Android应用程序最小化大约4或5次时,我总是会收到以下错误:

02-01 19:24:11.980: E/dalvikvm-heap(22362): Out of memory on a 3686416-byte allocation.
02-01 19:24:12.000: E/dalvikvm(22362): Out of memory: Heap Size=62755KB, Allocated=55237KB, Limit=65536KB
02-01 19:24:12.000: E/dalvikvm(22362): Extra info: Footprint=62435KB, Allowed Footprint=62755KB, Trimmed=2144KB
02-01 19:24:12.000: E/Bitmap_JNI(22362): Create Bitmap Failed.    
02-01 19:24:12.000: E/Bitmap_JNI(22362): Failed to create SkBitmap!
02-01 19:24:12.000: E/AndroidRuntime(22362): FATAL EXCEPTION: main
02-01 19:24:12.000: E/AndroidRuntime(22362): java.lang.OutOfMemoryError: (Heap Size=62755KB, Allocated=55237KB)
02-01 19:24:12.000: E/AndroidRuntime(22362):    at android.graphics.Bitmap.nativeCreateScaledBitmap(Native Method)
02-01 19:24:12.000: E/AndroidRuntime(22362):    at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:744)
02-01 19:24:12.000: E/AndroidRuntime(22362):    at de.vauge.mb.Utils.getResizedBitmap(Utils.java:56)
02-01 19:24:12.000: E/AndroidRuntime(22362):    at de.vauge.mb.MenuView.initialize(MenuView.java:74)
02-01 19:24:12.000: E/AndroidRuntime(22362): …
Run Code Online (Sandbox Code Playgroud)

memory heap android bitmap

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

如何在easeljs中更改位图宽度和高度?

我正在使用easeljs来创建HTML5页面.我必须在画布中加载图像.如何更改我正在加载的位图的宽度和高度.

var img = new Image();  
img.src = image_path+images; // image from folder        
var loading_img = new createjs.Bitmap(img);  
stage.addChild(loading_img);
Run Code Online (Sandbox Code Playgroud)

它只是在画布上显示图像,我尝试使用

loading_img.sourceRect = { x:img.width/2, y:img.height/2, width:280, height:150 };
Run Code Online (Sandbox Code Playgroud)

但它裁剪图像(280*150).

谢谢,沙迪亚

height canvas bitmap width easeljs

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

将控件绘制到内存(位图)

是否可以将wpf控件绘制到内存(位图)而根本不在屏幕上绘制?
我找到了一个如何保存到位图的示例,但是仅当在屏幕上绘制了窗口时,该示例才起作用。

BitmapImage bitmap = new BitmapImage();
    RenderTargetBitmap renderTarget =
    new RenderTargetBitmap((int)canvaspad.Width,
    (int)canvaspad.Height,
    96,
    96,
    System.Windows.Media.PixelFormats.Default);
renderTarget.Render(canvaspad);
Run Code Online (Sandbox Code Playgroud)

c# wpf controls render bitmap

4
推荐指数
1
解决办法
2272
查看次数

如何从位图中删除白色背景颜色

我想删除位图中的白色背景颜色

Bitmap capcha = new Bitmap("C:/image.jpg");
pictureBox1.Image = capcha;
Run Code Online (Sandbox Code Playgroud)

但是我想在我的pictureBox1中显示背景中没有白色的图像

c# background image bitmap picturebox

4
推荐指数
1
解决办法
7800
查看次数

比较两个BitmapImages以检查它们在WPF中是否不同的最快方法

比较2个BitmapImage对象的最快方法是什么.一个是在Image Source属性中,另一个是我在代码中创建的.

我可以使用新的位图图像设置图像源,但它会导致闪烁,因为它会一遍又一遍地设置相同的图像.

我想只设置图像,如果它的像素与Image.Source中的像素不同.

编辑:

AlbumArt是视图中的图像(跟随MVVM).

一些代码(在视图代码后面运行):

Task.Factory.StartNew(() =>
    {
        while (((App)Application.Current).Running)
        {
            Thread.Sleep(1000);

            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                if ((this.DataContext as AudioViewModel).CurrentDevice != null)
                {
                    if ((((this.DataContext as AudioViewModel).CurrentDevice) as AUDIO).SupportsAlbumArt)
                    {
                        BitmapImage image = new BitmapImage();
                        image.BeginInit();
                        image.UriSource = new Uri((((this.DataContext as AudioViewModel).CurrentDevice) as AUDIO).AlbumArt);
                        image.CacheOption = BitmapCacheOption.None;
                        image.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
                        image.EndInit();

                        AlbumArt.Source = image;
                        ...
Run Code Online (Sandbox Code Playgroud)

c# wpf image bitmap

4
推荐指数
1
解决办法
6474
查看次数